From: Jihoon Jung Date: Mon, 15 Jun 2015 01:54:12 +0000 (+0900) Subject: apply Tizen 2.4 nfc-manager implementation X-Git-Tag: submit/tizen/20150615.015651^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8dd8ce956eb9090594619d900383e204a19a33c4;p=platform%2Fcore%2Fconnectivity%2Fnfc-manager.git apply Tizen 2.4 nfc-manager implementation Signed-off-by: Ji-hoon Jung Change-Id: I1c8c08cf74a0433096b2cad869cbbc0b0b2f3484 --- diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index 8d334f1..62115ff --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,34 +1,13 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(nfc-manager C) -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") - -IF(ARM_TARGET) - ADD_DEFINITIONS("-DTARGET") - MESSAGE("add -DTARGET") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}") -ENDIF(ARM_TARGET) - -SET(CMAKE_SHARED_LINKER_FLAGS " -Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") -SET(CMAKE_EXE_LINKER_FLAGS " -Wl,--as-needed -Wl,--hash-style=both") +MESSAGE("build nfc-common-lib and nfc-manager") SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(LIBDIR "${PREFIX}/lib") +SET(MODULEDIR "${LIBDIR}/nfc") -ADD_DEFINITIONS("-DNFC_MANAGER_MODULEDIR=\"${LIB_INSTALL_DIR}/nfc\"") - -#ADD_DEFINITIONS("-DSECURITY_SERVER") -ADD_DEFINITIONS("-DUSE_FULL_URI") -#ADD_DEFINITIONS("-DESE_ALWAYS_ON") +ADD_DEFINITIONS("-D_GNU_SOURCE") -ADD_SUBDIRECTORY(common) -ADD_SUBDIRECTORY(client) -ADD_SUBDIRECTORY(daemon) -ADD_SUBDIRECTORY(tests) -#ADD_SUBDIRECTORY(tools/ndef-tool) -#ADD_SUBDIRECTORY(tools/nfc-client) +ADD_SUBDIRECTORY(src/commonlib) +ADD_SUBDIRECTORY(src/clientlib) +ADD_SUBDIRECTORY(src/manager) diff --git a/TC/testcase/utc_net_nfc_client_ndef_message.c b/TC/testcase/utc_net_nfc_client_ndef_message.c deleted file mode 100755 index 7383ebd..0000000 --- a/TC/testcase/utc_net_nfc_client_ndef_message.c +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include - -#include "net_nfc_ndef_message.h" -#include "net_nfc_util_private.h" -#include "net_nfc.h" // to use net_nfc_data - - -enum { - POSITIVE_TC_IDX = 0x01, - NEGATIVE_TC_IDX, -}; -static void startup(void); -static void cleanup(void); - -void (*tet_startup)(void) = startup; -void (*tet_cleanup)(void) = cleanup; - -static void utc_net_nfc_create_ndef_message_p(void); -static void utc_net_nfc_create_ndef_message_n(void); -static void utc_net_nfc_create_rawdata_from_ndef_message_p(void); -static void utc_net_nfc_create_rawdata_from_ndef_message_n(void); -static void utc_net_nfc_create_ndef_message_from_rawdata_p(void); -static void utc_net_nfc_create_ndef_message_from_rawdata_n(void); -static void utc_net_nfc_get_ndef_message_byte_length_p(void); -static void utc_net_nfc_get_ndef_message_byte_length_n(void); -static void utc_net_nfc_append_record_to_ndef_message_p(void); -static void utc_net_nfc_append_record_to_ndef_message_n(void); -static void utc_net_nfc_free_ndef_message_p(void); -static void utc_net_nfc_free_ndef_message_n(void); -static void utc_net_nfc_get_ndef_message_record_count_p(void); -static void utc_net_nfc_get_ndef_message_record_count_n(void); - - - - -struct tet_testlist tet_testlist[] = { - { utc_net_nfc_create_ndef_message_p , POSITIVE_TC_IDX }, - { utc_net_nfc_create_ndef_message_n , NEGATIVE_TC_IDX }, - { utc_net_nfc_create_rawdata_from_ndef_message_p, POSITIVE_TC_IDX }, - { utc_net_nfc_create_rawdata_from_ndef_message_n , NEGATIVE_TC_IDX}, - { utc_net_nfc_create_ndef_message_from_rawdata_p, 1}, - { utc_net_nfc_create_ndef_message_from_rawdata_n, 2 }, - { utc_net_nfc_get_ndef_message_byte_length_p, 1}, - { utc_net_nfc_get_ndef_message_byte_length_n, 2}, - { utc_net_nfc_append_record_to_ndef_message_p, 1}, - { utc_net_nfc_append_record_to_ndef_message_n, 2}, - { utc_net_nfc_free_ndef_message_p, 1}, - { utc_net_nfc_free_ndef_message_n, 2}, - { utc_net_nfc_get_ndef_message_record_count_p, 1}, - { utc_net_nfc_get_ndef_message_record_count_n, 2}, - { NULL, 0 }, -}; - -//this method is called only once in start -static void startup(void) -{ - /* start of TC */ -} - -static void cleanup(void) -{ - /* end of TC */ -} -static void utc_net_nfc_create_ndef_message_p(void) -{ - int ret ; - ndef_message_h message; - - ret = net_nfc_create_ndef_message(&message); - net_nfc_free_ndef_message(message); - - dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message is failed"); -} - -static void utc_net_nfc_create_ndef_message_n(void) -{ - int ret=0; - - ret = net_nfc_create_ndef_message( NULL); - - dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message not allow null"); -} - -static void utc_net_nfc_create_rawdata_from_ndef_message_p(void) -{ - int ret ; - char url[] = "samsung.com"; - ndef_record_h record = NULL; - ndef_message_h msg = NULL; - data_h rawdata = NULL; - - net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW); - - net_nfc_create_ndef_message(&msg); - - net_nfc_append_record_to_ndef_message(msg, record); - - ret = net_nfc_create_rawdata_from_ndef_message (msg, &rawdata); - - dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_rawdata_from_ndef_message is failed"); -} - -static void utc_net_nfc_create_rawdata_from_ndef_message_n(void) -{ - int ret ; - - ret = net_nfc_create_rawdata_from_ndef_message (NULL, NULL); - - dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_rawdata_from_ndef_message not allow null"); -} - -static void utc_net_nfc_create_ndef_message_from_rawdata_p(void) -{ - int ret ; - uint8_t url[] = "samsung.com"; - ndef_message_s* msg = NULL; - data_s* rawdata = NULL; - - rawdata = calloc(1, sizeof(data_s)); - msg = calloc(1, sizeof(ndef_message_s)); - - rawdata->buffer = url; - rawdata->length = 11; - - ret = net_nfc_create_ndef_message_from_rawdata ((ndef_message_h*)msg, (data_h)rawdata); - - net_nfc_free_ndef_message((ndef_message_h)msg); - - dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message_from_rawdata is failed"); -} - -static void utc_net_nfc_create_ndef_message_from_rawdata_n(void) -{ - int ret ; - - ret = net_nfc_create_ndef_message_from_rawdata (NULL, NULL); - - dts_check_ne(__func__, ret, NET_NFC_OK,"net_nfc_create_ndef_message_from_rawdata not allow null"); -} - -static void utc_net_nfc_get_ndef_message_byte_length_p(void) -{ - int ret ; - char url[] = "samsung.com"; - ndef_record_h record = NULL; - ndef_message_h msg = NULL; - 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"); -} diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt deleted file mode 100644 index b9f1239..0000000 --- a/client/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -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) - -IF(X11_SUPPORT) - SET(WIN_PKG "ecore-x") -ENDIF(X11_SUPPORT) -IF(WAYLAND_SUPPORT) - SET(WIN_PKG "${WIN_PKG} ecore-wayland") -ENDIF(WAYLAND_SUPPORT) -pkg_check_modules(client_pkgs REQUIRED security-server dlog vconf libtzplatform-config ${WIN_PKG}) - - -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}) - -IF(X11_SUPPORT) - ADD_DEFINITIONS("-DHAVE_X11") -ENDIF(X11_SUPPORT) -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_INSTALL_DIR}/pkgconfig) - -INSTALL(TARGETS ${NFC_CLIENT} DESTINATION ${LIB_INSTALL_DIR}) - -FOREACH(hfile ${CLIENT_HEADER}) - INSTALL(FILES ${hfile} DESTINATION include/${NFC_CLIENT}) -ENDFOREACH(hfile) diff --git a/client/include/net_nfc.h b/client/include/net_nfc.h deleted file mode 100644 index 6dd4834..0000000 --- a/client/include/net_nfc.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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__ - -#ifdef __cplusplus -extern "C" { -#endif - -#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_phdc.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_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" - -#ifdef __cplusplus -} -#endif - -#endif //__NET_NFC_H__ diff --git a/client/include/net_nfc_client_context.h b/client/include/net_nfc_client_context.h deleted file mode 100644 index b7c556e..0000000 --- a/client/include/net_nfc_client_context.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -#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); - - -#endif //__NET_NFC_CLIENT_CONTEXT_H__ diff --git a/client/include/net_nfc_client_handover.h b/client/include/net_nfc_client_handover.h deleted file mode 100644 index 0c931f1..0000000 --- a/client/include/net_nfc_client_handover.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -typedef void (*net_nfc_p2p_connection_handover_completed_cb)( - net_nfc_error_e result, - net_nfc_conn_handover_carrier_type_e carrier, - data_s *ac_data, - void *user_data); - - -net_nfc_error_e net_nfc_client_handover_free_alternative_carrier_data( - net_nfc_connection_handover_info_s *info_handle); - - -net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_type( - net_nfc_connection_handover_info_s *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_s *info_handle, data_s **data); - - -net_nfc_error_e net_nfc_client_p2p_connection_handover( - net_nfc_target_handle_s *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_s *handle, - net_nfc_conn_handover_carrier_type_e arg_type, - net_nfc_conn_handover_carrier_type_e *out_carrier, - data_s **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); - -#endif //__NET_NFC_CLIENT_HANDOVER_H__ diff --git a/client/include/net_nfc_client_llcp.h b/client/include/net_nfc_client_llcp.h deleted file mode 100644 index 26d985c..0000000 --- a/client/include/net_nfc_client_llcp.h +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -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_accept_completed)(net_nfc_error_e result, - void *user_data); - -typedef void (*net_nfc_client_llcp_reject_completed)(net_nfc_error_e result, - 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, - void *user_data); - -typedef void (*net_nfc_client_llcp_send_to_completed) (net_nfc_error_e result, - void *user_data); - -typedef void (*net_nfc_client_llcp_receive_completed) (net_nfc_error_e result, - data_s *data, - void *user_data); - -typedef void (*net_nfc_client_llcp_receive_from_completed) ( - net_nfc_error_e result, - sap_t sap, - data_s *data, - void *user_data); - -typedef void (*net_nfc_client_llcp_close_completed) (net_nfc_error_e result, - void *user_data); - -typedef void (*net_nfc_client_llcp_disconnect_completed)(net_nfc_error_e result, - void *user_data); - -net_nfc_error_e net_nfc_client_llcp_config(net_nfc_llcp_config_info_s *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_s *config); - -net_nfc_error_e net_nfc_client_llcp_get_config(net_nfc_llcp_config_info_s **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_accept(net_nfc_llcp_socket_t socket, - net_nfc_client_llcp_accept_completed callback, - void *user_data); - -net_nfc_error_e net_nfc_client_llcp_accept_sync(net_nfc_llcp_socket_t socket); - -net_nfc_error_e net_nfc_client_llcp_reject(net_nfc_llcp_socket_t socket, - net_nfc_client_llcp_reject_completed callback, - void *user_data); - -net_nfc_error_e net_nfc_client_llcp_reject_sync(net_nfc_llcp_socket_t 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_s *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_s *data); - -net_nfc_error_e net_nfc_client_llcp_send_to(net_nfc_llcp_socket_t socket, - sap_t sap, - data_s *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_s *data); - -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_s **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_s **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_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); - -void net_nfc_client_llcp_create_socket(net_nfc_llcp_socket_t *socket, - net_nfc_llcp_socket_option_s *option); - -net_nfc_error_e net_nfc_client_llcp_get_local_config( - net_nfc_llcp_config_info_s **config); - -net_nfc_error_e net_nfc_client_llcp_get_local_socket_option( - net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s **option); - -net_nfc_error_e net_nfc_client_llcp_create_socket_option( - net_nfc_llcp_socket_option_s **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_s **option); - -net_nfc_error_e net_nfc_client_llcp_get_socket_option_miu( - net_nfc_llcp_socket_option_s *option, uint16_t *miu); - -net_nfc_error_e net_nfc_client_llcp_set_socket_option_miu( - net_nfc_llcp_socket_option_s *option, uint16_t miu); - -net_nfc_error_e net_nfc_client_llcp_get_socket_option_rw( - net_nfc_llcp_socket_option_s *option, uint8_t *rt); - -net_nfc_error_e net_nfc_client_llcp_set_socket_option_rw( - net_nfc_llcp_socket_option_s *option, uint8_t rt); - -net_nfc_error_e net_nfc_client_llcp_get_socket_option_type( - net_nfc_llcp_socket_option_s *option, net_nfc_socket_type_e *type); - -net_nfc_error_e net_nfc_client_llcp_set_socket_option_type( - net_nfc_llcp_socket_option_s *option, net_nfc_socket_type_e type); - -net_nfc_error_e net_nfc_client_llcp_free_socket_option( - net_nfc_llcp_socket_option_s * option); - -net_nfc_error_e net_nfc_client_llcp_create_config( - net_nfc_llcp_config_info_s **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_s **config); - -net_nfc_error_e net_nfc_client_llcp_get_config_miu( - net_nfc_llcp_config_info_s *config, uint16_t *miu); - -net_nfc_error_e net_nfc_client_llcp_get_config_wks( - net_nfc_llcp_config_info_s *config, uint16_t *wks); - -net_nfc_error_e net_nfc_client_llcp_get_config_lto( - net_nfc_llcp_config_info_s *config, uint8_t *lto); - -net_nfc_error_e net_nfc_client_llcp_get_config_option( - net_nfc_llcp_config_info_s *config, uint8_t *option); - -net_nfc_error_e net_nfc_client_llcp_set_config_miu( - net_nfc_llcp_config_info_s *config, uint16_t miu); - -net_nfc_error_e net_nfc_client_llcp_set_config_wks( - net_nfc_llcp_config_info_s *config, uint16_t wks); - -net_nfc_error_e net_nfc_client_llcp_set_config_lto( - net_nfc_llcp_config_info_s *config, uint8_t lto); - -net_nfc_error_e net_nfc_client_llcp_set_config_option( - net_nfc_llcp_config_info_s *config, uint8_t option); - -net_nfc_error_e net_nfc_client_llcp_free_config( - net_nfc_llcp_config_info_s *config); - -net_nfc_error_e net_nfc_client_llcp_create_socket_option_default( - net_nfc_llcp_socket_option_s **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); - -#endif //__NET_NFC_CLIENT_LLCP_H__ diff --git a/client/include/net_nfc_client_manager.h b/client/include/net_nfc_client_manager.h deleted file mode 100644 index 4fb5a55..0000000 --- a/client/include/net_nfc_client_manager.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -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); - -bool net_nfc_client_manager_is_activated(void); - -/* TODO : move to internal header */ -net_nfc_error_e net_nfc_client_manager_init(void); - -void net_nfc_client_manager_deinit(void); - - -#endif //__NET_NFC_CLIENT_MANAGER_H__ diff --git a/client/include/net_nfc_client_ndef.h b/client/include/net_nfc_client_ndef.h deleted file mode 100644 index 04a8fa9..0000000 --- a/client/include/net_nfc_client_ndef.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -typedef void (*net_nfc_client_ndef_read_completed) (net_nfc_error_e result, - ndef_message_s *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_s *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_s *handle, - ndef_message_s **message); - -net_nfc_error_e net_nfc_client_ndef_write(net_nfc_target_handle_s *handle, - ndef_message_s *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_s *handle, - ndef_message_s *message); - -net_nfc_error_e net_nfc_client_ndef_make_read_only( - net_nfc_target_handle_s *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_s *handle); - -net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_s *handle, - data_s *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_s *handle, - data_s *key); - -/* TODO : move to internal header */ -net_nfc_error_e net_nfc_client_ndef_init(void); - -void net_nfc_client_ndef_deinit(void); - -#endif //__NET_NFC_CLIENT_NDEF_H__ diff --git a/client/include/net_nfc_client_p2p.h b/client/include/net_nfc_client_p2p.h deleted file mode 100644 index 75b774d..0000000 --- a/client/include/net_nfc_client_p2p.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -/* 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_s *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_s *p2p_data, void *user_data); - -/* P2P client API's*/ -net_nfc_error_e net_nfc_client_p2p_send(net_nfc_target_handle_s *handle, - data_s *data, net_nfc_client_p2p_send_completed callback, void *user_data); - -net_nfc_error_e net_nfc_client_p2p_send_sync(net_nfc_target_handle_s *handle, - data_s *data); - - -/* 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); - -#endif //__NET_NFC_CLIENT_P2P_H__ diff --git a/client/include/net_nfc_client_phdc.h b/client/include/net_nfc_client_phdc.h deleted file mode 100755 index d88ba2a..0000000 --- a/client/include/net_nfc_client_phdc.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_PHDC_H__ -#define __NET_NFC_CLIENT_PHDC_H__ - -#include "net_nfc_typedef.h" - -/* PHDC callbacks */ - -typedef void (*net_nfc_client_phdc_send_completed)(net_nfc_error_e result, - void *user_data); - -typedef void (*net_nfc_client_phdc_transport_connect_indication)( - net_nfc_phdc_handle_h handle_info,void *user_data); - -typedef void (*net_nfc_client_phdc_transport_disconnect_indication)(void *user_data); - -typedef void (*net_nfc_client_phdc_data_received)(data_s *phdc_data, - void *user_data); - -typedef void (*net_nfc_client_phdc_event_cb)( net_nfc_error_e result, - net_nfc_llcp_state_t event, void *user_data); - -/* PHDC client API's*/ -net_nfc_error_e net_nfc_client_phdc_send(net_nfc_phdc_handle_h handle, - data_s *data, net_nfc_client_phdc_send_completed callback, void *user_data); - -net_nfc_error_e net_nfc_client_phdc_send_sync(net_nfc_phdc_handle_h handle, - data_s *data); - -/* PHDC client API's - used for registering callbacks*/ -void net_nfc_client_phdc_set_transport_connect_indication( - net_nfc_client_phdc_transport_connect_indication callback, void *user_data); - -void net_nfc_client_phdc_set_transport_disconnect_indication( - net_nfc_client_phdc_transport_disconnect_indication callback, void *user_data); - -void net_nfc_client_phdc_set_data_received( - net_nfc_client_phdc_data_received callback, void *user_data); - -net_nfc_error_e net_nfc_client_phdc_register(net_nfc_phdc_role_e role, - const char *san,net_nfc_client_phdc_event_cb callback, void *user_data); - -net_nfc_error_e net_nfc_client_phdc_unregister( net_nfc_phdc_role_e role, - const char *san); - - -/* PHDC client API's - used for unregistering callbacks*/ -void net_nfc_client_phdc_unset_transport_connect_indication(void); - -void net_nfc_client_phdc_unset_transport_disconnect_indication(void); - -void net_nfc_client_phdc_unset_data_received(void); - -/* Init/Deint function calls*/ -net_nfc_error_e net_nfc_client_phdc_init(void); - -void net_nfc_client_phdc_deinit(void); - -#endif //__NET_NFC_CLIENT_PHDC_H__ - - diff --git a/client/include/net_nfc_client_se.h b/client/include/net_nfc_client_se.h deleted file mode 100644 index 6a82eff..0000000 --- a/client/include/net_nfc_client_se.h +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 -#include "net_nfc_typedef.h" - -/*************Secure Element Callbacks*********/ -typedef void (*net_nfc_se_set_se_cb)( - net_nfc_error_e result, - void *user_data); - -typedef void (*net_nfc_se_get_se_cb)( - net_nfc_error_e result, - net_nfc_se_type_e se_type, - void *user_data); - -typedef void (*net_nfc_se_set_card_emulation_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_s *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_s *data, - void *user_data); - -typedef void (*net_nfc_se_send_apdu_cb)(net_nfc_error_e result, data_s *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)( - net_nfc_se_type_e se_type, - data_s *aid, - data_s *param, - void *user_data); - -typedef void (*net_nfc_client_se_ese_detected_event)( - net_nfc_target_handle_s *handle, - int dev_type, - data_s *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( - net_nfc_se_get_se_cb callback, void *user_data); - -net_nfc_error_e net_nfc_client_se_get_secure_element_type_sync( - net_nfc_se_type_e *se_type); - -net_nfc_error_e net_nfc_set_card_emulation_mode( - net_nfc_card_emulation_mode_t mode, - net_nfc_se_set_card_emulation_cb callback, - void *user_data); - -net_nfc_error_e net_nfc_set_card_emulation_mode_sync( - net_nfc_card_emulation_mode_t mode); - -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_get_card_emulation_mode( - net_nfc_se_type_e *type); - -net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync( - net_nfc_se_type_e se_type, net_nfc_target_handle_s **handle); - -net_nfc_error_e net_nfc_client_se_close_internal_secure_element( - net_nfc_target_handle_s *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_s *handle); - -net_nfc_error_e net_nfc_client_se_get_atr(net_nfc_target_handle_s *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_s *handle, - data_s **atr); - -net_nfc_error_e net_nfc_client_se_send_apdu(net_nfc_target_handle_s *handle, - data_s *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_s *handle, data_s *apdu_data, data_s **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_se_type_e se_type, - net_nfc_client_se_transaction_event callback, - void *user_data); - -void net_nfc_client_se_unset_transaction_event_cb(net_nfc_se_type_e type); - -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); - - -#endif //__NET_NFC_CLIENT_SE_H__ diff --git a/client/include/net_nfc_client_snep.h b/client/include/net_nfc_client_snep.h deleted file mode 100644 index 2b06692..0000000 --- a/client/include/net_nfc_client_snep.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -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_s *msg, - void *user_data); - -net_nfc_error_e net_nfc_client_snep_start_server( - net_nfc_target_handle_s *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_s *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_s *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_s *target, - net_nfc_snep_type_t snep_type, - ndef_message_s *msg, - net_nfc_snep_type_t *resp_type, - ndef_message_s **response); - -net_nfc_error_e net_nfc_client_snep_stop_service( - net_nfc_target_handle_s *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_s *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); - -#endif //__NET_NFC_CLIENT_SNEP_H__ diff --git a/client/include/net_nfc_client_system_handler.h b/client/include/net_nfc_client_system_handler.h deleted file mode 100644 index ef3cbfb..0000000 --- a/client/include/net_nfc_client_system_handler.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -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); - -#endif //__NET_NFC_CLIENT_SYSTEM_HANDLER_H__ diff --git a/client/include/net_nfc_client_tag.h b/client/include/net_nfc_client_tag.h deleted file mode 100644 index 3a9f58c..0000000 --- a/client/include/net_nfc_client_tag.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -#if 0 -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_s *info, void *user_data); - -typedef void (*net_nfc_client_tag_get_current_target_handle_completed)( - net_nfc_error_e result, net_nfc_target_handle_s *handle, void *user_data); -#endif -typedef void (*net_nfc_client_tag_tag_discovered)(net_nfc_target_info_s *info, - void *user_data); - -typedef void (*net_nfc_client_tag_tag_detached)(void *user_data); - -#if 0 -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_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_target_handle( - net_nfc_client_tag_get_current_target_handle_completed callback, void *user_data); -#endif -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_sync( - net_nfc_target_info_s **info); - -net_nfc_error_e net_nfc_client_tag_get_current_target_handle_sync( - net_nfc_target_handle_s **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); - - -/* internal function */ -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); - -#endif //__NET_NFC_CLIENT_TAG_H__ diff --git a/client/include/net_nfc_client_tag_felica.h b/client/include/net_nfc_client_tag_felica.h deleted file mode 100644 index b6128e0..0000000 --- a/client/include/net_nfc_client_tag_felica.h +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -/** - - @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_s *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_s *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_s *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_s *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_s *handle, - uint8_t number_of_services, - uint16_t service_list[], - uint8_t number_of_blocks, - uint8_t block_list[], - data_s *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_s *handle, - nfc_transceive_data_callback callback, - void* trans_param); - -/** - @} - */ - -#endif //__NET_NFC_CLIENT_TAG_FELICA_H__ diff --git a/client/include/net_nfc_client_tag_jewel.h b/client/include/net_nfc_client_tag_jewel.h deleted file mode 100644 index 81b70a1..0000000 --- a/client/include/net_nfc_client_tag_jewel.h +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -/** - - @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_s *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_s *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_s *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_s *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_s *handle, - uint8_t block, - uint8_t byte, - uint8_t data, - nfc_transceive_callback callback, - void *user_data); - -/** - @} - */ - -#endif //__NET_NFC_CLIENT_TAG_JEWEL_H__ diff --git a/client/include/net_nfc_client_tag_mifare.h b/client/include/net_nfc_client_tag_mifare.h deleted file mode 100644 index 4990e78..0000000 --- a/client/include/net_nfc_client_tag_mifare.h +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -/** - - @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_s *handle, - uint8_t sector, - data_s *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_s *handle, - uint8_t sector, - data_s *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_s *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_s *handle, - uint8_t addr, - data_s *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_s *handle, - uint8_t addr, - data_s *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_s *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_s *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_s *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_s *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_s **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_s **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_s **key); - -/** - @} - */ - -#endif //__NET_NFC_TAG_MIFARE_H__ diff --git a/client/include/net_nfc_client_transceive.h b/client/include/net_nfc_client_transceive.h deleted file mode 100644 index ef9e570..0000000 --- a/client/include/net_nfc_client_transceive.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -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_s *data, - void *user_data); - -net_nfc_error_e net_nfc_client_transceive(net_nfc_target_handle_s *handle, - data_s *rawdata, nfc_transceive_callback callback, void *user_data); - -net_nfc_error_e net_nfc_client_transceive_data(net_nfc_target_handle_s *handle, - data_s *rawdata, nfc_transceive_data_callback callback, void *user_data); - -net_nfc_error_e net_nfc_client_transceive_sync(net_nfc_target_handle_s *handle, - data_s *rawdata); - -net_nfc_error_e net_nfc_client_transceive_data_sync( - net_nfc_target_handle_s *handle, data_s *rawdata, data_s **response); - -/* TODO : move to internal header */ -net_nfc_error_e net_nfc_client_transceive_init(void); - -void net_nfc_client_transceive_deinit(void); - -#endif //__NET_NFC_CLIENT_TRANSCEIVE_H__ diff --git a/client/include/net_nfc_data.h b/client/include/net_nfc_data.h deleted file mode 100644 index e9c2cc8..0000000 --- a/client/include/net_nfc_data.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -/** - - @addtogroup NET_NFC_MANAGER_INFO - @{ - This document is for the APIs reference document - - NFC Manager defines are defined in - - @li @c #net_nfc_client_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) illegal NULL pointer(s) - @exception NET_NFC_ALLOC_FAIL memory allocation is failed - */ - -net_nfc_error_e net_nfc_create_data_only(data_s **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) illegal NULL pointer(s) - @exception NET_NFC_ALLOC_FAIL memory allocation is failed - */ -net_nfc_error_e net_nfc_create_data(data_s **data, const uint8_t *bytes, size_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) illegal NULL pointer(s) - */ -net_nfc_error_e net_nfc_get_data(const data_s *data, uint8_t **bytes, size_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(data_s *data, const uint8_t *bytes, size_t length); - -/** - get length of data handler's bytes. - - @param[in] data data handler - - @return return the length of bytes - - @exception 0 is returned if data is NULL - */ - -size_t net_nfc_get_data_length(const data_s *data); - -/** - get pointer of the handler's bytes (do not free this. it should be freed when the application call "net_nfc_free_data" function - - @param[in] data data handler - - @return return the pointer of bytes. - - @exception NULL is returned if data is NULL - */ - -uint8_t* net_nfc_get_data_buffer(const data_s *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_s *data); - - -/** - @} - */ - -#endif //__NET_NFC_DATA_H__ diff --git a/client/include/net_nfc_ndef_message.h b/client/include/net_nfc_ndef_message.h deleted file mode 100644 index 99c4cab..0000000 --- a/client/include/net_nfc_ndef_message.h +++ /dev/null @@ -1,440 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -/** - - @addtogroup NET_NFC_MANAGER_NDEF - @{ - This document is for the APIs reference document - - NFC Manager defines are defined in - - @li @c #net_nfc_client_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_s *msg = NULL; - ndef_record_s *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_s **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_s *ndef = (ndef_message_s*)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_s *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_s *rawdata; - ndef_message_s *msg = NULL; - ndef_record_s *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_s *ndef_message, data_s **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_s *url; - data_s *ndef_type; - data_s *payload; - - ndef_message_s *ndef = (ndef_message_s*)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_s **ndef_message, data_s *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_s - - \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_s *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_s *rawdata; - ndef_message_s *msg = NULL; - ndef_record_s *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_s *ndef_message, ndef_record_s *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_s *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_s *ndef_message, - int index, ndef_record_s **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_s *ndef_message, - int index, ndef_record_s *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_s *ndef = (ndef_message_s*)data; - ndef_record_s *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_s *ndef_message, - net_nfc_record_tnf_e tnf, data_s *type, ndef_record_s **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_s *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_s **ndef_message); - - -/** - @} - */ - -#endif //__NET_NFC_NDEF_MESSAGE_H__ diff --git a/client/include/net_nfc_ndef_message_handover.h b/client/include/net_nfc_ndef_message_handover.h deleted file mode 100644 index 60ce18a..0000000 --- a/client/include/net_nfc_ndef_message_handover.h +++ /dev/null @@ -1,445 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -/** - 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_s **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_s *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_s *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_s *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_s *config, net_nfc_carrier_property_s *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_s *config, net_nfc_carrier_property_s *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_s *config, int index, net_nfc_carrier_property_s **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_s *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_carrier_property_s **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_carrier_property_s *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_carrier_property_s *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_carrier_property_s *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_carrier_property_s *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_s **record, net_nfc_carrier_config_s *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_s **config, ndef_record_s *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_s *message, - ndef_record_s *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_s *message, - ndef_record_s *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_s *message, - int index, ndef_record_s **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_s *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_s *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_s *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_s *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_s *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_s **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_s **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_s **record, - uint8_t reason, uint32_t data); - -#endif //__NET_NFC_NDEF_MESSAGE_HANDOVER_H__ diff --git a/client/include/net_nfc_ndef_record.h b/client/include/net_nfc_ndef_record.h deleted file mode 100644 index 3b293db..0000000 --- a/client/include/net_nfc_ndef_record.h +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -/** - - @addtogroup NET_NFC_MANAGER_RECORD - @{ - This document is for the APIs reference document - - NFC Manager defines are defined in - -*/ - - -/** - This define gives you Message Begin from the flag byte - - @param[in] flag flag that comes from "net_nfc_get_record_flags" function - @return the mb flag - - @exception NONE - */ -uint8_t net_nfc_get_record_mb (uint8_t flag); -/** - This define gives you Message end from the flag byte - - @param[in] flag flag that comes from "net_nfc_get_record_flags" function - @return the me flag - - @exception NONE - */ -uint8_t net_nfc_get_record_me (uint8_t flag); -/** - This define gives you Chun Flag that indicate that either the first record chunk or a middle record chunk of a chunked payload - - @param[in] flag flag that comes from "net_nfc_get_record_flags" function - @return the chunk flag - - @exception NONE - */ -uint8_t net_nfc_get_record_cf (uint8_t flag); -/** - This define gives you ID length present flag - - @param[in] flag flag that comes from "net_nfc_get_record_flags" function - @return the il (id length flag) flag - - @exception NONE - -*/ -uint8_t net_nfc_get_record_il (uint8_t flag); -/** - This define gives you short record flag. This flag indicates that the payload length filed is a single octet - - @param[in] flag flag that comes from "net_nfc_get_record_flags" function - @return the short record flag - - @exception NONE - */ -uint8_t net_nfc_get_record_sr (uint8_t flag); - - - -/** - creat a record with given parameter value. this function automatically set the NDEF record flags - - @param[out] record Record handler - @param[in] tnf record type (TNF value) empty, well known, mime type, URI, external, or unchanged - @param[in] typeName specify type name ex) Sp, U, or Hr ... - @param[in] id record id - @param[in] payload payload of this record - - @return return the result of the calling the function - - @exception NET_NFC_OUT_OF_BOUND tnf value is out of range - @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) - @exception NET_NFC_ALLOC_FAIL memory allocation is failed - - @code - char uri[] = " yahoo.com"; - ndef_record_s uriRecord; - - data_s *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_s **record, - net_nfc_record_tnf_e tnf, - const data_s *typeName, - const data_s *id, - const data_s *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_s *msg = NULL; - ndef_record_s *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_s **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_s *msg = NULL; - ndef_record_s *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_s **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_s* 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_s *record, - data_s **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_s *record, data_s **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_s *record, data_s **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_s *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_s *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_s *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_s *record, data_s *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_s *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_s *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_s *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_s *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_s *record, char **uri); - -#endif //__NET_NFC_NDEF_RECORD_H__ diff --git a/client/include/net_nfc_sign_record.h b/client/include/net_nfc_sign_record.h deleted file mode 100644 index 35fe4c7..0000000 --- a/client/include/net_nfc_sign_record.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -/** - - @addtogroup NET_NFC_MANAGER_RECORD - @{ - This document is for the APIs reference document - - NFC Manager defines are defined in - -*/ - -/** - this function make the signature of some continuous records - please refer the NFC forum specification "Signature Record type Definition" - - @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added. - @param[in] begin_index the index of beginning record that will be signed. - @param[in] end_index the last index of record that will be signed. - @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type) - @param[in] passowrd the password of cert_file - - @return return the result of the calling the function - - @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) - @exception NET_NFC_ALLOC_FAIL memory allocation is failed - - @code - ndef_message_s *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_s *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_s *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_s *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_s *msg = NULL; - ndef_record_s *begin_record = NULL; - ndef_record_s *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_s *begin_record, - ndef_record_s *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_s *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_s *msg); - -#endif //__NET_NFC_SIGN_RECORD_H__ diff --git a/client/include/net_nfc_target_info.h b/client/include/net_nfc_target_info.h deleted file mode 100644 index 03ceeb4..0000000 --- a/client/include/net_nfc_target_info.h +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -/** - - @addtogroup NET_NFC_MANAGER_INFO - @{ - This document is for the APIs reference document - - NFC Manager defines are defined in - - These APIs help to get infomation of detected target. these target info handler holds - - type of target - - target ID - - ndef message supporting - - max data size (if this tag is ndef message tag) - - actual data size (if this tag is ndef message tag) - */ - -/** - type getter from targte info handler - - \par Sync (or) Async: Sync - This is a Synchronous API - - @param[in] target_info target info handler - @param[out] type tag type these type is one of the enum "net_nfc_target_type_e" defined - - @return return the result of calling this functions - - @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) - -*/ - -net_nfc_error_e net_nfc_get_tag_type(net_nfc_target_info_s *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_s *target_info, - net_nfc_target_handle_s **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_s *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_s *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_s *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_s *target_info = (net_nfc_target_info_s*)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_s *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_s *target_info = (net_nfc_target_info_s*)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_s *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_s *target_info, - const char *key, data_s **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_s *target_info = (net_nfc_target_info_s*)data; - net_nfc_target_info_s *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_s *origin, - net_nfc_target_info_s **result); - -/** - After using net_nfc_target_info_s *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_s *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_s *target_info); - - -/** - @} - */ - -#endif //__NET_NFC_TARGET_INFO_H__ diff --git a/client/net_nfc_client.c b/client/net_nfc_client.c deleted file mode 100644 index 6118ba0..0000000 --- a/client/net_nfc_client.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -#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_phdc.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_handover_init() != NET_NFC_OK) - return; - if(net_nfc_client_phdc_init() != NET_NFC_OK) - return; -} - -void net_nfc_client_gdbus_deinit(void) -{ - net_nfc_client_handover_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_phdc_deinit(); - net_nfc_client_manager_deinit(); -#ifdef SECURITY_SERVER - _deinit_smack(); -#endif -} diff --git a/client/net_nfc_client.h b/client/net_nfc_client.h deleted file mode 100644 index c80142c..0000000 --- a/client/net_nfc_client.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -typedef struct _NetNfcCallback -{ - void *callback; - void *user_data; -} -NetNfcCallback; - -void net_nfc_client_gdbus_init(void); - -void net_nfc_client_gdbus_deinit(void); - -GVariant *net_nfc_client_gdbus_get_privilege(); - -#endif //__NET_NFC_CLIENT_H__ diff --git a/client/net_nfc_client_context.c b/client/net_nfc_client_context.c deleted file mode 100644 index 1b2246e..0000000 --- a/client/net_nfc_client_context.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -#include "net_nfc_debug_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; -} diff --git a/client/net_nfc_client_data.c b/client/net_nfc_client_data.c deleted file mode 100644 index eda8e93..0000000 --- a/client/net_nfc_client_data.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "net_nfc_debug_internal.h" -#include "net_nfc_data.h" -#include "net_nfc_typedef_internal.h" -#include "net_nfc_util_internal.h" - -API net_nfc_error_e net_nfc_create_data_only(data_s **data) -{ - return net_nfc_create_data(data, NULL, 0); -} - -API net_nfc_error_e net_nfc_create_data(data_s **data, const uint8_t *bytes, - const size_t length) -{ - data_s *tmp_data = NULL; - - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - - _net_nfc_util_alloc_mem(tmp_data, sizeof(data_s)); - if (tmp_data == NULL) - return NET_NFC_ALLOC_FAIL; - - if (0 < length) - { - _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 = tmp_data; - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_get_data(const data_s *data, uint8_t **bytes, - size_t *length) -{ - RETV_IF(NULL == bytes, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == length, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - - *bytes = data->buffer; - *length = data->length; - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_set_data(data_s *data, const uint8_t *bytes, - const size_t length) -{ - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - - if (data->buffer == bytes && data->length == length) - return NET_NFC_OK; - - if (data->buffer) - _net_nfc_util_free_mem(data->buffer); - - if (length <= 0) - { - data->buffer = NULL; - data->length = 0; - return NET_NFC_OK; - } - - if (0 < length) - _net_nfc_util_alloc_mem(data->buffer, length); - - if (bytes) - memcpy(data->buffer, bytes, length); - - data->length = length; - - return NET_NFC_OK; -} - -API size_t net_nfc_get_data_length(const data_s *data) -{ - RETV_IF(NULL == data, 0); - - return data->length; -} - -API uint8_t* net_nfc_get_data_buffer(const data_s *data) -{ - RETV_IF(NULL == data, NULL); - - return data->buffer; -} - -API net_nfc_error_e net_nfc_free_data(data_s *data) -{ - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - - if (data->buffer != NULL) - _net_nfc_util_free_mem(data->buffer); - - _net_nfc_util_free_mem(data); - - return NET_NFC_OK; -} \ No newline at end of file diff --git a/client/net_nfc_client_handover.c b/client/net_nfc_client_handover.c deleted file mode 100644 index 1b2a1fb..0000000 --- a/client/net_nfc_client_handover.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - - -static NetNfcGDbusHandover *handover_proxy = NULL; - -static void p2p_connection_handover(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - data_s arg_data; - GError *error = NULL; - GVariant *data = NULL; - net_nfc_error_e result; - NetNfcCallback *func_data = user_data; - net_nfc_p2p_connection_handover_completed_cb callback; - net_nfc_conn_handover_carrier_type_e type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_handover_call_request_finish(handover_proxy, - (gint *)&result, (gint *)&type, &data, res, &error); - - if (FALSE == ret) - { - NFC_ERR("Can not finish connection handover: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - callback = (net_nfc_p2p_connection_handover_completed_cb)func_data->callback; - - net_nfc_util_gdbus_variant_to_data_s(data, &arg_data); - - callback(result, type, &arg_data, func_data->user_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_s *info) -{ - RETV_IF(NULL == info, NET_NFC_NULL_PARAMETER); - - if (info->data.buffer != NULL) - _net_nfc_util_free_mem(info->data.buffer); - - _net_nfc_util_free_mem(info); - - return NET_NFC_OK; -} - - -API net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_type( - net_nfc_connection_handover_info_s *info, - net_nfc_conn_handover_carrier_type_e *type) -{ - RETV_IF(NULL == info, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == type, NET_NFC_NULL_PARAMETER); - - *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_s *info, data_s **data) -{ - RETV_IF(NULL == info, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - - return net_nfc_create_data(data, info->data.buffer, info->data.length); -} - - -API net_nfc_error_e net_nfc_client_p2p_connection_handover( - net_nfc_target_handle_s *handle, - net_nfc_conn_handover_carrier_type_e arg_type, - net_nfc_p2p_connection_handover_completed_cb callback, - void *cb_data) -{ - NetNfcCallback *funcdata; - - RETV_IF(NULL == handover_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - funcdata = g_try_new0(NetNfcCallback, 1); - RETV_IF(NULL == funcdata, NET_NFC_ALLOC_FAIL); - - funcdata->callback = (gpointer)callback; - funcdata->user_data = cb_data; - - net_nfc_gdbus_handover_call_request(handover_proxy, - GPOINTER_TO_UINT(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_s *handle, - net_nfc_conn_handover_carrier_type_e arg_type, - net_nfc_conn_handover_carrier_type_e *out_carrier, - data_s **out_ac_data) -{ - gboolean ret; - GError *error = NULL; - GVariant *out_data = NULL; - net_nfc_error_e out_result = NET_NFC_OK; - net_nfc_conn_handover_carrier_type_e out_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; - - RETV_IF(NULL == handover_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - ret = net_nfc_gdbus_handover_call_request_sync(handover_proxy, - GPOINTER_TO_UINT(handle), - arg_type, - net_nfc_client_gdbus_get_privilege(), - (gint32 *)&out_result, - (gint32 *)&out_type, - &out_data, - NULL, - &error); - - if (TRUE == ret) - { - if (out_carrier) - *out_carrier = out_type; - - if (out_ac_data) - *out_ac_data = net_nfc_util_gdbus_variant_to_data(out_data); - } - else - { - NFC_ERR("handover (sync call) failed: %s",error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - return out_result; -} - - -net_nfc_error_e net_nfc_client_handover_init(void) -{ - GError *error = NULL; - - if (handover_proxy) - { - NFC_WARN("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 (NULL == handover_proxy) - { - NFC_ERR("Can not create proxy : %s", error->message); - g_error_free(error); - return NET_NFC_UNKNOWN_ERROR; - } - - return NET_NFC_OK; -} - - -void net_nfc_client_handover_deinit(void) -{ - if (handover_proxy) - { - g_object_unref(handover_proxy); - handover_proxy = NULL; - } -} diff --git a/client/net_nfc_client_llcp.c b/client/net_nfc_client_llcp.c deleted file mode 100644 index e90b780..0000000 --- a/client/net_nfc_client_llcp.c +++ /dev/null @@ -1,1919 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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; - -/* signal callback */ -static void llcp_error(NetNfcGDbusLlcp *object, guint arg_handle, guint client_socket, - gint error, gpointer user_data) -{ - NFC_INFO(">>> SIGNAL arrived"); -} - -static void llcp_incoming(NetNfcGDbusLlcp *object, guint arg_handle, - guint client_socket, guint incoming_socket, gpointer user_data) -{ - NFC_INFO(">>> SIGNAL arrived"); -} - -void llcp_socket_data_append(net_nfc_llcp_internal_socket_s *socket_data) -{ - RET_IF(NULL == socket_data_list); - - 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) -{ - RET_IF(NULL == socket_data_list); - - 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; - - RETV_IF(NULL == socket_data_list, 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; -} - -/* aysnc callback */ -static void llcp_call_config(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - LlcpFuncData *func_data = user_data; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_config_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish config: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - net_nfc_client_llcp_config_completed callback = - (net_nfc_client_llcp_config_completed)func_data->callback; - - callback(result, func_data->user_data); - } - - g_free(func_data); -} - -static void llcp_call_listen(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket = -1; - LlcpFuncData *func_data = user_data; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_listen_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, &out_client_socket, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish listen: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - socket_data = llcp_socket_data_find(out_client_socket); - if (socket_data == NULL) - { - NFC_ERR("Wrong client socket is returned"); - return; - } - - if (func_data->callback != NULL) - { - net_nfc_client_llcp_listen_completed callback = - (net_nfc_client_llcp_listen_completed)func_data->callback; - - callback(result, out_client_socket, func_data->user_data); - } - - /* TODO : release resource when socket is closed */ - // g_free(func_data); -} - -static void llcp_call_accept(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - LlcpFuncData *func_data = user_data; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_accept_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish accept: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - net_nfc_client_llcp_accept_completed callback = - (net_nfc_client_llcp_accept_completed)func_data->callback; - - callback(result, func_data->user_data); - } - - g_free(func_data); -} - -static void llcp_call_reject(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - LlcpFuncData *func_data = user_data; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_reject_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish reject: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - net_nfc_client_llcp_reject_completed callback = - (net_nfc_client_llcp_reject_completed)func_data->callback; - - callback(result, func_data->user_data); - } - - g_free(func_data); -} - -static void llcp_call_connect(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket = -1; - LlcpFuncData *func_data = user_data; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_connect_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, &out_client_socket, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish connect: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - socket_data = llcp_socket_data_find(out_client_socket); - if (socket_data == NULL) - { - NFC_ERR("Wrong client socket is returned"); - return; - } - - if (func_data->callback != NULL) - { - net_nfc_client_llcp_connect_completed callback = - (net_nfc_client_llcp_connect_completed)func_data->callback; - - callback(result, out_client_socket, func_data->user_data); - } - - /* TODO : release resource when socket is closed */ - // g_free(func_data); -} - -static void llcp_call_connect_sap(GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket = -1; - LlcpFuncData *func_data = user_data; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_connect_sap_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, &out_client_socket, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish connect sap: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - socket_data = llcp_socket_data_find(out_client_socket); - if (socket_data == NULL) - { - NFC_ERR("Wrong client socket is returned"); - return; - } - - if (func_data->callback != NULL) - { - net_nfc_client_llcp_connect_sap_completed callback = - (net_nfc_client_llcp_connect_sap_completed)func_data->callback; - - callback(result, out_client_socket, func_data->user_data); - } - - /* TODO : release resource when socket is closed */ - // g_free(func_data); -} - -static void llcp_call_send(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket = -1; - LlcpFuncData *func_data = user_data; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_send_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, &out_client_socket, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish send: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - net_nfc_client_llcp_send_completed callback = - (net_nfc_client_llcp_send_completed)func_data->callback; - - callback(result, func_data->user_data); - } - - g_free(func_data); -} - -static void llcp_call_send_to(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket = -1; - LlcpFuncData *func_data = user_data; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_send_to_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, &out_client_socket, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish send to: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - net_nfc_client_llcp_send_to_completed callback = - (net_nfc_client_llcp_send_to_completed)func_data->callback; - - callback(result, func_data->user_data); - } - - g_free(func_data); -} - -static void llcp_call_receive(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GVariant *variant; - GError *error = NULL; - net_nfc_error_e result; - LlcpFuncData *func_data = user_data; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_receive_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, &variant, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish receive: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - data_s data = { NULL, 0 }; - net_nfc_client_llcp_receive_completed callback = - (net_nfc_client_llcp_receive_completed)func_data->callback; - - net_nfc_util_gdbus_variant_to_data_s(variant, &data); - - 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) -{ - gboolean ret; - sap_t sap = 0; - GError *error = NULL; - net_nfc_error_e result; - GVariant *variant = NULL; - LlcpFuncData *func_data = user_data; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_receive_from_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, &sap, &variant, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish receive from: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - data_s data = { NULL, 0 }; - net_nfc_client_llcp_receive_from_completed callback = - (net_nfc_client_llcp_receive_from_completed)func_data->callback; - - net_nfc_util_gdbus_variant_to_data_s(variant, &data); - - 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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket = -1; - LlcpFuncData *func_data = user_data; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_close_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, &out_client_socket, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish close: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - socket_data = llcp_socket_data_find(out_client_socket); - if (socket_data == NULL) - { - NFC_ERR("Wrong client socket is returned"); - return; - } - - if (func_data->callback != NULL) - { - net_nfc_client_llcp_close_completed callback = - (net_nfc_client_llcp_close_completed)func_data->callback; - - callback(result, func_data->user_data); - } - - g_free(func_data); -} - -static void llcp_call_disconnect(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket = -1; - LlcpFuncData *func_data = user_data; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - - g_assert(func_data != NULL); - - ret = net_nfc_gdbus_llcp_call_disconnect_finish(NET_NFC_GDBUS_LLCP(source_object), - &result, &out_client_socket, res, &error); - if (FALSE == ret) - { - NFC_ERR("Can not finish disconnect: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - socket_data = llcp_socket_data_find(out_client_socket); - if (socket_data == NULL) - { - NFC_ERR("Wrong client socket is returned"); - return; - } - - if (func_data->callback != NULL) { - net_nfc_client_llcp_disconnect_completed callback = - (net_nfc_client_llcp_disconnect_completed)func_data->callback; - - callback(result, func_data->user_data); - } - - g_free(func_data); -} - - -/* Public APIs */ -API net_nfc_error_e net_nfc_client_llcp_config(net_nfc_llcp_config_info_s *config, - net_nfc_client_llcp_config_completed callback, void *user_data) -{ - GVariant *var; - LlcpFuncData *func_data; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) - { - NFC_ERR("g_new0 failed"); - return NET_NFC_ALLOC_FAIL; - } - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - memcpy(&llcp_config, config, sizeof(net_nfc_llcp_config_info_s)); - - var = g_variant_new("(qqyy)", config->miu, config->wks, config->lto, config->option); - - net_nfc_gdbus_llcp_call_config(llcp_proxy, var, 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_s *config) -{ - gboolean ret; - GVariant *var = NULL; - GError *error = NULL; - net_nfc_error_e result; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - memcpy(&llcp_config, config, sizeof(net_nfc_llcp_config_info_s)); - - var = g_variant_new("(qqyy)", config->miu, config->wks, config->lto, config->option); - - ret = net_nfc_gdbus_llcp_call_config_sync(llcp_proxy, var, - net_nfc_client_gdbus_get_privilege(), &result, NULL, &error); - if (FALSE == ret) - { - NFC_ERR("can not config: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -API net_nfc_error_e net_nfc_client_llcp_get_config( - net_nfc_llcp_config_info_s **config) -{ - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - - *config = &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; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("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; - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) { - NFC_ERR("g_new0 failed"); - - return NET_NFC_ALLOC_FAIL; - } - - 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->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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - net_nfc_llcp_internal_socket_s *out_socket_data = NULL; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(NULL == out_socket, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == service_name, NET_NFC_NULL_PARAMETER); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("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; - - ret = net_nfc_gdbus_llcp_call_listen_sync(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket_data->client_socket, - socket_data->miu, - socket_data->rw, - socket_data->type, - socket_data->sap, - service_name, - net_nfc_client_gdbus_get_privilege(), - &result, - &out_client_socket, - NULL, - &error); - if (TRUE == ret) - { - out_socket_data = llcp_socket_data_find(out_client_socket); - if (out_socket_data == NULL || out_socket_data != socket_data) - { - NFC_ERR("out_socket_data(%p), socket_data(%p)", out_socket_data, socket_data); - return NET_NFC_UNKNOWN_ERROR; - } - - if (out_socket) - *out_socket = out_client_socket; - } - else - { - NFC_ERR("can not listen: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -API net_nfc_error_e net_nfc_client_llcp_accept(net_nfc_llcp_socket_t socket, - net_nfc_client_llcp_accept_completed callback, void *user_data) -{ - LlcpFuncData *func_data; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) - { - NFC_ERR("g_new0 failed"); - return NET_NFC_ALLOC_FAIL; - } - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - net_nfc_gdbus_llcp_call_accept(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket, - net_nfc_client_gdbus_get_privilege(), - NULL, - llcp_call_accept, - func_data); - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_accept_sync(net_nfc_llcp_socket_t socket) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - ret = net_nfc_gdbus_llcp_call_accept_sync(llcp_proxy, GPOINTER_TO_UINT(llcp_handle), - socket, net_nfc_client_gdbus_get_privilege(), &result, NULL, &error); - if (FALSE == ret) - { - NFC_ERR("can not connect: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -API net_nfc_error_e net_nfc_client_llcp_reject(net_nfc_llcp_socket_t socket, - net_nfc_client_llcp_reject_completed callback, void *user_data) -{ - LlcpFuncData *func_data; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) - { - NFC_ERR("g_new0 failed"); - return NET_NFC_ALLOC_FAIL; - } - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - net_nfc_gdbus_llcp_call_reject(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket, - net_nfc_client_gdbus_get_privilege(), - NULL, - llcp_call_reject, - func_data); - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_reject_sync(net_nfc_llcp_socket_t socket) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - ret = net_nfc_gdbus_llcp_call_reject_sync(llcp_proxy, GPOINTER_TO_UINT(llcp_handle), - socket, net_nfc_client_gdbus_get_privilege(), &result, NULL, &error); - if (FALSE == ret) - { - NFC_ERR("can not connect: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -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; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(NULL == service_name, NET_NFC_NULL_PARAMETER); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) - { - NFC_ERR("g_new0 failed"); - - return NET_NFC_ALLOC_FAIL; - } - - 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->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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - net_nfc_llcp_internal_socket_s *out_socket_data = NULL; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(NULL == service_name, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == out_socket, NET_NFC_NULL_PARAMETER); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - ret = net_nfc_gdbus_llcp_call_connect_sync(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket_data->client_socket, - socket_data->miu, - socket_data->rw, - socket_data->type, - service_name, - net_nfc_client_gdbus_get_privilege(), - &result, - &out_client_socket, - NULL, - &error); - if (TRUE == ret) - { - out_socket_data = llcp_socket_data_find(out_client_socket); - if (out_socket_data == NULL || out_socket_data != socket_data) - { - NFC_ERR("out_socket_data(%p), socket_data(%p)", out_socket_data, socket_data); - return NET_NFC_UNKNOWN_ERROR; - } - - if (out_socket) - *out_socket = out_client_socket; - } - else - { - NFC_ERR("can not connect: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -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; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(0 == sap, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) - { - NFC_ERR("g_new0 failed"); - return NET_NFC_ALLOC_FAIL; - } - - 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->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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - net_nfc_llcp_internal_socket_s *out_socket_data = NULL; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(NULL == out_socket, NET_NFC_NULL_PARAMETER); - RETV_IF(0 == sap, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - ret = net_nfc_gdbus_llcp_call_connect_sap_sync(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket_data->client_socket, - socket_data->miu, - socket_data->rw, - socket_data->type, - sap, - net_nfc_client_gdbus_get_privilege(), - &result, - &out_client_socket, - NULL, - &error); - if (TRUE == ret) - { - out_socket_data = llcp_socket_data_find(out_client_socket); - if (out_socket_data == NULL || out_socket_data != socket_data) - { - NFC_ERR("out_socket_data(%p), socket_data(%p)", out_socket_data, socket_data); - return NET_NFC_UNKNOWN_ERROR; - } - - if (out_socket) - *out_socket = out_client_socket; - } - else - { - NFC_ERR("can not connect: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -API net_nfc_error_e net_nfc_client_llcp_send(net_nfc_llcp_socket_t socket, - data_s *data, net_nfc_client_llcp_send_completed callback, void *user_data) -{ - GVariant *variant; - LlcpFuncData *func_data; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) - { - NFC_ERR("g_new0 failed"); - return NET_NFC_ALLOC_FAIL; - } - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - variant = net_nfc_util_gdbus_data_to_variant(data); - - net_nfc_gdbus_llcp_call_send(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket_data->client_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_s *data) -{ - gboolean ret; - GVariant *variant; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket; - net_nfc_llcp_internal_socket_s *socket_data; - net_nfc_llcp_internal_socket_s *out_socket_data; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - variant = net_nfc_util_gdbus_data_to_variant(data); - - ret = net_nfc_gdbus_llcp_call_send_sync(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket_data->client_socket, - variant, - net_nfc_client_gdbus_get_privilege(), - &result, - &out_client_socket, - NULL, - &error); - if (TRUE == ret) - { - out_socket_data = llcp_socket_data_find(out_client_socket); - if (out_socket_data == NULL) - { - NFC_ERR("out_socket_data is NULL"); - return NET_NFC_UNKNOWN_ERROR; - } - } - else - { - NFC_ERR("can not call send: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -API net_nfc_error_e net_nfc_client_llcp_send_to(net_nfc_llcp_socket_t socket, - sap_t sap, - data_s *data, - net_nfc_client_llcp_send_to_completed callback, - void *user_data) -{ - GVariant *variant; - LlcpFuncData *func_data; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - RETV_IF(0 == sap, NET_NFC_INVALID_PARAM); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) - { - NFC_ERR("g_new0 failed"); - return NET_NFC_ALLOC_FAIL; - } - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - variant = net_nfc_util_gdbus_data_to_variant(data); - - net_nfc_gdbus_llcp_call_send_to(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket_data->client_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_s *data) -{ - gboolean ret; - GVariant *variant; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket; - net_nfc_llcp_internal_socket_s *socket_data; - net_nfc_llcp_internal_socket_s *out_socket_data; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - RETV_IF(0 == sap, NET_NFC_INVALID_PARAM); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - variant = net_nfc_util_gdbus_data_to_variant(data); - - ret = net_nfc_gdbus_llcp_call_send_to_sync(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket_data->client_socket, - sap, - variant, - net_nfc_client_gdbus_get_privilege(), - &result, - &out_client_socket, - NULL, - &error); - if (TRUE == ret) - { - out_socket_data = llcp_socket_data_find(out_client_socket); - if (out_socket_data == NULL) - { - NFC_ERR("out_socket_data is NULL"); - return NET_NFC_UNKNOWN_ERROR; - } - } - else - { - NFC_ERR("can not call send to: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -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; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(0 == request_length, NET_NFC_INVALID_PARAM); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) - { - NFC_ERR("g_new0 failed"); - return NET_NFC_ALLOC_FAIL; - } - - 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, - 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_s **out_data) -{ - gboolean ret; - GVariant *variant; - GError *error = NULL; - net_nfc_error_e result; - net_nfc_llcp_internal_socket_s *socket_data; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(NULL == out_data, NET_NFC_NULL_PARAMETER); - RETV_IF(0 == request_length, NET_NFC_INVALID_PARAM); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - *out_data = NULL; - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - ret = net_nfc_gdbus_llcp_call_receive_sync(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket_data->client_socket, - request_length, - net_nfc_client_gdbus_get_privilege(), - &result, - &variant, - NULL, - &error); - if (TRUE == ret) - { - *out_data = net_nfc_util_gdbus_variant_to_data(variant); - } - else - { - NFC_ERR("can not call receive: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -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; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(0 == request_length, NET_NFC_INVALID_PARAM); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) - { - NFC_ERR("g_new0 failed"); - return NET_NFC_ALLOC_FAIL; - } - - 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, - 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_s **out_data) -{ - sap_t sap; - gboolean ret; - GVariant *variant; - GError *error = NULL; - net_nfc_error_e result; - net_nfc_llcp_internal_socket_s *socket_data; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(NULL == out_sap, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == out_data, NET_NFC_NULL_PARAMETER); - RETV_IF(0 == request_length, NET_NFC_INVALID_PARAM); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - *out_data = NULL; - *out_sap = 0; - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - ret = net_nfc_gdbus_llcp_call_receive_from_sync(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket_data->client_socket, - request_length, - net_nfc_client_gdbus_get_privilege(), - &result, - &sap, - &variant, - NULL, - &error); - if (TRUE == ret) - { - *out_sap = sap; - *out_data = net_nfc_util_gdbus_variant_to_data(variant); - } - else - { - NFC_ERR("can not call receive from: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -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; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) - { - NFC_ERR("g_new0 failed"); - return NET_NFC_ALLOC_FAIL; - } - - 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, - 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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - net_nfc_llcp_internal_socket_s *out_socket_data = NULL; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - ret = net_nfc_gdbus_llcp_call_close_sync(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket_data->client_socket, - net_nfc_client_gdbus_get_privilege(), - &result, - &out_client_socket, - NULL, - &error); - if (TRUE == ret) - { - out_socket_data = llcp_socket_data_find(out_client_socket); - if (out_socket_data == NULL || out_socket_data != socket_data) - { - NFC_ERR("out_socket_data(%p), socket_data(%p)", out_socket_data, socket_data); - return NET_NFC_UNKNOWN_ERROR; - } - } - else - { - NFC_ERR("can not close: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -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; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - func_data = g_new0(LlcpFuncData, 1); - if (func_data == NULL) - { - NFC_ERR("g_new0 failed"); - return NET_NFC_ALLOC_FAIL; - } - - 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, - 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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - guint32 out_client_socket; - net_nfc_llcp_internal_socket_s *socket_data = NULL; - net_nfc_llcp_internal_socket_s *out_socket_data = NULL; - - RETV_IF(NULL == llcp_proxy, NET_NFC_NOT_INITIALIZED); - RETV_IF(socket <= 0, NET_NFC_INVALID_PARAM); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - { - NFC_ERR("can not get socket_data"); - return NET_NFC_LLCP_INVALID_SOCKET; - } - - ret = net_nfc_gdbus_llcp_call_disconnect_sync(llcp_proxy, - GPOINTER_TO_UINT(llcp_handle), - socket_data->client_socket, - net_nfc_client_gdbus_get_privilege(), - &result, - &out_client_socket, - NULL, - &error); - if (TRUE == ret) - { - out_socket_data = llcp_socket_data_find(out_client_socket); - if (out_socket_data == NULL || out_socket_data != socket_data) - { - NFC_ERR("out_socket_data(%p), socket_data(%p)", out_socket_data, socket_data); - return NET_NFC_UNKNOWN_ERROR; - } - } - else - { - NFC_ERR("can not disconnect: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -API void net_nfc_client_llcp_create_socket(net_nfc_llcp_socket_t *socket, - net_nfc_llcp_socket_option_s *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_s **config) -{ - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - - *config = &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_s **info) -{ - net_nfc_llcp_internal_socket_s *socket_data = NULL; - - socket_data = llcp_socket_data_find(socket); - if (socket_data == NULL) - return NET_NFC_LLCP_INVALID_SOCKET; - - *info = (net_nfc_llcp_socket_option_s*)socket_data; - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_create_socket_option( - net_nfc_llcp_socket_option_s **option, - uint16_t miu, - uint8_t rw, - net_nfc_socket_type_e type) -{ - net_nfc_llcp_socket_option_s *tmp_option = NULL; - - RETV_IF(NULL == option, NET_NFC_NULL_PARAMETER); - RETVM_IF(miu < 128 || miu > 1152, NET_NFC_OUT_OF_BOUND, "miu = %d", miu); - RETVM_IF(rw < 1 || rw > 15, NET_NFC_OUT_OF_BOUND, "rw = %d", rw); - RETVM_IF((type < NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED - || type > NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS), - NET_NFC_OUT_OF_BOUND, - "type = %d", type); - - _net_nfc_util_alloc_mem(tmp_option, sizeof(net_nfc_llcp_socket_option_s)); - if (tmp_option != NULL) - { - tmp_option->miu = miu; - tmp_option->rw = rw; - tmp_option->type = type; - - *option = tmp_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_s **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_s *option, uint16_t *miu) -{ - RETV_IF(NULL == option, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == miu, NET_NFC_NULL_PARAMETER); - - *miu = option->miu; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_set_socket_option_miu( - net_nfc_llcp_socket_option_s *option, uint16_t miu) -{ - RETV_IF(NULL == option, NET_NFC_NULL_PARAMETER); - - 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_s *option, uint8_t *rw) -{ - RETV_IF(NULL == option, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == rw, NET_NFC_NULL_PARAMETER); - - *rw = option->rw; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_set_socket_option_rw( - net_nfc_llcp_socket_option_s *option, uint8_t rw) -{ - RETV_IF(NULL == option, NET_NFC_NULL_PARAMETER); - - 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_s *option, net_nfc_socket_type_e *type) -{ - RETV_IF(NULL == type, NET_NFC_NULL_PARAMETER); - - *type = option->type; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_set_socket_option_type( - net_nfc_llcp_socket_option_s *option, net_nfc_socket_type_e type) -{ - RETV_IF(NULL == option, NET_NFC_NULL_PARAMETER); - - option->type = type; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_free_socket_option( - net_nfc_llcp_socket_option_s *option) -{ - RETV_IF(NULL == option, 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_s **config, - uint16_t miu, - uint16_t wks, - uint8_t lto, - uint8_t option) -{ - net_nfc_llcp_config_info_s *tmp_config; - - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - - _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; - - *config = tmp_config; - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_create_config_default( - net_nfc_llcp_config_info_s **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_s *config, uint16_t *miu) -{ - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == miu, NET_NFC_NULL_PARAMETER); - - *miu = config->miu; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_get_config_wks( - net_nfc_llcp_config_info_s *config, uint16_t *wks) -{ - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == wks, NET_NFC_NULL_PARAMETER); - - *wks = config->wks; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_get_config_lto( - net_nfc_llcp_config_info_s *config, uint8_t *lto) -{ - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == lto, NET_NFC_NULL_PARAMETER); - - *lto = config->lto; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_get_config_option( - net_nfc_llcp_config_info_s *config, uint8_t *option) -{ - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == option, NET_NFC_NULL_PARAMETER); - - *option = config->option; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_set_config_miu( - net_nfc_llcp_config_info_s *config, uint16_t miu) -{ - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - RETVM_IF(miu < 128 || miu > 1152, NET_NFC_OUT_OF_BOUND, "miu = %d", miu); - - config->miu = miu; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_set_config_wks( - net_nfc_llcp_config_info_s *config, uint16_t wks) -{ - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - - config->wks = wks; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_set_config_lto( - net_nfc_llcp_config_info_s *config, uint8_t lto) -{ - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - - config->lto = lto; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_set_config_option( - net_nfc_llcp_config_info_s *config, uint8_t option) -{ - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - - config->option = option; - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_llcp_free_config( - net_nfc_llcp_config_info_s *config) -{ - RETV_IF(NULL == config, 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) - { - NFC_WARN("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) - { - NFC_ERR("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); - - g_signal_connect(llcp_proxy, "incoming", - G_CALLBACK(llcp_incoming), NULL); - - return NET_NFC_OK; -} - -void net_nfc_client_llcp_deinit(void) -{ - if (llcp_proxy) - { - g_object_unref(llcp_proxy); - llcp_proxy = NULL; - } -} diff --git a/client/net_nfc_client_manager.c b/client/net_nfc_client_manager.c deleted file mode 100644 index 49ac7a7..0000000 --- a/client/net_nfc_client_manager.c +++ /dev/null @@ -1,368 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -#define DEACTIVATE_DELAY 500 /* ms */ - -typedef struct _ManagerFuncData ManagerFuncData; - -struct _ManagerFuncData -{ - gpointer callback; - gpointer user_data; - net_nfc_error_e result; -}; - -static NetNfcGDbusManager *manager_proxy = NULL; -static gboolean activation_is_running = FALSE; -static ManagerFuncData activated_func_data; -static int is_activated = -1; -static guint timeout_id[2]; - -static gboolean _set_activate_time_elapsed_callback(gpointer user_data) -{ - net_nfc_client_manager_set_active_completed callback; - ManagerFuncData *func_data = user_data; - - g_assert(func_data != NULL); - - timeout_id[0] = 0; - - callback = (net_nfc_client_manager_set_active_completed)func_data->callback; - - callback(func_data->result, func_data->user_data); - - g_free(func_data); - - return false; -} - -static void manager_call_set_active_callback(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - ManagerFuncData *func_data = user_data; - - g_assert(user_data != NULL); - - activation_is_running = FALSE; - - ret = net_nfc_gdbus_manager_call_set_active_finish( - NET_NFC_GDBUS_MANAGER(source_object), &result, res, &error); - - if (FALSE == ret) - { - NFC_ERR("Can not finish call_set_active: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - func_data->result = result; - net_nfc_client_get_nfc_state(&is_activated); - - if (is_activated == false) - { - //TODO : wait several times - timeout_id[0] = g_timeout_add(DEACTIVATE_DELAY, _set_activate_time_elapsed_callback, - func_data); - } - else - { - g_main_context_invoke(NULL, _set_activate_time_elapsed_callback, func_data); - } -} - -static void manager_call_get_server_state_callback(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - guint out_state = 0; - GError *error = NULL; - net_nfc_error_e result; - NetNfcCallback *func_data = user_data; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_manager_call_get_server_state_finish( - NET_NFC_GDBUS_MANAGER(source_object), - &result, - &out_state, - res, - &error); - - if (FALSE == ret) - { - NFC_ERR("Can not finish get_server_state: %s", - error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - net_nfc_client_manager_get_server_state_completed callback = - (net_nfc_client_manager_get_server_state_completed)func_data->callback; - - callback(result, out_state, func_data->user_data); - } - - g_free(func_data); -} - -static gboolean _activated_time_elapsed_callback(gpointer user_data) -{ - net_nfc_client_manager_activated callback = - (net_nfc_client_manager_activated)activated_func_data.callback; - - timeout_id[1] = 0; - - callback(is_activated, activated_func_data.user_data); - - return false; -} - -static void manager_activated(NetNfcGDbusManager *manager, gboolean activated, - gpointer user_data) -{ - NFC_INFO(">>> SIGNAL arrived : activated %d", activated); - - /* update current state */ - is_activated = (int)activated; - - if (activated_func_data.callback != NULL) - { - if (is_activated == false) - { - /* FIXME : wait several times */ - timeout_id[1] = g_timeout_add(DEACTIVATE_DELAY, - _activated_time_elapsed_callback, NULL); - } - else - { - g_main_context_invoke(NULL, _activated_time_elapsed_callback, NULL); - } - } -} - -API void net_nfc_client_manager_set_activated( - net_nfc_client_manager_activated callback, void *user_data) -{ - RET_IF(NULL == callback); - - activated_func_data.callback = callback; - activated_func_data.user_data = user_data; -} - -API void net_nfc_client_manager_unset_activated(void) -{ - activated_func_data.callback = NULL; - activated_func_data.user_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; - - RETV_IF(NULL == manager_proxy, NET_NFC_NOT_INITIALIZED); - - /* allow this function even nfc is off */ - RETV_IF(TRUE == activation_is_running, NET_NFC_BUSY); - - activation_is_running = TRUE; - - func_data = g_try_new0(ManagerFuncData, 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_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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e out_result = NET_NFC_OK; - - RETV_IF(NULL == manager_proxy, NET_NFC_NOT_INITIALIZED); - - /* allow this function even nfc is off */ - - ret = net_nfc_gdbus_manager_call_set_active_sync(manager_proxy, - (gboolean)state, - net_nfc_client_gdbus_get_privilege(), - &out_result, - NULL, - &error); - - if (FALSE == ret) - { - NFC_ERR("can not call SetActive: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - return out_result; -} - -API net_nfc_error_e net_nfc_client_manager_get_server_state( - net_nfc_client_manager_get_server_state_completed callback, void *user_data) -{ - NetNfcCallback *func_data; - - RETV_IF(NULL == manager_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_try_new0(NetNfcCallback, 1); - if (func_data == NULL) - return NET_NFC_ALLOC_FAIL; - - 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) -{ - gboolean ret; - guint out_state = 0; - GError *error = NULL; - net_nfc_error_e out_result = NET_NFC_OK; - - RETV_IF(NULL == state, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == manager_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - *state = 0; - - ret = net_nfc_gdbus_manager_call_get_server_state_sync(manager_proxy, - net_nfc_client_gdbus_get_privilege(), - &out_result, - &out_state, - NULL, - &error); - - if (TRUE == ret) - { - *state = out_state; - } - else - { - NFC_ERR("can not call GetServerState: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - return out_result; -} - -net_nfc_error_e net_nfc_client_manager_init(void) -{ - GError *error = NULL; - - if (manager_proxy) - { - NFC_WARN("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 (NULL == manager_proxy) - { - NFC_ERR("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) - { - int i; - - for (i = 0; i < 2; i++) - { - if (timeout_id[i] > 0) - { - g_source_remove(timeout_id[i]); - timeout_id[i] = 0; - } - } - - g_object_unref(manager_proxy); - manager_proxy = 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; -} diff --git a/client/net_nfc_client_ndef.c b/client/net_nfc_client_ndef.c deleted file mode 100644 index 71c18f2..0000000 --- a/client/net_nfc_client_ndef.c +++ /dev/null @@ -1,502 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - -static NetNfcGDbusNdef *ndef_proxy = NULL; - -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 (NULL == target_info) - { - NFC_ERR("target_info does not exist"); - return FALSE; - } - - switch (target_info->devType) - { - case NET_NFC_ISO14443_A_PICC : - case NET_NFC_MIFARE_MINI_PICC : - case NET_NFC_MIFARE_1K_PICC : - case NET_NFC_MIFARE_4K_PICC : - case NET_NFC_MIFARE_ULTRA_PICC : - case NET_NFC_JEWEL_PICC : - return TRUE; - break; - default: - NFC_ERR("not supported tag(%d) for read only tag", target_info->devType); - return FALSE; - } -} - -static void ndef_call_read(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - GVariant *out_data = NULL; - net_nfc_error_e out_result; - NetNfcCallback *func_data = user_data; - net_nfc_client_ndef_read_completed callback; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_ndef_call_read_finish(NET_NFC_GDBUS_NDEF(source_object), - (gint *)&out_result, &out_data, res, &error); - - if (FALSE == ret) - { - - NFC_ERR("Can not finish read: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - ndef_message_s *message; - - callback = (net_nfc_client_ndef_read_completed)func_data->callback; - - message = net_nfc_util_gdbus_variant_to_ndef_message(out_data); - - callback(out_result, message, func_data->user_data); - - net_nfc_util_free_ndef_message(message); - } - - g_free(func_data); -} - -static void ndef_call_write(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e out_result; - NetNfcCallback *func_data = user_data; - net_nfc_client_ndef_write_completed callback; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_ndef_call_write_finish(NET_NFC_GDBUS_NDEF(source_object), - (gint *)&out_result, res, &error); - - if (FALSE == ret) - { - NFC_ERR("Can not finish write: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - 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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e out_result; - NetNfcCallback *func_data = user_data; - net_nfc_client_ndef_make_read_only_completed callback; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_ndef_call_make_read_only_finish(NET_NFC_GDBUS_NDEF(source_object), - (gint *)&out_result, res, &error); - - if (FALSE == ret) - { - NFC_ERR("Can not finish make read only: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - 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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e out_result; - NetNfcCallback *func_data = user_data; - net_nfc_client_ndef_format_completed callback; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_ndef_call_format_finish(NET_NFC_GDBUS_NDEF(source_object), - (gint *)&out_result, res, &error); - - if (FALSE == ret) - { - NFC_ERR("Can not finish format: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - 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_s *handle, - net_nfc_client_ndef_read_completed callback, void *user_data) -{ - NetNfcCallback *func_data; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == ndef_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_NOT_CONNECTED); - - NFC_DBG("send request :: read ndef = [%p]", handle); - - func_data = g_try_new0(NetNfcCallback, 1); - if (NULL == func_data) - return NET_NFC_ALLOC_FAIL; - - 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_s *handle, - ndef_message_s **message) -{ - gboolean ret; - GError *error = NULL; - GVariant *out_data = NULL; - net_nfc_error_e out_result = NET_NFC_OK; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == ndef_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_NOT_CONNECTED); - - NFC_DBG("send request :: read ndef = [%p]", handle); - - ret = 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); - - if (TRUE == ret) - { - *message = net_nfc_util_gdbus_variant_to_ndef_message(out_data); - } - else - { - NFC_ERR("can not call read: %s", error->message); - g_error_free(error); - out_result = NET_NFC_IPC_FAIL; - } - - return out_result; -} - -API net_nfc_error_e net_nfc_client_ndef_write(net_nfc_target_handle_s *handle, - ndef_message_s *message, - net_nfc_client_ndef_write_completed callback, - void *user_data) -{ - GVariant *arg_data; - NetNfcCallback *func_data; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == message, NET_NFC_NULL_PARAMETER); - - RETV_IF(NULL == ndef_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_NOT_CONNECTED); - - func_data = g_try_new0(NetNfcCallback, 1); - if (NULL == func_data) - return NET_NFC_ALLOC_FAIL; - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - arg_data = net_nfc_util_gdbus_ndef_message_to_variant(message); - - 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_s *handle, - ndef_message_s *message) -{ - gboolean ret; - GVariant *arg_data; - GError *error = NULL; - net_nfc_error_e out_result = NET_NFC_OK; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == message, NET_NFC_NULL_PARAMETER); - - RETV_IF(NULL == ndef_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_NOT_CONNECTED); - - arg_data = net_nfc_util_gdbus_ndef_message_to_variant(message); - - ret = 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); - - if (FALSE == ret) - { - NFC_ERR("can not call write: %s", error->message); - g_error_free(error); - out_result = NET_NFC_IPC_FAIL; - } - - return out_result; -} - -API net_nfc_error_e net_nfc_client_ndef_make_read_only( - net_nfc_target_handle_s *handle, - net_nfc_client_ndef_make_read_only_completed callback, - void *user_data) -{ - NetNfcCallback *func_data; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == ndef_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_NOT_CONNECTED); - RETV_IF(ndef_is_supported_tag() == FALSE, NET_NFC_NOT_SUPPORTED); - - func_data = g_try_new0(NetNfcCallback, 1); - if (NULL == func_data) - return NET_NFC_ALLOC_FAIL; - - 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_s *handle) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e out_result = NET_NFC_OK; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == ndef_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_NOT_CONNECTED); - RETV_IF(ndef_is_supported_tag() == FALSE, NET_NFC_NOT_SUPPORTED); - - ret = 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); - - if (FALSE == ret) - { - NFC_ERR("can not make read only: %s", error->message); - g_error_free(error); - out_result = NET_NFC_IPC_FAIL; - } - - return out_result; -} - -API net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_s *handle, - data_s *key, net_nfc_client_ndef_format_completed callback, void *user_data) -{ - GVariant *arg_data; - NetNfcCallback *func_data; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == ndef_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_NOT_CONNECTED); - - func_data = g_try_new0(NetNfcCallback, 1); - if (NULL == func_data) - return NET_NFC_ALLOC_FAIL; - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)key); - - 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_s *handle, data_s *key) -{ - gboolean ret; - GVariant *arg_data; - GError *error = NULL; - net_nfc_error_e out_result = NET_NFC_OK; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == ndef_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_NOT_CONNECTED); - - arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)key); - - ret = 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); - - if (FALSE == ret) - { - NFC_ERR("can not call format: %s", error->message); - g_error_free(error); - out_result = NET_NFC_IPC_FAIL; - } - - return out_result; -} - -net_nfc_error_e net_nfc_client_ndef_init(void) -{ - GError *error = NULL; - - if (ndef_proxy) - { - NFC_WARN("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 (NULL == ndef_proxy) - { - NFC_ERR("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; - } -} diff --git a/client/net_nfc_client_ndef_message.c b/client/net_nfc_client_ndef_message.c deleted file mode 100644 index 7f561a9..0000000 --- a/client/net_nfc_client_ndef_message.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -#include "net_nfc_debug_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_s **ndef_message) -{ - return net_nfc_util_create_ndef_message(ndef_message); -} - -API net_nfc_error_e net_nfc_create_rawdata_from_ndef_message( - ndef_message_s *ndef_message, data_s **rawdata) -{ - data_s *data; - uint32_t count; - net_nfc_error_e result; - - RETV_IF(NULL == ndef_message, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == rawdata, 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, 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_s **ndef_message, data_s *rawdata) -{ - ndef_message_s *msg; - net_nfc_error_e result; - - RETV_IF(NULL == ndef_message, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == rawdata, 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(rawdata, 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_s *ndef_message, uint32_t *length) -{ - net_nfc_error_e result; - - RETV_IF(NULL == ndef_message, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == length, NET_NFC_NULL_PARAMETER); - - *length = net_nfc_util_get_ndef_message_length(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_s *ndef_message, ndef_record_s *record) -{ - RETV_IF(NULL == ndef_message, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - - return net_nfc_util_append_record(ndef_message, record); -} - -API net_nfc_error_e net_nfc_free_ndef_message(ndef_message_s *ndef_message) -{ - RETV_IF(NULL == ndef_message, NET_NFC_NULL_PARAMETER); - - return net_nfc_util_free_ndef_message(ndef_message); -} - -API net_nfc_error_e net_nfc_get_ndef_message_record_count( - ndef_message_s *ndef_message, int *count) -{ - RETV_IF(NULL == ndef_message, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == count, NET_NFC_NULL_PARAMETER); - - *count = ndef_message->recordCount; - return NET_NFC_OK; -} - -API void net_nfc_ndef_print_message (ndef_message_s *ndef_message) -{ - net_nfc_util_print_ndef_message(ndef_message); -} - - -API net_nfc_error_e net_nfc_search_record_by_type(ndef_message_s *ndef_message, - net_nfc_record_tnf_e tnf, data_s *type, ndef_record_s **record) -{ - return net_nfc_util_search_record_by_type(ndef_message, tnf, type, record); -} - -API net_nfc_error_e net_nfc_append_record_by_index(ndef_message_s *ndef_message, - int index, ndef_record_s *record) -{ - return net_nfc_util_append_record_by_index(ndef_message, index, record); -} - -API net_nfc_error_e net_nfc_get_record_by_index (ndef_message_s *ndef_message, - int index, ndef_record_s **record) -{ - return net_nfc_util_get_record_by_index(ndef_message, index, record); -} - -API net_nfc_error_e net_nfc_remove_record_by_index(ndef_message_s *ndef_message, - int index) -{ - return net_nfc_util_remove_record_by_index(ndef_message, index); -} - -API net_nfc_error_e net_nfc_retrieve_current_ndef_message( - ndef_message_s **ndef_message) -{ - FILE *fp = NULL; - char file_path[PATH_MAX] = { 0, }; - net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; - - RETV_IF(NULL == ndef_message, 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); - - NFC_DBG("message length = [%ld]", size); - - if (size > 0) - { - data_s data = { NULL, 0 }; - - if (net_nfc_util_alloc_data(&data, size) == true) - { - int current; - size_t offset = 0; - /* read fully */ - do { - current = fread(data.buffer + offset, 1, - data.length - offset, fp); - if (current > 0) - offset += current; - else - break; - } while (offset < data.length); - - if (offset == data.length) - result = net_nfc_create_ndef_message_from_rawdata(ndef_message, &data); - else - NFC_ERR("failed to read ndef message"); - - net_nfc_util_free_data(&data); - } - else - { - result = NET_NFC_ALLOC_FAIL; - } - } - else - { - result = NET_NFC_NO_NDEF_MESSAGE; - } - - fclose(fp); - } - else - { - result = NET_NFC_NO_NDEF_MESSAGE; - } - - return result; -} diff --git a/client/net_nfc_client_ndef_message_handover.c b/client/net_nfc_client_ndef_message_handover.c deleted file mode 100644 index 8df5610..0000000 --- a/client/net_nfc_client_ndef_message_handover.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -#include "net_nfc_ndef_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_s **config, net_nfc_conn_handover_carrier_type_e type) -{ - return net_nfc_util_create_carrier_config(config, type); -} - -API net_nfc_error_e net_nfc_add_carrier_config_property( - net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t size, uint8_t *data) -{ - return net_nfc_util_add_carrier_config_property(config, attribute, size, data); -} - -API net_nfc_error_e net_nfc_remove_carrier_config_property( - net_nfc_carrier_config_s *config, uint16_t attribute) -{ - return net_nfc_util_remove_carrier_config_property(config, attribute); -} - -API net_nfc_error_e net_nfc_get_carrier_config_property( - net_nfc_carrier_config_s *config, - uint16_t attribute, - uint16_t *size, - uint8_t **data) -{ - return net_nfc_util_get_carrier_config_property(config, attribute, size, data); -} - -API net_nfc_error_e net_nfc_append_carrier_config_group( - net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group) -{ - return net_nfc_util_append_carrier_config_group(config, group); -} - -API net_nfc_error_e net_nfc_remove_carrier_config_group( - net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group) -{ - return net_nfc_util_remove_carrier_config_group(config, group); -} - -API net_nfc_error_e net_nfc_get_carrier_config_group( - net_nfc_carrier_config_s *config, int index, net_nfc_carrier_property_s **group) -{ - return net_nfc_util_get_carrier_config_group(config, index, group); -} - -API net_nfc_error_e net_nfc_free_carrier_config(net_nfc_carrier_config_s *config) -{ - return net_nfc_util_free_carrier_config(config); -} - -API net_nfc_error_e net_nfc_create_carrier_config_group( - net_nfc_carrier_property_s **group, uint16_t attribute) -{ - return net_nfc_util_create_carrier_config_group(group, attribute); -} - -API net_nfc_error_e net_nfc_add_carrier_config_group_property( - net_nfc_carrier_property_s *group, - uint16_t attribute, - uint16_t size, - uint8_t *data) -{ - return net_nfc_util_add_carrier_config_group_property(group, attribute, size, data); -} - -API net_nfc_error_e net_nfc_get_carrier_config_group_property( - net_nfc_carrier_property_s *group, - uint16_t attribute, - uint16_t *size, - uint8_t **data) -{ - return net_nfc_util_get_carrier_config_group_property(group, attribute, size, data); -} - -API net_nfc_error_e net_nfc_remove_carrier_config_group_property( - net_nfc_carrier_property_s *group, uint16_t attribute) -{ - return net_nfc_util_remove_carrier_config_group_property(group, attribute); -} - -API net_nfc_error_e net_nfc_free_carrier_group(net_nfc_carrier_property_s *group) -{ - return net_nfc_util_free_carrier_group(group); -} - -API net_nfc_error_e net_nfc_create_ndef_record_with_carrier_config( - ndef_record_s **record, net_nfc_carrier_config_s *config) -{ - return net_nfc_util_create_ndef_record_with_carrier_config(record, config); -} - -API net_nfc_error_e net_nfc_create_carrier_config_from_config_record( - net_nfc_carrier_config_s **config, ndef_record_s *record) -{ - return net_nfc_util_create_carrier_config_from_config_record(config, record); -} - -API net_nfc_error_e net_nfc_append_carrier_config_record( - ndef_message_s *message, - ndef_record_s *record, - net_nfc_conn_handover_carrier_state_e power_status) -{ - return net_nfc_util_append_carrier_config_record(message, record, power_status); -} - -API net_nfc_error_e net_nfc_remove_carrier_config_record( - ndef_message_s *message, ndef_record_s *record) -{ - return net_nfc_util_remove_carrier_config_record(message, record); -} - -API net_nfc_error_e net_nfc_get_carrier_config_record(ndef_message_s *message, - int index, ndef_record_s **record) -{ - return net_nfc_util_get_carrier_config_record(message, index, record); -} - -API net_nfc_error_e net_nfc_get_handover_random_number( - ndef_message_s *message, unsigned short* random_number) -{ - return net_nfc_util_get_handover_random_number(message, random_number); -} - -API net_nfc_error_e net_nfc_get_alternative_carrier_record_count( - ndef_message_s *message, unsigned int *count) -{ - return net_nfc_util_get_alternative_carrier_record_count(message, count); -} - -API net_nfc_error_e net_nfc_get_alternative_carrier_power_status( - ndef_message_s *message, - int index, - net_nfc_conn_handover_carrier_state_e *power_state) -{ - return net_nfc_util_get_alternative_carrier_power_status(message, index, power_state); -} - -API net_nfc_error_e net_nfc_set_alternative_carrier_power_status( - ndef_message_s *message, - int index, - net_nfc_conn_handover_carrier_state_e power_status) -{ - return net_nfc_util_set_alternative_carrier_power_status(message, index, - power_status); -} - -API net_nfc_error_e net_nfc_get_alternative_carrier_type(ndef_message_s *message, - int index, net_nfc_conn_handover_carrier_type_e * type) -{ - return net_nfc_util_get_alternative_carrier_type(message, index, type); -} - -API net_nfc_error_e net_nfc_create_handover_request_message( - ndef_message_s **message) -{ - return net_nfc_util_create_handover_request_message(message); -} - -API net_nfc_error_e net_nfc_create_handover_select_message( - ndef_message_s **message) -{ - return net_nfc_util_create_handover_select_message(message); -} - -API net_nfc_error_e net_nfc_create_handover_error_record( - ndef_record_s **record, uint8_t reason, uint32_t data) -{ - return net_nfc_util_create_handover_error_record(record, reason, data); -} diff --git a/client/net_nfc_client_ndef_record.c b/client/net_nfc_client_ndef_record.c deleted file mode 100644 index 9f8d02d..0000000 --- a/client/net_nfc_client_ndef_record.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_s **record, - net_nfc_record_tnf_e tnf, - const data_s *typeName, - const data_s *id, - const data_s *payload) -{ - return net_nfc_util_create_record(tnf, typeName, id, payload, record); -} - -API net_nfc_error_e net_nfc_create_text_type_record(ndef_record_s **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, record); -} - -API net_nfc_error_e net_nfc_create_uri_type_record(ndef_record_s **record, - const char* uri, net_nfc_schema_type_e protocol_schema) -{ - return net_nfc_util_create_uri_type_record(uri, protocol_schema, record); -} - -API net_nfc_error_e net_nfc_free_record(ndef_record_s *record) -{ - return net_nfc_util_free_record(record); -} - -API net_nfc_error_e net_nfc_get_record_payload(ndef_record_s *record, - data_s **payload) -{ - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == payload, NET_NFC_NULL_PARAMETER); - - *payload = &(record->payload_s); - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_get_record_type(ndef_record_s *record, data_s **type) -{ - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == type, NET_NFC_NULL_PARAMETER); - - *type = &(record->type_s); - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_get_record_id(ndef_record_s *record, data_s **id) -{ - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == id, NET_NFC_NULL_PARAMETER); - - *id = &(record->id_s); - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_get_record_tnf(ndef_record_s *record, - net_nfc_record_tnf_e *TNF) -{ - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == TNF, NET_NFC_NULL_PARAMETER); - - *TNF = (net_nfc_record_tnf_e)record->TNF; - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_set_record_id(ndef_record_s *record, data_s *id) -{ - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == id, NET_NFC_NULL_PARAMETER); - - return net_nfc_util_set_record_id(record, id->buffer, id->length); -} - -API net_nfc_error_e net_nfc_get_record_flags(ndef_record_s *record, uint8_t *flag) -{ - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == flag, NET_NFC_NULL_PARAMETER); - - *flag = record->MB; - *flag <<= 1; - *flag += record->ME; - *flag <<= 1; - *flag += record->CF; - *flag <<= 1; - *flag += record->SR; - *flag <<= 1; - *flag += record->IL; - *flag <<= 3; - *flag += 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); -} - -static bool _is_text_record(ndef_record_s *record) -{ - data_s *type; - bool result = false; - - if ((net_nfc_get_record_type(record, &type) == NET_NFC_OK) - && (strncmp((char *)net_nfc_get_data_buffer(type), - TEXT_RECORD_TYPE, - net_nfc_get_data_length(type)) == 0)) - { - result = true; - } - - return result; -} - -API net_nfc_error_e net_nfc_create_text_string_from_text_record( - ndef_record_s *record, char **buffer) -{ - data_s *payload; - net_nfc_error_e result; - - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == buffer, NET_NFC_NULL_PARAMETER); - - *buffer = NULL; - - if (_is_text_record(record) == false) - { - NFC_ERR("record type is not matched"); - return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE; - } - - result = net_nfc_get_record_payload(record, &payload); - if (result == NET_NFC_OK) - { - uint8_t *buffer_temp = net_nfc_get_data_buffer(payload); - uint32_t buffer_length = net_nfc_get_data_length(payload); - - if (NULL == buffer_temp) - return NET_NFC_NO_DATA_FOUND; - - 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); - - char *temp = NULL; - - _net_nfc_util_alloc_mem(temp, text_length + 1); - if (temp != NULL) - { - memcpy(temp, &(buffer_temp[index]), text_length); - NFC_DBG("text = [%s]", temp); - - *buffer = temp; - } - else - { - result = NET_NFC_ALLOC_FAIL; - } - } - - return result; -} - -API net_nfc_error_e net_nfc_get_languange_code_string_from_text_record( - ndef_record_s *record, char **lang_code_str) -{ - data_s *payload; - net_nfc_error_e result; - - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == lang_code_str, NET_NFC_NULL_PARAMETER); - - *lang_code_str = NULL; - - if (_is_text_record(record) == false) - { - NFC_ERR("record type is not matched"); - return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE; - } - - result = net_nfc_get_record_payload(record, &payload); - if (result == NET_NFC_OK) - { - int index = 1; - char *buffer = NULL; - uint8_t *buffer_temp = net_nfc_get_data_buffer(payload); - - if (NULL == buffer_temp) - return NET_NFC_NO_DATA_FOUND; - - int controllbyte = buffer_temp[0]; - int lang_code_length = controllbyte & 0x3F; - - _net_nfc_util_alloc_mem(buffer, lang_code_length + 1); - if (buffer != NULL) - { - memcpy(buffer, &(buffer_temp[index]), lang_code_length); - NFC_DBG("language code = [%s]", buffer); - - *lang_code_str = buffer; - } - else - { - result = NET_NFC_ALLOC_FAIL; - } - } - - return result; -} - -API net_nfc_error_e net_nfc_get_encoding_type_from_text_record( - ndef_record_s *record, net_nfc_encode_type_e *encoding) -{ - data_s *payload; - net_nfc_error_e result; - - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == encoding, NET_NFC_NULL_PARAMETER); - - *encoding = NET_NFC_ENCODE_UTF_8; - - if (_is_text_record(record) == false) - { - NFC_ERR("record type is not matched"); - return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE; - } - - result = net_nfc_get_record_payload(record, &payload); - if (result == NET_NFC_OK) - { - uint8_t *buffer_temp = net_nfc_get_data_buffer(payload); - - if (NULL == buffer_temp) - return NET_NFC_NO_DATA_FOUND; - - int controllbyte = buffer_temp[0]; - - if ((controllbyte & 0x80) == 0x80) - *encoding = NET_NFC_ENCODE_UTF_16; - } - - return result; -} - -API net_nfc_error_e net_nfc_create_uri_string_from_uri_record( - ndef_record_s *record, char **uri) -{ - return net_nfc_util_create_uri_string_from_uri_record(record, uri); -} diff --git a/client/net_nfc_client_p2p.c b/client/net_nfc_client_p2p.c deleted file mode 100644 index 6593a23..0000000 --- a/client/net_nfc_client_p2p.c +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 _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; - -static void p2p_device_detached(GObject *source_object, - gpointer user_data) -{ - NFC_INFO(">>> SIGNAL arrived"); - - RET_IF(NULL == p2p_signal_handler.p2p_device_detached_cb); - - /*llcp client function to set/unset the current target id needs to be implemented*/ - /*net_nfc_client_llcp_current_target_id(NULL);*/ - - 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; - - NFC_INFO(">>> SIGNAL arrived"); - - RET_IF(NULL == p2p_signal_handler.p2p_device_discovered_cb); - - handle_info = GUINT_TO_POINTER(arg_handle); - - - 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) -{ - data_s p2p_data = { NULL, }; - - NFC_INFO(">>> SIGNAL arrived"); - - RET_IF(NULL == p2p_signal_handler.p2p_data_received_cb); - - 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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e out_result; - NetNfcCallback *func_data = user_data; - net_nfc_client_p2p_send_completed callback; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_p2p_call_send_finish(NET_NFC_GDBUS_P2P(source_object), - (gint *)&out_result, res, &error); - - if (FALSE == ret) - { - out_result = NET_NFC_IPC_FAIL; - - NFC_ERR("Can not finish p2p send: %s", error->message); - g_error_free(error); - } - - if (func_data->callback != NULL) - { - callback = (net_nfc_client_p2p_send_completed)func_data->callback; - - callback(out_result, func_data->user_data); - } - - g_free(func_data); -} - - -API net_nfc_error_e net_nfc_client_p2p_send(net_nfc_target_handle_s *handle, - data_s *data, net_nfc_client_p2p_send_completed callback, void *user_data) -{ - GVariant *arg_data; - NetNfcCallback *func_data; - - RETV_IF(NULL == p2p_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_try_new0(NetNfcCallback, 1); - if (NULL == func_data) - return NET_NFC_ALLOC_FAIL; - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - arg_data = net_nfc_util_gdbus_data_to_variant(data); - - net_nfc_gdbus_p2p_call_send(p2p_proxy, - 0 /* FIXME */, - 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_target_handle_s *handle, - data_s *data) -{ - gboolean ret; - GVariant *arg_data; - GError *error = NULL; - net_nfc_error_e out_result; - - RETV_IF(NULL == p2p_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - arg_data = net_nfc_util_gdbus_data_to_variant(data); - - ret = net_nfc_gdbus_p2p_call_send_sync(p2p_proxy, - 0 /* FIXME */, - arg_data, - GPOINTER_TO_UINT(handle), - net_nfc_client_gdbus_get_privilege(), - (gint *)&out_result, - NULL, - &error); - - if (FALSE == ret) - { - NFC_ERR("p2p send (sync call) failed: %s", error->message); - - g_error_free(error); - out_result = NET_NFC_IPC_FAIL; - } - - return out_result; -} - - -API void net_nfc_client_p2p_set_device_discovered( - net_nfc_client_p2p_device_discovered callback, void *user_data) -{ - RET_IF(NULL == callback); - - 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) -{ - RET_IF(NULL == callback); - - 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) -{ - RET_IF(NULL == callback); - - 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) -{ - p2p_signal_handler.p2p_device_discovered_cb = NULL; - p2p_signal_handler.p2p_device_discovered_data = NULL; -} - - -API void net_nfc_client_p2p_unset_device_detached(void) -{ - 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) -{ - 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) - { - NFC_WARN("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 (NULL == p2p_proxy) - { - NFC_ERR("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; - } -} diff --git a/client/net_nfc_client_phdc.c b/client/net_nfc_client_phdc.c deleted file mode 100755 index 09c50cb..0000000 --- a/client/net_nfc_client_phdc.c +++ /dev/null @@ -1,388 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_phdc.h" - -typedef struct _Phdc_SignalHandler PhdcSignalHandler; - -static NetNfcGDbusPhdc *phdc_proxy = NULL; -static PhdcSignalHandler phdc_signal_handler; - -struct _Phdc_SignalHandler -{ - net_nfc_client_phdc_transport_connect_indication phdc_transport_connect_indication_cb; - net_nfc_client_phdc_transport_disconnect_indication phdc_transport_disconnect_indication_cb; - net_nfc_client_phdc_data_received phdc_data_received_cb; - - gpointer phdc_transport_connect_indication_data; - gpointer phdc_transport_disconnect_indication_data; - gpointer phdc_data_received_data; -}; - - -static void _phdc_event_cb(NetNfcGDbusPhdc *object, gint arg_result, - guint arg_event,guint arg_user_data) -{ - GVariant *parameter = (GVariant *)GUINT_TO_POINTER(arg_user_data); - - NFC_DBG(" result [%d], event [%d], user_data [%p]", - arg_result, arg_event, parameter); - - if (parameter != NULL) - { - void *user_data; - net_nfc_client_phdc_event_cb callback; - - g_variant_get(parameter, "(uu)", - (guint *)&callback, - (guint *)&user_data); - - if (callback != NULL) - { - callback( arg_result, arg_event, user_data); - } - } - - if (arg_event == NET_NFC_LLCP_UNREGISTERED) - { - g_variant_unref(parameter); - } - -} - - -static void phdc_transport_disconnect_indication(GObject *source_object, gpointer user_data) -{ - NFC_INFO(">>> SIGNAL arrived"); - - RET_IF(NULL == phdc_signal_handler.phdc_transport_disconnect_indication_cb); - - phdc_signal_handler.phdc_transport_disconnect_indication_cb( - phdc_signal_handler.phdc_transport_disconnect_indication_data); -} - -static void phdc_transport_connect_indication(GObject *source_object, - guint arg_handle, gpointer user_data) -{ - net_nfc_phdc_handle_h handle_info = NULL; - - NFC_INFO(">>> SIGNAL arrived"); - - handle_info = GUINT_TO_POINTER(arg_handle); - - RET_IF(NULL == phdc_signal_handler.phdc_transport_connect_indication_cb); - - phdc_signal_handler.phdc_transport_connect_indication_cb(handle_info, - phdc_signal_handler.phdc_transport_connect_indication_data); -} - -static void phdc_call_send(GObject *source_object,GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - GVariant *parameter = (GVariant *)user_data; - GError *error = NULL; - net_nfc_error_e out_result; - net_nfc_client_phdc_send_completed callback; - net_nfc_phdc_handle_h handle; - void *user_param; - - NFC_INFO(">>> phdc_call_send \n"); - - ret = net_nfc_gdbus_phdc_call_send_finish(NET_NFC_GDBUS_PHDC(source_object), - (gint *)&out_result, res, &error); - - if (FALSE == ret) - { - out_result = NET_NFC_IPC_FAIL; - - NFC_ERR("Can not finish phdc send: %s", error->message); - g_error_free(error); - } - - g_variant_get(parameter, "(uuu)", - (guint *)&callback, - (guint *)&user_param, - (guint *)&handle); - - NFC_INFO(">>> phdc_call_send %p\n", handle); - - if (callback != NULL) - { - callback( out_result, user_param); - } - - g_variant_unref(parameter); -} - -static void phdc_device_data_received(GObject *source_object,GVariant *arg_data, - gpointer user_data) -{ - data_s phdc_data = { NULL, }; - - NFC_INFO(">>> SIGNAL arrived"); - - RET_IF(NULL == phdc_signal_handler.phdc_data_received_cb); - - net_nfc_util_gdbus_variant_to_data_s(arg_data, &phdc_data); - phdc_signal_handler.phdc_data_received_cb(&phdc_data, - phdc_signal_handler.phdc_data_received_data); - - net_nfc_util_free_data(&phdc_data); -} - -API net_nfc_error_e net_nfc_client_phdc_send(net_nfc_phdc_handle_h handle, - data_s *data, net_nfc_client_phdc_send_completed callback, void *user_data) -{ - GVariant *arg_data; - GVariant *parameter; - - NFC_INFO(">>> net_nfc_client_phdc_send \n"); - - RETV_IF(NULL == phdc_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - parameter = g_variant_new("(uuu)", - GPOINTER_TO_UINT(callback), - GPOINTER_TO_UINT(user_data), - GPOINTER_TO_UINT(handle)); - - - arg_data = net_nfc_util_gdbus_data_to_variant(data); - - net_nfc_gdbus_phdc_call_send(phdc_proxy, - GPOINTER_TO_UINT(handle), - arg_data, - net_nfc_client_gdbus_get_privilege(), - NULL, - phdc_call_send, - parameter); - - return NET_NFC_OK; -} - - -API net_nfc_error_e net_nfc_client_phdc_send_sync(net_nfc_phdc_handle_h handle, - data_s *data) -{ - gboolean ret; - GVariant *arg_data; - GError *error = NULL; - - net_nfc_error_e out_result; - - RETV_IF(NULL == phdc_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - arg_data = net_nfc_util_gdbus_data_to_variant(data); - - ret = net_nfc_gdbus_phdc_call_send_sync(phdc_proxy, - GPOINTER_TO_UINT(handle), - arg_data, - net_nfc_client_gdbus_get_privilege(), - (gint *)&out_result, - NULL, - &error); - - if(FALSE == ret) - { - NFC_ERR("phdc send (sync call) failed: %s", error->message); - - g_error_free(error); - out_result = NET_NFC_IPC_FAIL; - } - - return out_result; -} - -API net_nfc_error_e net_nfc_client_phdc_register(net_nfc_phdc_role_e role, - const char *san,net_nfc_client_phdc_event_cb callback, void *user_data) -{ - GError *error = NULL; - GVariant *parameter; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == phdc_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), - GPOINTER_TO_UINT(user_data)); - - if (net_nfc_gdbus_phdc_call_register_role_sync(phdc_proxy, - role, - san, - GPOINTER_TO_UINT(parameter), - net_nfc_client_gdbus_get_privilege(), - (gint *)&result, - NULL, - &error) == FALSE) - { - NFC_ERR("phdc register role(sync call) failed: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - g_variant_unref(parameter); - } - - return result; -} - -API net_nfc_error_e net_nfc_client_phdc_unregister( net_nfc_phdc_role_e role, - const char *san) -{ - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == phdc_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - if (net_nfc_gdbus_phdc_call_unregister_role_sync(phdc_proxy, - role, - san, - net_nfc_client_gdbus_get_privilege(), - (gint *)&result, - NULL, - &error) == FALSE) - { - NFC_ERR("phdc unregister role(sync call) failed: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - return result; -} - - -API void net_nfc_client_phdc_set_transport_connect_indication( - net_nfc_client_phdc_transport_connect_indication callback, void *user_data) -{ - RET_IF(NULL == callback); - - phdc_signal_handler.phdc_transport_connect_indication_cb = callback; - phdc_signal_handler.phdc_transport_connect_indication_data = user_data; -} - -API void net_nfc_client_phdc_set_transport_disconnect_indication( - net_nfc_client_phdc_transport_disconnect_indication callback, void *user_data) -{ - RET_IF(NULL == callback); - - phdc_signal_handler.phdc_transport_disconnect_indication_cb = callback; - phdc_signal_handler.phdc_transport_disconnect_indication_data = user_data; -} - -API void net_nfc_client_phdc_set_data_received( - net_nfc_client_phdc_data_received callback, void *user_data) -{ - RET_IF(NULL == callback); - - phdc_signal_handler.phdc_data_received_cb = callback; - phdc_signal_handler.phdc_data_received_data = user_data; -} - -API void net_nfc_client_phdc_unset_transport_connect_indication(void) -{ - phdc_signal_handler.phdc_transport_connect_indication_cb = NULL; - phdc_signal_handler.phdc_transport_connect_indication_data= NULL; -} - - -API void net_nfc_client_phdc_unset_transport_disconnect_indication(void) -{ - phdc_signal_handler.phdc_transport_disconnect_indication_cb = NULL; - phdc_signal_handler.phdc_transport_disconnect_indication_data = NULL; -} - -API void net_nfc_client_phdc_unset_data_received(void) -{ - phdc_signal_handler.phdc_data_received_cb = NULL; - phdc_signal_handler.phdc_data_received_data = NULL; -} - -net_nfc_error_e net_nfc_client_phdc_init(void) -{ - GError *error = NULL; - - if (phdc_proxy) - { - NFC_WARN("Already initialized"); - return NET_NFC_OK; - } - - phdc_proxy = net_nfc_gdbus_phdc_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - "org.tizen.NetNfcService", - "/org/tizen/NetNfcService/Phdc", - NULL, - &error); - if (NULL == phdc_proxy) - { - NFC_ERR("Can not create proxy : %s", error->message); - g_error_free(error); - - return NET_NFC_UNKNOWN_ERROR; - } - - net_nfc_client_phdc_unset_transport_connect_indication(); - net_nfc_client_phdc_unset_transport_disconnect_indication(); - net_nfc_client_phdc_unset_data_received(); - - g_signal_connect(phdc_proxy, "phdc_connect", - G_CALLBACK(phdc_transport_connect_indication), NULL); - - g_signal_connect(phdc_proxy, "phdc_disconnect", - G_CALLBACK(phdc_transport_disconnect_indication), NULL); - - g_signal_connect(phdc_proxy, "phdc_received", - G_CALLBACK(phdc_device_data_received), NULL); - - g_signal_connect(phdc_proxy, "phdc-event", G_CALLBACK(_phdc_event_cb), NULL); - - - return NET_NFC_OK; -} - -void net_nfc_client_phdc_deinit(void) -{ - if (phdc_proxy) - { - g_object_unref(phdc_proxy); - phdc_proxy = NULL; - } - - net_nfc_client_phdc_unset_transport_connect_indication(); - net_nfc_client_phdc_unset_transport_disconnect_indication(); - net_nfc_client_phdc_unset_data_received(); - -} - diff --git a/client/net_nfc_client_se.c b/client/net_nfc_client_se.c deleted file mode 100644 index abf2913..0000000 --- a/client/net_nfc_client_se.c +++ /dev/null @@ -1,1127 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -#include "net_nfc_typedef_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_se_type_e se_type; - net_nfc_client_se_transaction_event eSE_transaction_event_cb; - net_nfc_client_se_transaction_event UICC_transaction_event_cb; - gpointer eSE_transaction_event_data; - gpointer UICC_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) -{ - data_s buffer_data = { NULL, 0 }; - net_nfc_client_se_ese_detected_event callback; - - NFC_INFO(">>> SIGNAL arrived"); - - RET_IF(NULL == se_esedetecthandler.se_ese_detected_cb); - - net_nfc_util_gdbus_variant_to_data_s(arg_data, &buffer_data); - - callback = se_esedetecthandler.se_ese_detected_cb; - callback((net_nfc_target_handle_s*)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) -{ - net_nfc_client_se_event callback; - - NFC_INFO(">>> SIGNAL arrived"); - - RET_IF(NULL == se_eventhandler.se_event_cb); - - callback = se_eventhandler.se_event_cb; - callback((net_nfc_message_e)NET_NFC_MESSAGE_SE_TYPE_CHANGED, - se_eventhandler.se_event_data); -} - - -static void se_transaction_event(GObject *source_object, - gint arg_se_type, - GVariant *arg_aid, - GVariant *arg_param, - gint fg_dispatch, - gint focus_app_pid) -{ - void *user_data = NULL; - data_s aid = { NULL, 0 }; - data_s param = { NULL, 0 }; - net_nfc_client_se_transaction_event callback; - - NFC_INFO(">>> SIGNAL arrived"); - - RET_IF(NULL == se_transeventhandler.eSE_transaction_event_cb); - RET_IF(NULL == se_transeventhandler.UICC_transaction_event_cb); - - if (se_transeventhandler.se_type == arg_se_type) - { - pid_t mypid = getpid(); - if(fg_dispatch == false || - (fg_dispatch == true && focus_app_pid == (getpgid(mypid)))) - { - net_nfc_util_gdbus_variant_to_data_s(arg_aid, &aid); - net_nfc_util_gdbus_variant_to_data_s(arg_param, ¶m); - - if(arg_se_type == NET_NFC_SE_TYPE_ESE) - { - callback = se_transeventhandler.eSE_transaction_event_cb; - user_data = se_transeventhandler.eSE_transaction_event_data; - } - else if(arg_se_type == NET_NFC_SE_TYPE_UICC) - { - callback = se_transeventhandler.UICC_transaction_event_cb; - user_data = se_transeventhandler.UICC_transaction_event_data; - } - - callback(arg_se_type, &aid, ¶m, user_data); - - net_nfc_util_free_data(¶m); - net_nfc_util_free_data(&aid); - } - } -} - -static void se_card_emulation_mode_changed(GObject *source_object, - gint arg_se_type) -{ - net_nfc_client_se_event callback; - NFC_DBG(">>> SIGNAL arrived"); - - RET_IF(NULL == se_eventhandler.se_event_cb); - - callback = se_eventhandler.se_event_cb; - callback((net_nfc_message_e)NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED, - se_eventhandler.se_event_data); -} - -static void set_secure_element(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - net_nfc_se_set_se_cb se_callback; - SeFuncData *func_data = user_data; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_secure_element_call_set_finish(se_proxy, &result, res, &error); - - if(FALSE == ret) - { - NFC_ERR("Could not set secure element: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - if (func_data->se_callback != NULL) - { - 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 get_secure_element(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - gint type = 0; - GError *error = NULL; - net_nfc_error_e result; - net_nfc_se_get_se_cb se_callback; - NetNfcCallback *func_data = user_data; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_secure_element_call_get_finish(se_proxy, - &result, &type, res, &error); - - if (FALSE == ret) - { - NFC_ERR("Could not set secure element: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - se_callback = (net_nfc_se_get_se_cb)func_data->callback; - - se_callback(result, type, func_data->user_data); - } - - g_free(func_data); -} - -static void _set_card_emulation_cb(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - net_nfc_se_set_se_cb se_callback; - NetNfcCallback *func_data = user_data; - - g_assert(user_data != NULL); - - - ret = net_nfc_gdbus_secure_element_call_set_card_emulation_finish( - se_proxy, &result, res, &error); - - if(FALSE == ret) - { - NFC_ERR("Could not set card emulation: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - se_callback = (net_nfc_se_set_se_cb)func_data->callback; - - se_callback(result, func_data->user_data); - } - - g_free(func_data); -} - - -static void open_secure_element(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - guint out_handle = 0; - net_nfc_error_e result; - SeFuncData *func_data = user_data; - net_nfc_se_open_se_cb se_callback; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_secure_element_call_open_secure_element_finish( - se_proxy, &result, &out_handle, res, &error); - - if (FALSE == ret) - { - NFC_ERR("Could not open secure element: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - if (func_data->se_callback != NULL) - { - se_callback = (net_nfc_se_open_se_cb)func_data->se_callback; - - se_callback(result, (net_nfc_target_handle_s*)out_handle, func_data->se_data); - } - - g_free(func_data); -} - - -static void close_secure_element(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - SeFuncData *func_data = user_data; - net_nfc_se_close_se_cb se_callback; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_secure_element_call_close_secure_element_finish( - se_proxy, &result, res, &error); - - if (FALSE == ret) - { - NFC_ERR("Could not close secure element: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - if (func_data->se_callback != NULL) - { - 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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - GVariant *out_response = NULL; - SeFuncData *func_data = user_data; - net_nfc_se_send_apdu_cb se_callback; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_secure_element_call_send_apdu_finish( - se_proxy, &result, &out_response, res, &error); - - if (FALSE == ret) - { - NFC_ERR("Could not send apdu: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - if (func_data->se_callback != NULL) - { - 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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - GVariant *out_atr = NULL; - SeFuncData *func_data = user_data; - net_nfc_se_get_atr_cb se_callback; - - g_assert(user_data != NULL); - - RET_IF(NULL == func_data->se_callback); - - ret = net_nfc_gdbus_secure_element_call_get_atr_finish( - se_proxy, &result, &out_atr, res, &error); - - if (FALSE == ret) - { - NFC_ERR("Could not get atr: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - if (func_data->se_callback != NULL) - { - 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; - - RETV_IF(NULL == se_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_try_new0(SeFuncData, 1); - if (NULL == func_data) - 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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == se_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - ret = net_nfc_gdbus_secure_element_call_set_sync(se_proxy, (gint)se_type, - net_nfc_client_gdbus_get_privilege(), &result, NULL, &error); - - if (FALSE == ret) - { - NFC_ERR("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_get_secure_element_type( - net_nfc_se_get_se_cb callback, void *user_data) -{ - NetNfcCallback *func_data; - - RETV_IF(NULL == se_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_try_new0(NetNfcCallback, 1); - if (NULL == func_data) - return NET_NFC_ALLOC_FAIL; - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - net_nfc_gdbus_secure_element_call_get(se_proxy, net_nfc_client_gdbus_get_privilege(), - NULL, get_secure_element, func_data); - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_client_se_get_secure_element_type_sync( - net_nfc_se_type_e *se_type) -{ - gint type; - net_nfc_error_e result = NET_NFC_OK; - -#if 0 - gboolean ret; - GError *error = NULL; -#endif - RETV_IF(NULL == se_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - -#if 1 - if (vconf_get_int(VCONFKEY_NFC_SE_TYPE, &type) == 0) - *se_type = type; - else - result = NET_NFC_OPERATION_FAIL; -#else - ret = net_nfc_gdbus_secure_element_call_get_sync(se_proxy, - net_nfc_client_gdbus_get_privilege(), &result, (gint)&type, NULL, &error); - - if (TRUE == ret) - { - *se_type = type; - } - else - { - NFC_ERR("Set secure element failed: %s", error->message); - - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } -#endif - return result; -} - -API net_nfc_error_e net_nfc_set_card_emulation_mode( - net_nfc_card_emulation_mode_t mode, - net_nfc_se_set_card_emulation_cb callback, - void *user_data) -{ - NetNfcCallback *func_data; - - RETV_IF(NULL == se_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_try_new0(NetNfcCallback, 1); - if (NULL == func_data) - return NET_NFC_ALLOC_FAIL; - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - net_nfc_gdbus_secure_element_call_set_card_emulation(se_proxy, (gint)mode, - net_nfc_client_gdbus_get_privilege(), NULL, _set_card_emulation_cb, func_data); - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_get_card_emulation_mode(net_nfc_se_type_e *type) -{ - int ret; - int se_type; - net_nfc_error_e result = NET_NFC_OK; - - ret = vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_type); - - if (0 == ret) - { - switch(se_type) - { - case VCONFKEY_NFC_SE_TYPE_UICC: - *type = NET_NFC_SE_TYPE_UICC; - break; - - case VCONFKEY_NFC_SE_TYPE_ESE: - *type = NET_NFC_SE_TYPE_ESE; - break; - - default : - *type = NET_NFC_SE_TYPE_NONE; - break; - } - } - else - { - result = NET_NFC_UNKNOWN_ERROR; - } - - return result; -} - -API net_nfc_error_e net_nfc_set_card_emulation_mode_sync( - net_nfc_card_emulation_mode_t mode) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == se_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - ret = net_nfc_gdbus_secure_element_call_set_card_emulation_sync(se_proxy, (gint)mode, - net_nfc_client_gdbus_get_privilege(), &result, NULL, &error); - - if (FALSE == ret) - { - NFC_ERR("Set card emulation 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; - - RETV_IF(NULL == se_proxy, NET_NFC_NOT_INITIALIZED); - - /* allow this function even nfc is off */ - - func_data = g_try_new0(SeFuncData, 1); - if (NULL == func_data) - 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, func_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_s **handle) -{ - gboolean ret; - guint out_handle = 0; - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == se_proxy, NET_NFC_NOT_INITIALIZED); - - /* allow this function even nfc is off */ - - ret = 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); - - if (TRUE == ret) - { - *handle = GUINT_TO_POINTER(out_handle); - } - else - { - NFC_ERR("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_s *handle, net_nfc_se_close_se_cb callback, void *user_data) -{ - GError *error = NULL; - SeFuncData *func_data; - NetNfcGDbusSecureElement* auto_proxy; - - if(se_proxy != NULL) - { - auto_proxy = se_proxy; - } - else - { - auto_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(NULL == auto_proxy) - { - NFC_ERR("Can not create proxy : %s", error->message); - g_error_free(error); - - return NET_NFC_UNKNOWN_ERROR; - } - } - - /* allow this function even nfc is off */ - - func_data = g_try_new0(SeFuncData, 1); - if (NULL == func_data) - { - g_object_unref(auto_proxy); - 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( - auto_proxy, - GPOINTER_TO_UINT(handle), - net_nfc_client_gdbus_get_privilege(), - NULL, - close_secure_element, - func_data); - - g_object_unref(auto_proxy); - return NET_NFC_OK; -} - - -API net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync( - net_nfc_target_handle_s *handle) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - NetNfcGDbusSecureElement* auto_proxy; - - if(se_proxy != NULL) - { - auto_proxy = se_proxy; - } - else - { - auto_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 (NULL == auto_proxy) - { - NFC_ERR("Can not create proxy : %s", error->message); - g_error_free(error); - - return NET_NFC_UNKNOWN_ERROR; - } - } - - /* allow this function even nfc is off */ - - ret = net_nfc_gdbus_secure_element_call_close_secure_element_sync( - auto_proxy, - GPOINTER_TO_UINT(handle), - net_nfc_client_gdbus_get_privilege(), - &result, - NULL, - &error); - - if (FALSE == ret) - { - NFC_ERR("close internal secure element failed: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - g_object_unref(auto_proxy); - return result; -} - - -API net_nfc_error_e net_nfc_client_se_get_atr(net_nfc_target_handle_s *handle, - net_nfc_se_get_atr_cb callback, void *user_data) -{ - GError *error = NULL; - SeFuncData *func_data; - NetNfcGDbusSecureElement* auto_proxy; - - if(se_proxy != NULL) - { - auto_proxy = se_proxy; - } - else - { - auto_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 (NULL == auto_proxy) - { - NFC_ERR("Can not create proxy : %s", error->message); - g_error_free(error); - - return NET_NFC_UNKNOWN_ERROR; - } - } - - /* allow this function even nfc is off */ - - func_data = g_try_new0(SeFuncData, 1); - if (NULL == func_data) - { - g_object_unref(auto_proxy); - 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( - auto_proxy, - GPOINTER_TO_UINT(handle), - net_nfc_client_gdbus_get_privilege(), - NULL, - get_atr_secure_element, - func_data); - - g_object_unref(auto_proxy); - return NET_NFC_OK; -} - - -API net_nfc_error_e net_nfc_client_se_get_atr_sync( - net_nfc_target_handle_s *handle, data_s **atr) -{ - gboolean ret; - GError *error = NULL; - GVariant *out_atr = NULL; - net_nfc_error_e result = NET_NFC_OK; - NetNfcGDbusSecureElement* auto_proxy; - - RETV_IF(NULL == atr, NET_NFC_NULL_PARAMETER); - - if(se_proxy != NULL) - { - auto_proxy = se_proxy; - } - else - { - auto_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 (NULL == auto_proxy) - { - NFC_DBG("Can not create proxy : %s", error->message); - g_error_free(error); - - return NET_NFC_UNKNOWN_ERROR; - } - } - - *atr = NULL; - - /* allow this function even nfc is off */ - - ret = net_nfc_gdbus_secure_element_call_get_atr_sync( - auto_proxy, - GPOINTER_TO_UINT(handle), - net_nfc_client_gdbus_get_privilege(), - &result, - &out_atr, - NULL, - &error); - - if (TRUE == ret) - { - *atr = net_nfc_util_gdbus_variant_to_data(out_atr); - } - else - { - NFC_ERR("Get attributes failed: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - g_object_unref(auto_proxy); - return result; -} - - -API net_nfc_error_e net_nfc_client_se_send_apdu(net_nfc_target_handle_s *handle, - data_s *apdu_data, net_nfc_se_send_apdu_cb callback, void *user_data) -{ - GVariant *arg_data; - GError *error = NULL; - SeFuncData *func_data; - NetNfcGDbusSecureElement* auto_proxy; - - if(se_proxy != NULL) - { - auto_proxy = se_proxy; - } - else - { - auto_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 (NULL == auto_proxy) - { - NFC_ERR("Can not create proxy : %s", error->message); - g_error_free(error); - - return NET_NFC_UNKNOWN_ERROR; - } - } - - /* allow this function even nfc is off */ - - arg_data = net_nfc_util_gdbus_data_to_variant(apdu_data); - if (arg_data == NULL) - { - g_object_unref(auto_proxy); - return NET_NFC_INVALID_PARAM; - } - - func_data = g_try_new0(SeFuncData, 1); - if (NULL == func_data) - { - g_variant_unref(arg_data); - g_object_unref(auto_proxy); - 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( - auto_proxy, - GPOINTER_TO_UINT(handle), - arg_data, - net_nfc_client_gdbus_get_privilege(), - NULL, - send_apdu_secure_element, - func_data); - - g_object_unref(auto_proxy); - return NET_NFC_OK; -} - - -API net_nfc_error_e net_nfc_client_se_send_apdu_sync( - net_nfc_target_handle_s *handle, data_s *apdu_data, data_s **response) -{ - gboolean ret; - GVariant *arg_data; - GError *error = NULL; - GVariant *out_data = NULL; - net_nfc_error_e result = NET_NFC_OK; - NetNfcGDbusSecureElement* auto_proxy; - - RETV_IF(NULL == response, NET_NFC_NULL_PARAMETER); - - if(se_proxy != NULL) - { - auto_proxy = se_proxy; - } - else - { - GError *error = NULL; - - auto_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 (NULL == auto_proxy) - { - NFC_ERR("Can not create proxy : %s", error->message); - g_error_free(error); - - return NET_NFC_UNKNOWN_ERROR; - } - } - - *response = NULL; - - /* allow this function even nfc is off */ - - arg_data = net_nfc_util_gdbus_data_to_variant(apdu_data); - if (NULL == arg_data) - { - g_object_unref(auto_proxy); - return NET_NFC_INVALID_PARAM; - } - - ret = net_nfc_gdbus_secure_element_call_send_apdu_sync( - auto_proxy, - GPOINTER_TO_UINT(handle), - arg_data, - net_nfc_client_gdbus_get_privilege(), - &result, - &out_data, - NULL, - &error); - - if (TRUE == ret) - { - *response = net_nfc_util_gdbus_variant_to_data(out_data); - } - else - { - NFC_ERR("Send APDU failed: %s", error->message); - g_error_free(error); - result = NET_NFC_IPC_FAIL; - } - - g_object_unref(auto_proxy); - 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) -{ - se_esedetecthandler.se_ese_detected_cb = NULL; - se_esedetecthandler.se_ese_detected_data = NULL; -} - - -API void net_nfc_client_se_set_transaction_event_cb( - net_nfc_se_type_e se_type, - net_nfc_client_se_transaction_event callback, - void *user_data) -{ - se_transeventhandler.se_type = se_type; - - if(se_type == NET_NFC_SE_TYPE_ESE) - { - se_transeventhandler.eSE_transaction_event_cb = callback; - se_transeventhandler.eSE_transaction_event_data = user_data; - } - else if(se_type == NET_NFC_SE_TYPE_UICC) - { - se_transeventhandler.UICC_transaction_event_cb = callback; - se_transeventhandler.UICC_transaction_event_data = user_data; - } -} - - -API void net_nfc_client_se_unset_transaction_event_cb(net_nfc_se_type_e type) -{ - se_transeventhandler.se_type = NET_NFC_SE_TYPE_NONE; - - if (type == NET_NFC_SE_TYPE_ESE) - { - se_transeventhandler.eSE_transaction_event_cb = NULL; - se_transeventhandler.eSE_transaction_event_data = NULL; - } - else if (type == NET_NFC_SE_TYPE_UICC) - { - se_transeventhandler.UICC_transaction_event_cb = NULL; - se_transeventhandler.UICC_transaction_event_data = 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) -{ - se_eventhandler.se_event_cb = NULL; - se_eventhandler.se_event_data = NULL; -} - - -net_nfc_error_e net_nfc_client_se_init(void) -{ - GError *error = NULL; - - if (se_proxy) - { - NFC_WARN("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 (NULL == se_proxy) - { - NFC_ERR("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); - - g_signal_connect(se_proxy, "card-emulation-mode-changed", - G_CALLBACK(se_card_emulation_mode_changed), NULL); - - return NET_NFC_OK; -} - - -void net_nfc_client_se_deinit(void) -{ - if (se_proxy) - { - g_object_unref(se_proxy); - se_proxy = NULL; - } -} diff --git a/client/net_nfc_client_sign_record.c b/client/net_nfc_client_sign_record.c deleted file mode 100644 index 8abbd57..0000000 --- a/client/net_nfc_client_sign_record.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_s *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_s *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_s *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_s *begin_record, - ndef_record_s *sign_record) -{ - return net_nfc_util_verify_signature_records(begin_record, sign_record); -} diff --git a/client/net_nfc_client_snep.c b/client/net_nfc_client_snep.c deleted file mode 100644 index 3138e2c..0000000 --- a/client/net_nfc_client_snep.c +++ /dev/null @@ -1,416 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 void snep_send_client_request(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - void *user_param; - GError *error = NULL; - GVariant *out_data = NULL; - net_nfc_error_e out_result; - net_nfc_snep_handle_h handle; - net_nfc_client_snep_event_cb callback; - GVariant *parameter = (GVariant *)user_data; - net_nfc_snep_type_t out_type = NET_NFC_SNEP_GET; - - g_assert(parameter != NULL); - - 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) - { - NFC_ERR("Can not finish send client request %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - g_variant_get(parameter, "(uuu)", (guint *)&callback, (guint *)&user_param, - (guint *)&handle); - - if (callback != NULL) { - ndef_message_s *message = NULL; - - message = net_nfc_util_gdbus_variant_to_ndef_message(out_data); - - callback(handle, out_type, out_result,message, user_param); - net_nfc_free_ndef_message(message); - } - - g_variant_unref(parameter); -} - -API net_nfc_error_e net_nfc_client_snep_start_server( - net_nfc_target_handle_s *target, - const char *san, - sap_t sap, - net_nfc_client_snep_event_cb callback, - void *user_data) -{ - GVariant *parameter; - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == snep_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, 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_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) - { - NFC_ERR("snep server(sync call) failed: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - - g_variant_unref(parameter); - } - - return result; -} - -API net_nfc_error_e net_nfc_client_snep_start_client( - net_nfc_target_handle_s *target, - const char *san, - sap_t sap, - net_nfc_client_snep_event_cb callback, - void *user_data) -{ - GVariant *parameter; - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == snep_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), - GPOINTER_TO_UINT(user_data)); - - 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) - { - NFC_ERR("snep client(sync call) failed: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - - g_variant_unref(parameter); - } - - 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_s *msg, - net_nfc_client_snep_event_cb callback, - void *user_data) -{ - GVariant *parameter; - GVariant *ndef_msg = NULL; - - RETV_IF(NULL == target, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == msg, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == snep_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - parameter = g_variant_new("(uuu)", - GPOINTER_TO_UINT(callback), - GPOINTER_TO_UINT(user_data), - GPOINTER_TO_UINT(target)); - - ndef_msg = net_nfc_util_gdbus_ndef_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_s *target, - net_nfc_snep_type_t snep_type, - ndef_message_s *msg, - net_nfc_snep_type_t *resp_type, - ndef_message_s **response) -{ - GVariant *resp_msg = NULL; - GVariant *arg_msg = NULL; - GError *error = NULL; - net_nfc_error_e result; - guint type; - - if (target == NULL || msg == NULL - || resp_type == NULL || response == NULL) - { - return NET_NFC_NULL_PARAMETER; - } - - *response = NULL; - - if (snep_proxy == NULL) - { - NFC_ERR("Can not get Snep Proxy"); - - return NET_NFC_NOT_INITIALIZED; - } - - arg_msg = net_nfc_util_gdbus_ndef_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) == TRUE) - { - 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); - } - } - else - { - NFC_ERR(" send client request (sync call) failed: %s", - error->message); - g_error_free(error); - - return NET_NFC_IPC_FAIL; - } - - return result; -} -#endif -API net_nfc_error_e net_nfc_client_snep_stop_service_sync( - net_nfc_target_handle_s *target, net_nfc_snep_handle_h service) -{ - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == target, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == service, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == snep_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, 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) - { - NFC_ERR("snep stop service(sync call) failed: %s", error->message); - g_error_free(error); - - result = 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); - - NFC_DBG("handle [%p], event [%d], result [%d], user_data [%p]", - GUINT_TO_POINTER(arg_handle), arg_event, arg_result, parameter); - - if (parameter != NULL) - { - void *user_data; - net_nfc_client_snep_event_cb callback; - - g_variant_get(parameter, "(uu)", &callback, &user_data); - - if (callback != NULL) - { - ndef_message_s *message; - message = net_nfc_util_gdbus_variant_to_ndef_message(arg_ndef_msg); - - callback(GUINT_TO_POINTER(arg_handle), arg_event, arg_result, - message, user_data); - - net_nfc_free_ndef_message(message); - } - - 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) -{ - GVariant *parameter; - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == snep_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, 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) - { - NFC_ERR("snep register server(sync call) failed: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - - g_variant_unref(parameter); - } - - return result; -} - -API net_nfc_error_e net_nfc_client_snep_unregister_server(const char *san, - sap_t sap) -{ - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == snep_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, 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) - { - NFC_ERR("snep unregister server(sync call) failed: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -net_nfc_error_e net_nfc_client_snep_init(void) -{ - GError *error = NULL; - - if (snep_proxy) - { - NFC_WARN("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) - { - NFC_ERR("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; - } -} diff --git a/client/net_nfc_client_system_handler.c b/client/net_nfc_client_system_handler.c deleted file mode 100644 index 7c68071..0000000 --- a/client/net_nfc_client_system_handler.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_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" - - - -static NetNfcGDbusPopup *popup_proxy = NULL; -static int popup_state = 0; - -static void popup_set_active_callback(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - net_nfc_client_popup_set_state_callback callback; - NetNfcCallback *func_data = (NetNfcCallback *)user_data; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_popup_call_set_finish(NET_NFC_GDBUS_POPUP(source_object), - &result, res, &error); - - if (FALSE == ret) - { - NFC_ERR("Can not finish popup_set_active: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - callback = (net_nfc_client_popup_set_state_callback)func_data->callback; - - callback(result, func_data->user_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) -{ - NetNfcCallback *func_data; - - RETV_IF(NULL == popup_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_try_new0(NetNfcCallback, 1); - if (NULL == func_data) - return NET_NFC_ALLOC_FAIL; - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - net_nfc_gdbus_popup_call_set(popup_proxy, - state, - CHECK_FOREGROUND, - 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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == popup_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - ret = net_nfc_gdbus_popup_call_set_sync(popup_proxy, - state, - CHECK_FOREGROUND, - net_nfc_client_gdbus_get_privilege(), - &result, - NULL, - &error); - - if (FALSE == ret) - { - NFC_ERR("can not call SetActive: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -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) -{ - NetNfcCallback *func_data; - - RETV_IF(NULL == popup_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_try_new0(NetNfcCallback, 1); - if (NULL == func_data) - return NET_NFC_ALLOC_FAIL; - - func_data->callback = (gpointer)callback; - func_data->user_data = user_data; - - net_nfc_gdbus_popup_call_set(popup_proxy, - state, - NO_CHECK_FOREGROUND, - 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) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result; - - RETV_IF(NULL == popup_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - ret = net_nfc_gdbus_popup_call_set_sync(popup_proxy, - state, - NO_CHECK_FOREGROUND, - net_nfc_client_gdbus_get_privilege(), - &result, - NULL, - &error); - - if (FALSE == ret) - { - NFC_ERR("can not call SetActive: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -API net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state( - int enable) -{ - popup_state = enable; - - return net_nfc_client_sys_handler_set_state_sync(enable); -} - -API net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state_force( - int enable) -{ - popup_state = enable; - - return net_nfc_client_sys_handler_set_state_force_sync(enable); -} - -API net_nfc_error_e net_nfc_client_sys_handler_get_launch_popup_state( - int *state) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - gint out_state = NET_NFC_LAUNCH_APP_SELECT; - - RETV_IF(NULL == state, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == popup_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - *state = NET_NFC_LAUNCH_APP_SELECT; - - ret = net_nfc_gdbus_popup_call_get_sync(popup_proxy, - net_nfc_client_gdbus_get_privilege(), - &result, - &out_state, - NULL, - &error); - - if (TRUE == ret) - { - *state = out_state; - } - else - { - NFC_ERR("net_nfc_gdbus_popup_call_get_sync failed: %s", error->message); - g_error_free(error); - - result = NET_NFC_IPC_FAIL; - } - - return result; -} - -net_nfc_error_e net_nfc_client_sys_handler_init(void) -{ - GError *error = NULL; - - if (popup_proxy) - { - NFC_WARN("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 (NULL == popup_proxy) - { - NFC_ERR("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; - } -} diff --git a/client/net_nfc_client_tag.c b/client/net_nfc_client_tag.c deleted file mode 100644 index 20c639a..0000000 --- a/client/net_nfc_client_tag.c +++ /dev/null @@ -1,804 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" - - -static NetNfcGDbusTag *tag_proxy = NULL; - -static NetNfcCallback tag_discovered_func_data; -static NetNfcCallback tag_detached_func_data; - -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) -{ - net_nfc_event_filter_e converted = NET_NFC_ALL_ENABLE; - - NFC_DBG("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) -{ - gint i = 0; - gint length; - guint8 *pos = buffer; - net_nfc_tag_info_s *current = NULL; - net_nfc_tag_info_s *tmp_list = NULL; - - RET_IF(NULL == buffer); - - tmp_list = g_new0(net_nfc_tag_info_s, number_of_keys); - current = tmp_list; - - while (i < number_of_keys) - { - gchar *str = NULL; - data_s *value = NULL; - - /* key */ - length = *pos; /* first values is length of key */ - pos++; - - str = g_new0(gchar, length + 1); - memcpy(str, pos, length); - - NFC_DBG("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_tag_info_s *list = NULL; - net_nfc_target_info_s *info_data = NULL; - - RET_IF(NULL == info); - - 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; -} -#if 0 -static void tag_is_tag_connected(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e out_result; - gboolean out_is_connected = false; - NetNfcCallback *func_data = (NetNfcCallback *)user_data; - net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_tag_call_is_tag_connected_finish( - NET_NFC_GDBUS_TAG(source_object), - &out_result, - &out_is_connected, - (gint32 *)&out_dev_type, - res, - &error); - - if (FALSE == ret) - { - NFC_ERR("Can not finish is_tag_connected: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - net_nfc_client_tag_is_tag_connected_completed callback = - (net_nfc_client_tag_is_tag_connected_completed)func_data->callback; - - if (out_is_connected == FALSE) - out_result = NET_NFC_NOT_CONNECTED; - - callback(out_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) -{ - gboolean ret; - guint out_handle = 0; - GError *error = NULL; - guint out_max_data_size = 0; - guint out_number_of_keys = 0; - GVariant *out_raw_data = NULL; - guchar out_ndef_card_state = 0; - guint out_actual_data_size = 0; - gboolean out_is_connected = FALSE; - gboolean out_is_ndef_supported = FALSE; - GVariant *out_target_info_values = NULL; - net_nfc_error_e out_result = NET_NFC_OK; - NetNfcCallback *func_data = (NetNfcCallback *)user_data; - net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_tag_call_get_current_tag_info_finish ( - NET_NFC_GDBUS_TAG(source_object), - &out_result, - &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); - - if (FALSE == ret) - { - out_result = NET_NFC_IPC_FAIL; - - NFC_ERR("Can not finish get_current_tag_info: %s", error->message); - g_error_free(error); - } - - if (out_result == NET_NFC_OK && out_is_connected == true) - { - net_nfc_release_tag_info(client_target_info); - client_target_info = NULL; - - if (tag_check_filter(out_dev_type) == true) - { - 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, - &client_target_info); - } - else - { - NFC_INFO("The detected target is filtered out, type [%d]", out_dev_type); - - out_is_connected = false; - } - } - - if (func_data->callback != NULL) - { - net_nfc_client_tag_get_current_tag_info_completed callback = - (net_nfc_client_tag_get_current_tag_info_completed)func_data->callback; - - if (out_result == NET_NFC_OK && out_is_connected == false) - out_result = NET_NFC_NOT_CONNECTED; - - callback(out_result, client_target_info, func_data->user_data); - } - - g_free(func_data); -} - -static void tag_get_current_target_handle(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - gboolean out_is_connected = false; - net_nfc_error_e out_result = NET_NFC_OK; - net_nfc_target_handle_s *out_handle = NULL; - NetNfcCallback *func_data = (NetNfcCallback *)user_data; - net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_tag_call_get_current_target_handle_finish( - NET_NFC_GDBUS_TAG(source_object), - &out_result, - &out_is_connected, - (guint *)&out_handle, - (gint *)&out_dev_type, - res, - &error); - - if (FALSE == ret) - { - NFC_ERR("Can not finish get_current_target_handle: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - net_nfc_client_tag_get_current_target_handle_completed callback = - (net_nfc_client_tag_get_current_target_handle_completed)func_data->callback; - - if (out_result == NET_NFC_OK && out_is_connected == FALSE) - out_result = NET_NFC_NOT_CONNECTED; - - callback(out_result, GUINT_TO_POINTER(out_handle), func_data->user_data); - } - - g_free(func_data); -} -#endif -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) -{ - net_nfc_client_tag_tag_discovered callback; - - NFC_INFO(">>> SIGNAL arrived"); - - net_nfc_release_tag_info(client_target_info); - client_target_info = NULL; - - if (tag_check_filter(arg_dev_type) == FALSE) - { - NFC_INFO("The detected target is filtered out, type [%d]", arg_dev_type); - - return; - } - - 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, - &client_target_info); - - if (tag_discovered_func_data.callback != NULL) - { - callback = (net_nfc_client_tag_tag_discovered)tag_discovered_func_data.callback; - - callback(client_target_info, tag_discovered_func_data.user_data); - } -} - -static void tag_tag_detached(NetNfcGDbusTag *object, guint arg_handle, - gint arg_dev_type, gpointer user_data) -{ - NFC_INFO(">>> SIGNAL arrived"); - net_nfc_client_tag_tag_detached callback; - if (tag_check_filter(arg_dev_type) == TRUE) - { - if (tag_detached_func_data.callback != NULL) - { - callback = (net_nfc_client_tag_tag_detached)tag_detached_func_data.callback; - - callback(tag_detached_func_data.user_data); - } - } - else - { - NFC_INFO("The detected target is filtered out, type [%d]", arg_dev_type); - } - - net_nfc_release_tag_info(client_target_info); - client_target_info = NULL; -} - -/* internal function */ -gboolean net_nfc_client_tag_is_connected(void) -{ - RETV_IF(NULL == client_target_info, FALSE); - RETV_IF(NULL == client_target_info->handle, FALSE); - - return TRUE; -} - -net_nfc_target_info_s *net_nfc_client_tag_get_client_target_info(void) -{ - return client_target_info; -} - -/* public APIs */ -#if 0 -API net_nfc_error_e net_nfc_client_tag_is_tag_connected( - net_nfc_client_tag_is_tag_connected_completed callback, void *user_data) -{ - NetNfcCallback *func_data; - - RETV_IF(NULL == tag_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_try_new0(NetNfcCallback, 1); - if (func_data == NULL) - return NET_NFC_ALLOC_FAIL; - - 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; -} -#endif - -API net_nfc_error_e net_nfc_client_tag_is_tag_connected_sync( - net_nfc_target_type_e *dev_type) -{ - gboolean ret; - GError *error = NULL; - net_nfc_target_info_s *info; - gboolean out_is_connected = FALSE; - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; - - RETV_IF(NULL == tag_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - info = net_nfc_client_tag_get_client_target_info(); - if (NULL == info) - { - /* try to request target information from server */ - ret = net_nfc_gdbus_tag_call_is_tag_connected_sync(tag_proxy, - net_nfc_client_gdbus_get_privilege(), - &result, - &out_is_connected, - (gint *)&out_dev_type, - NULL, - &error); - - if (FALSE == ret) - { - NFC_ERR("Can not get is_tag_connected result: %s", error->message); - g_error_free(error); - - return NET_NFC_IPC_FAIL; - } - - if (TRUE == out_is_connected) - { - if (dev_type) - *dev_type = out_dev_type; - - result = NET_NFC_OK; - } - else - { - result = NET_NFC_NOT_CONNECTED; - } - } - else - { - /* target was connected */ - if (dev_type != NULL) - *dev_type = info->devType; - - result = NET_NFC_OK; - } - - return result; -} - -#if 0 -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) -{ - NetNfcCallback *func_data; - - RETV_IF(NULL == tag_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_try_new0(NetNfcCallback, 1); - if (func_data == NULL) - return NET_NFC_ALLOC_FAIL; - - 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; -} -#endif - -API net_nfc_error_e net_nfc_client_tag_get_current_tag_info_sync( - net_nfc_target_info_s **info) -{ - gboolean ret; - GError *error = NULL; - guint out_handle = 0; - guint out_max_data_size = 0; - guint out_number_of_keys = 0; - GVariant *out_raw_data = NULL; - guchar out_ndef_card_state = 0; - guint out_actual_data_size = 0; - gboolean out_is_connected = FALSE; - net_nfc_error_e result = NET_NFC_OK; - gboolean out_is_ndef_supported = FALSE; - GVariant *out_target_info_values = NULL; - net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; - - RETV_IF(NULL == tag_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - if (net_nfc_client_tag_get_client_target_info() == NULL) - { - ret = net_nfc_gdbus_tag_call_get_current_tag_info_sync(tag_proxy, - net_nfc_client_gdbus_get_privilege(), - &result, - &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); - - /* try to request target information from server */ - if (FALSE == ret) - { - NFC_ERR("Can not get current_tag_info result: %s", error->message); - g_error_free(error); - - return NET_NFC_IPC_FAIL; - } - - if (TRUE == out_is_connected) - { - if (tag_check_filter(out_dev_type) == TRUE) - { - 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, - &client_target_info); - - result = NET_NFC_OK; - } - else - { - NFC_INFO("The detected target is filtered out"); - - result = NET_NFC_NOT_CONNECTED; - } - } - else - { - result = NET_NFC_NOT_CONNECTED; - } - } - else - { - result = NET_NFC_OK; - } - - if (result == NET_NFC_OK && info != NULL) - *info = client_target_info; - - return result; -} - -#if 0 -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) -{ - NetNfcCallback *func_data; - - RETV_IF(NULL == tag_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - func_data = g_try_new0(NetNfcCallback, 1); - if (func_data == NULL) - return NET_NFC_ALLOC_FAIL; - - 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; -} -#endif - -API net_nfc_error_e net_nfc_client_tag_get_current_target_handle_sync( - net_nfc_target_handle_s **handle) -{ - gboolean ret; - GError *error = NULL; - guint out_handle = 0; - net_nfc_error_e result; - net_nfc_target_info_s *info; - gboolean out_is_connected = FALSE; - net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; - - RETV_IF(NULL == tag_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - info = net_nfc_client_tag_get_client_target_info(); - if (NULL == info) - { - ret = net_nfc_gdbus_tag_call_get_current_target_handle_sync( - tag_proxy, - net_nfc_client_gdbus_get_privilege(), - &result, - &out_is_connected, - &out_handle, - (gint *)&out_dev_type, - NULL, - &error); - - if (FALSE == ret) - { - NFC_ERR("Can not get current_target_handle result: %s", error->message); - g_error_free(error); - - return result; - } - - if (TRUE == out_is_connected) - { - if (handle) - *handle = GUINT_TO_POINTER(out_handle); - - result = NET_NFC_OK; - } - else - { - result = NET_NFC_NOT_CONNECTED; - } - } - else if (NET_NFC_NFCIP1_INITIATOR == info->devType || - NET_NFC_NFCIP1_TARGET == info->devType) - { - if (handle) - *handle = info->handle; - - result = NET_NFC_OK; - } - else - { - result = NET_NFC_NOT_CONNECTED; - } - - return result; -} - -API void net_nfc_client_tag_set_tag_discovered( - net_nfc_client_tag_tag_discovered callback, void *user_data) -{ - RET_IF(NULL == callback); - - 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) -{ - tag_discovered_func_data.callback = NULL; - tag_discovered_func_data.user_data = NULL; -} - -API void net_nfc_client_tag_set_tag_detached( - net_nfc_client_tag_tag_detached callback, void *user_data) -{ - RET_IF(NULL == callback); - - 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) -{ - tag_detached_func_data.callback = NULL; - tag_detached_func_data.user_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) - { - NFC_WARN("Alrady initialized"); - return NET_NFC_OK; - } - - if (client_target_info) - { - net_nfc_release_tag_info(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 (NULL == tag_proxy) - { - NFC_ERR("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) -{ - client_filter = NET_NFC_ALL_ENABLE; - - net_nfc_release_tag_info(client_target_info); - client_target_info = NULL; - - net_nfc_client_tag_unset_tag_discovered(); - net_nfc_client_tag_unset_tag_detached(); - - if (tag_proxy) - { - g_object_unref(tag_proxy); - tag_proxy = NULL; - } -} diff --git a/client/net_nfc_client_tag_felica.c b/client/net_nfc_client_tag_felica.c deleted file mode 100644 index e51543a..0000000 --- a/client/net_nfc_client_tag_felica.c +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "net_nfc_client_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_s *handle, - net_nfc_felica_poll_request_code_e req_code, - uint8_t time_slote, - nfc_transceive_data_callback callback, - void *user_data) -{ - data_s rawdata; - uint8_t send_buffer[6] = { 0x00, }; - net_nfc_target_info_s* target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NO_DATA_FOUND; - - if (target_info->devType != NET_NFC_FELICA_PICC) - { - NFC_ERR("only felica tag is available(TAG = %d)", target_info->devType); - 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, &rawdata, callback, user_data); -} - -API net_nfc_error_e net_nfc_client_felica_request_service( - net_nfc_target_handle_s *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) -{ - int i; - data_s rawdata; - data_s *IDm = NULL; - uint8_t* temp = NULL; - uint8_t* send_buffer = NULL; - uint32_t send_buffer_length; - net_nfc_target_info_s* target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == area_service_list, NET_NFC_NULL_PARAMETER); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NO_DATA_FOUND; - - if (target_info->devType != NET_NFC_FELICA_PICC) - { - NFC_ERR("only Felica tag is available(TAG=%d)", target_info->devType); - return NET_NFC_NOT_ALLOWED_OPERATION; - } - - if (net_nfc_get_tag_info_value(target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK) - return NET_NFC_NO_DATA_FOUND; - - if (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 (NULL == send_buffer) - 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, IDm->buffer, IDm->length); - send_buffer = send_buffer + 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, &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_s *handle, - nfc_transceive_data_callback callback, - void *user_data) -{ - data_s rawdata; - data_s *IDm = NULL; - uint8_t send_buffer[10] = { 0x00, }; - net_nfc_target_info_s* target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NO_DATA_FOUND; - - if (target_info->devType != NET_NFC_FELICA_PICC) - { - NFC_ERR("only Felica tag is available(TAG=%d)", target_info->devType); - return NET_NFC_NOT_ALLOWED_OPERATION; - } - - if (net_nfc_get_tag_info_value(target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK) - return NET_NFC_NO_DATA_FOUND; - - if (IDm->length != 8) - return NET_NFC_OUT_OF_BOUND; - - send_buffer[0] = 0xA; - send_buffer[1] = FELICA_CMD_REQ_RESPONSE; - - memcpy(send_buffer + 2, IDm->buffer, IDm->length); - - DEBUG_MSG_PRINT_BUFFER(send_buffer, 10); - - rawdata.buffer = send_buffer; - rawdata.length = 10; - - return net_nfc_client_transceive_data(handle, &rawdata, callback, user_data); -} - -API net_nfc_error_e net_nfc_client_felica_read_without_encryption( - net_nfc_target_handle_s *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) -{ - int i; - data_s rawdata; - data_s *IDm = NULL; - uint8_t* temp = NULL; - uint8_t* send_buffer = NULL; - uint32_t send_buffer_length; - net_nfc_target_info_s* target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == service_list, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == block_list, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NO_DATA_FOUND; - - if (target_info->devType != NET_NFC_FELICA_PICC) - { - NFC_ERR("only Felica tag is available(TAG=%d)", target_info->devType); - return NET_NFC_NOT_ALLOWED_OPERATION; - } - - if (net_nfc_get_tag_info_value(target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK) - return NET_NFC_NO_DATA_FOUND; - - if (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, IDm->buffer, IDm->length); - send_buffer = send_buffer + 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, &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_s *handle, - uint8_t number_of_services, - uint16_t service_list[], - uint8_t number_of_blocks, - uint8_t block_list[], - data_s *data, - nfc_transceive_data_callback callback, - void *user_data) -{ - int i; - data_s rawdata; - data_s *IDm = NULL; - uint8_t* temp = NULL; - uint8_t* send_buffer = NULL; - uint32_t send_buffer_length; - net_nfc_target_info_s* target_info = NULL; - - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == block_list, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == service_list, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NO_DATA_FOUND; - - if (target_info->devType != NET_NFC_FELICA_PICC) - { - NFC_ERR("only Felica tag is available(TAG=%d)", target_info->devType); - return NET_NFC_NOT_ALLOWED_OPERATION; - } - - if (net_nfc_get_tag_info_value(target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK) - return NET_NFC_NO_DATA_FOUND; - - if (IDm->length != 8) - return NET_NFC_OUT_OF_BOUND; - - if (number_of_services > 16) - return NET_NFC_OUT_OF_BOUND; - - if (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->length; - - _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); - if (NULL == send_buffer) - 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, IDm->buffer, IDm->length); - send_buffer = send_buffer + 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->buffer, 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, &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_s *handle, - nfc_transceive_data_callback callback, - void *user_data) -{ - data_s rawdata; - data_s *IDm = NULL; - uint8_t send_buffer[10] = { 0x00, }; - net_nfc_target_info_s* target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NO_DATA_FOUND; - - if (target_info->devType != NET_NFC_FELICA_PICC) - { - NFC_ERR("only Felica tag is available(TAG=%d)", target_info->devType); - return NET_NFC_NOT_ALLOWED_OPERATION; - } - - if (net_nfc_get_tag_info_value(target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK) - return NET_NFC_NO_DATA_FOUND; - - if (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, IDm->buffer, IDm->length); - - DEBUG_MSG_PRINT_BUFFER(send_buffer, 10); - - rawdata.buffer = send_buffer; - rawdata.length = 10; - - return net_nfc_client_transceive_data(handle, &rawdata, callback, user_data); -} diff --git a/client/net_nfc_client_tag_internal.h b/client/net_nfc_client_tag_internal.h deleted file mode 100644 index 5d89960..0000000 --- a/client/net_nfc_client_tag_internal.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -#include "net_nfc_typedef.h" - -gboolean net_nfc_client_tag_is_connected(void); - -net_nfc_target_info_s* net_nfc_client_tag_get_client_target_info(void); - -#endif //__NET_NFC_CLIENT_TAG_INTERNAL_H__ diff --git a/client/net_nfc_client_tag_jewel.c b/client/net_nfc_client_tag_jewel.c deleted file mode 100644 index e9026f3..0000000 --- a/client/net_nfc_client_tag_jewel.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "net_nfc_client_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_s *handle, - nfc_transceive_data_callback callback, void *user_data) -{ - data_s rawdata; - uint8_t send_buffer[9] = {0x00, }; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NO_DATA_FOUND; - - if(target_info->devType != NET_NFC_JEWEL_PICC) - { - NFC_ERR("only Jewel tag is available(TAG=%d)", target_info->devType); - 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, &rawdata, callback, user_data); -} - -API net_nfc_error_e net_nfc_client_jewel_read_byte(net_nfc_target_handle_s *handle, - uint8_t block, uint8_t byte, nfc_transceive_data_callback callback, void *user_data) -{ - data_s rawdata; - data_s *UID = NULL; - uint8_t send_buffer[9] = {0x00, }; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - RETVM_IF(block > 0xE || byte > 0x7, NET_NFC_OUT_OF_BOUND, - "block value is = [0x%x], byte value is = [0x%x]", block, byte); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NO_DATA_FOUND; - - if(target_info->devType != NET_NFC_JEWEL_PICC) - { - NFC_ERR("only Jewel tag is available(TAG=%d)", target_info->devType); - return NET_NFC_NOT_ALLOWED_OPERATION; - } - - if(net_nfc_get_tag_info_value(target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK) - return NET_NFC_NO_DATA_FOUND; - - if(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]), UID->buffer, 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, &rawdata, callback, user_data); -} - -API net_nfc_error_e net_nfc_client_jewel_read_all(net_nfc_target_handle_s *handle, - nfc_transceive_data_callback callback, void *user_data) -{ - data_s rawdata; - data_s *UID = NULL; - uint8_t send_buffer[9] = {0x00, }; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NO_DATA_FOUND; - - if(target_info->devType != NET_NFC_JEWEL_PICC) - { - NFC_ERR("only Jewel tag is available(TAG=%d)", target_info->devType); - return NET_NFC_NOT_ALLOWED_OPERATION; - } - - if(net_nfc_get_tag_info_value(target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK) - return NET_NFC_NO_DATA_FOUND; - - if(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]), UID->buffer, 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, &rawdata, callback, user_data); -} - -API net_nfc_error_e net_nfc_client_jewel_write_with_erase( - net_nfc_target_handle_s *handle, - uint8_t block, - uint8_t byte, - uint8_t data, - nfc_transceive_callback callback, - void *user_data) -{ - data_s rawdata; - data_s *UID = NULL; - uint8_t send_buffer[9] = {0x00, }; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - RETVM_IF(block > 0xE || byte > 0x7, NET_NFC_OUT_OF_BOUND, - "block value is = [0x%x], byte value is = [0x%x]", block, byte); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NO_DATA_FOUND; - - if(net_nfc_get_tag_info_value(target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK) - return NET_NFC_NO_DATA_FOUND; - - if(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]), UID->buffer, 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, &rawdata, callback, user_data); -} - -API net_nfc_error_e net_nfc_client_jewel_write_with_no_erase( - net_nfc_target_handle_s *handle, - uint8_t block, - uint8_t byte, - uint8_t data, - nfc_transceive_callback callback, - void *user_data) -{ - data_s rawdata; - data_s *UID = NULL; - uint8_t send_buffer[9] = {0x00, }; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - RETVM_IF(block > 0xE || byte > 0x7, NET_NFC_OUT_OF_BOUND, - "block value is = [0x%x], byte value is = [0x%x]", block, byte); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NO_DATA_FOUND; - - - if(target_info->devType != NET_NFC_JEWEL_PICC) - { - NFC_ERR("only Jewel tag is available(TAG=%d)", target_info->devType); - return NET_NFC_NOT_ALLOWED_OPERATION; - } - - if(net_nfc_get_tag_info_value(target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK) - return NET_NFC_NO_DATA_FOUND; - - if(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]), UID->buffer, 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, &rawdata, callback, user_data); -} diff --git a/client/net_nfc_client_tag_mifare.c b/client/net_nfc_client_tag_mifare.c deleted file mode 100644 index abb9714..0000000 --- a/client/net_nfc_client_tag_mifare.c +++ /dev/null @@ -1,785 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include - -#include "net_nfc_client_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_s *handle, - uint8_t sector, - data_s *auth_key, - void *callback, - void *user_data) -{ - data_s rawdata; - data_s *UID = NULL; - uint8_t* temp = NULL; - net_nfc_error_e result; - int send_buffer_length = 0; - uint8_t* send_buffer = NULL; - uint8_t sector_to_block = 0; - net_nfc_target_info_s* target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == auth_key, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - RETVM_IF(auth_key->length != 6, NET_NFC_OUT_OF_BOUND, - "auth_key->length(%d) != 6", auth_key->length); - - 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) - { - NFC_ERR("not a MIFARE Classic TAG(%d)", target_info->devType); - return NET_NFC_NOT_SUPPORTED; - } - } - - if (net_nfc_get_tag_info_value(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 + UID->length + auth_key->length + 2; - - _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); - if (NULL == send_buffer) - { - 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, UID->buffer, UID->length); - temp = temp + UID->length; - - memcpy(temp, auth_key->buffer, auth_key->length); - - net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length); - - - rawdata.buffer = send_buffer; - rawdata.length = send_buffer_length; - - result = net_nfc_client_transceive(handle, &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_s *handle, - uint8_t sector, - data_s *auth_key, - void *callback, - void *user_data) -{ - data_s rawdata; - data_s *UID = NULL; - uint8_t* temp = NULL; - net_nfc_error_e result; - int send_buffer_length = 0; - uint8_t* send_buffer = NULL; - uint8_t sector_to_block = 0; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == auth_key, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - RETVM_IF(auth_key->length != 6, NET_NFC_OUT_OF_BOUND, - "auth_key->length(%d) != 6", auth_key->length); - - - 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) - { - NFC_ERR("not a MIFARE Classic TAG(%d)", target_info->devType); - return NET_NFC_NOT_SUPPORTED; - } - } - - if (net_nfc_get_tag_info_value(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; - } - - /* cmd + addr + UID + AUTH_KEY + CRC_A */ - send_buffer_length = 1 + 1 + UID->length + auth_key->length + 2; - - _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); - if (NULL == send_buffer) - { - 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, UID->buffer, UID->length); - temp = temp + UID->length; - - memcpy(temp, auth_key->buffer, auth_key->length); - - net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length); - - rawdata.buffer = send_buffer; - rawdata.length = send_buffer_length; - - result = net_nfc_client_transceive(handle, &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_s *handle, - uint8_t addr, void *callback, void *user_data) -{ - data_s rawdata; - uint8_t send_buffer[4] = {0}; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, 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) - { - NFC_ERR("not a MIFARE Classic 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, &rawdata, callback, user_data); -} - -API net_nfc_error_e net_nfc_client_mifare_write_block( - net_nfc_target_handle_s *handle, - uint8_t addr, - data_s *data, - void *callback, - void *user_data) -{ - data_s rawdata; - net_nfc_error_e result; - uint8_t* send_buffer = NULL; - uint32_t send_buffer_length = 0; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - return NET_NFC_NOT_INITIALIZED; - - if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || - target_info->devType > NET_NFC_MIFARE_ULTRA_PICC) - { - NFC_ERR("not a MIFARE Classic 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; - } - - if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC) - { - if (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 (NULL == send_buffer) - return NET_NFC_ALLOC_FAIL; - - temp = send_buffer; - - *temp = MIFARE_CMD_WRITE_PAGE; - temp++; - - *temp = addr; - temp++; - - memcpy(temp, data->buffer, MIFARE_PAGE_SIZE); - - } - else - { - uint8_t* temp = NULL; - - /* cmd + addr + page + CRC */ - send_buffer_length = 1 + 1 + data->length + 2; - - _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); - if (NULL == send_buffer) - return NET_NFC_ALLOC_FAIL; - - temp = send_buffer; - - *temp = MIFARE_CMD_WRITE_PAGE; - temp++; - - *temp = addr; - temp++; - - memcpy(temp, data->buffer, data->length); - } - } - else - { - if (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 (NULL == send_buffer) - return NET_NFC_ALLOC_FAIL; - - temp = send_buffer; - - *temp = MIFARE_CMD_WRITE_BLOCK; - temp++; - - *temp = addr; - temp++; - - memcpy(temp, data->buffer, MIFARE_BLOCK_SIZE); - } - else - { - uint8_t* temp = NULL; - - /* cmd + addr + page + CRC */ - send_buffer_length = 1 + 1 + data->length + 2; - - _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); - if (NULL == send_buffer) - return NET_NFC_ALLOC_FAIL; - - temp = send_buffer; - - *temp = MIFARE_CMD_WRITE_BLOCK; - temp++; - - *temp = addr; - temp++; - - memcpy(temp, data->buffer, data->length); - } - } - - net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length); - - rawdata.buffer = send_buffer; - rawdata.length = send_buffer_length; - - result = net_nfc_client_transceive(handle, &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_s *handle, - uint8_t addr, - data_s *data, - void *callback, - void *user_data) -{ - data_s rawdata; - net_nfc_error_e result; - uint8_t* send_buffer = NULL; - uint32_t send_buffer_length = 0; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, NET_NFC_OPERATION_FAIL); - - target_info = net_nfc_client_tag_get_client_target_info(); - - if (NULL == target_info) - return NET_NFC_NOT_INITIALIZED; - - if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || - target_info->devType > NET_NFC_MIFARE_ULTRA_PICC) - { - NFC_ERR("not a MIFARE Classic 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; - } - - if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC) - { - if (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 (NULL == send_buffer) - return NET_NFC_ALLOC_FAIL; - - temp = send_buffer; - - *temp = MIFARE_CMD_WRITE_PAGE; - temp++; - - *temp = addr; - temp++; - - memcpy(temp, data->buffer, MIFARE_PAGE_SIZE); - } - else - { - uint8_t* temp = NULL; - - /* cmd + addr + page + CRC */ - send_buffer_length = 1 + 1 + data->length + 2; - - _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); - if (NULL == send_buffer) - return NET_NFC_ALLOC_FAIL; - - temp = send_buffer; - - *temp = MIFARE_CMD_WRITE_PAGE; - temp++; - - *temp = addr; - temp++; - - memcpy(temp, data->buffer, data->length); - } - - } - else - { - if (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 (NULL == send_buffer) - return NET_NFC_ALLOC_FAIL; - - temp = send_buffer; - - *temp = MIFARE_CMD_WRITE_BLOCK; - temp++; - - *temp = addr; - temp++; - - memcpy(temp, data->buffer, MIFARE_PAGE_SIZE); - - } - else - { - uint8_t* temp = NULL; - - /* cmd + addr + page + CRC */ - send_buffer_length = 1 + 1 + data->length + 2; - - _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); - if (NULL == send_buffer) - return NET_NFC_ALLOC_FAIL; - - temp = send_buffer; - - *temp = MIFARE_CMD_WRITE_BLOCK; - temp++; - - *temp = addr; - temp++; - - memcpy(temp, data->buffer, data->length); - } - - } - - net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length); - - rawdata.buffer = send_buffer; - rawdata.length = send_buffer_length; - - result = net_nfc_client_transceive(handle, &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_s *handle, - uint8_t addr, - int value, - void *callback, - void *user_data) -{ - data_s rawdata; - uint8_t send_buffer[8] = { 0 }; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, 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) - { - NFC_ERR("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, &rawdata, callback, user_data); -} - -API net_nfc_error_e net_nfc_client_mifare_decrement( - net_nfc_target_handle_s *handle, - uint8_t addr, - int value, - void *callback, - void *user_data) -{ - data_s rawdata; - uint8_t send_buffer[8] = { 0 }; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, 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) - { - NFC_ERR("not a MIFARE Classic TAG(%d)", 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, &rawdata, callback, user_data); -} - -API net_nfc_error_e net_nfc_client_mifare_transfer(net_nfc_target_handle_s *handle, - uint8_t addr, void *callback, void *user_data) -{ - data_s rawdata; - uint8_t send_buffer[4] = { 0 }; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, 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) - { - NFC_ERR("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, &rawdata, callback, user_data); -} - -API net_nfc_error_e net_nfc_client_mifare_restore(net_nfc_target_handle_s *handle, - uint8_t addr, void *callback, void *user_data) -{ - data_s rawdata; - uint8_t send_buffer[4] = { 0 }; - net_nfc_target_info_s *target_info = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - RETV_IF(net_nfc_client_tag_is_connected() == FALSE, 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) - { - NFC_ERR("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, &rawdata, callback, user_data); -} - -API net_nfc_error_e net_nfc_client_mifare_create_default_key(data_s** key) -{ - RETV_IF(NULL == key, 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_s** key) -{ - RETV_IF(NULL == key, 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_s** key) -{ - RETV_IF(NULL == key, NET_NFC_NULL_PARAMETER); - - return net_nfc_create_data(key, net_nfc_forum_key, 6); -} - diff --git a/client/net_nfc_client_target_info.c b/client/net_nfc_client_target_info.c deleted file mode 100644 index 6ddbacc..0000000 --- a/client/net_nfc_client_target_info.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "net_nfc_typedef_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_s *target_info, - net_nfc_target_type_e *type) -{ - RETV_IF(NULL == type, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == target_info, NET_NFC_INVALID_HANDLE); - - *type = NET_NFC_UNKNOWN_TARGET; - *type = target_info->devType; - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_s *target_info, - net_nfc_target_handle_s **handle) -{ - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == target_info, NET_NFC_INVALID_HANDLE); - - *handle = NULL; - *handle = target_info->handle; - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_get_tag_ndef_support( - net_nfc_target_info_s *target_info, bool *is_support) -{ - RETV_IF(NULL == target_info, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == is_support, NET_NFC_NULL_PARAMETER); - - *is_support = (bool)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_s *target_info, uint32_t *max_size) -{ - RETV_IF(NULL == target_info, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == max_size, NET_NFC_NULL_PARAMETER); - - *max_size = target_info->maxDataSize; - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_get_tag_actual_data_size( - net_nfc_target_info_s *target_info, uint32_t *actual_data) -{ - RETV_IF(NULL == target_info, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == actual_data, NET_NFC_NULL_PARAMETER); - - *actual_data = target_info->actualDataSize; - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_s *target_info, - char ***keys, int *number_of_keys) -{ - int i = 0; - - RETV_IF(NULL == keys, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == target_info, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == number_of_keys, NET_NFC_NULL_PARAMETER); - - RETV_IF(NULL == target_info->tag_info_list, NET_NFC_NO_DATA_FOUND); - RETV_IF(target_info->number_of_keys <= 0, NET_NFC_NO_DATA_FOUND); - - if (target_info->keylist != NULL) - { - *keys = target_info->keylist; - return NET_NFC_OK; - } - - _net_nfc_util_alloc_mem(*keys, target_info->number_of_keys * sizeof(char *)); - if (NULL == *keys) - return NET_NFC_ALLOC_FAIL; - - net_nfc_tag_info_s *tag_info = target_info->tag_info_list; - - for (; i < target_info->number_of_keys; i++, tag_info++) - { - (*keys)[i] = tag_info->key; - } - - *number_of_keys = target_info->number_of_keys; - - NFC_DBG("number of keys = [%d]", target_info->number_of_keys); - - target_info->keylist = *keys; - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_s *target_info, - const char *key, data_s **value) -{ - int i; - net_nfc_tag_info_s *tag_info; - - RETV_IF(NULL == key, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == value, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == target_info, NET_NFC_NULL_PARAMETER); - - RETV_IF(NULL == target_info->tag_info_list, NET_NFC_NO_DATA_FOUND); - - tag_info = target_info->tag_info_list; - - for (i = 0; i < target_info->number_of_keys; i++, tag_info++) - { - if (strcmp(key, tag_info->key) == 0) - { - if (NULL == tag_info->value) - { - return NET_NFC_NO_DATA_FOUND; - } - else - { - *value = tag_info->value; - break; - } - } - } - - if (i == target_info->number_of_keys) - return NET_NFC_NO_DATA_FOUND; - - return NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_duplicate_target_info(net_nfc_target_info_s *origin, - net_nfc_target_info_s **result) -{ - net_nfc_target_info_s *temp = NULL; - - RETV_IF(NULL == origin, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == result, NET_NFC_NULL_PARAMETER); - - _net_nfc_util_alloc_mem(temp, sizeof(net_nfc_target_info_s)); - if (NULL == temp) - return NET_NFC_ALLOC_FAIL; - - temp->ndefCardState = origin->ndefCardState; - temp->actualDataSize = origin->actualDataSize; - temp->maxDataSize = origin->maxDataSize; - temp->devType = origin->devType; - temp->handle = origin->handle; - temp->is_ndef_supported = origin->is_ndef_supported; - temp->number_of_keys = origin->number_of_keys; - - if (0 < temp->number_of_keys) - { - int i; - - _net_nfc_util_alloc_mem(temp->tag_info_list, - temp->number_of_keys * sizeof(net_nfc_tag_info_s)); - - if (NULL == temp->tag_info_list) - { - _net_nfc_util_free_mem(temp); - return NET_NFC_ALLOC_FAIL; - } - - for (i = 0; i < origin->number_of_keys; i++) - { - if (origin->tag_info_list[i].key != NULL) - { - _net_nfc_util_strdup(temp->tag_info_list[i].key, - origin->tag_info_list[i].key); - } - - if (origin->tag_info_list[i].value != NULL) - { - data_s *data = origin->tag_info_list[i].value; - - net_nfc_create_data(&temp->tag_info_list[i].value, - data->buffer, data->length); - } - } - } - - if (0 < origin->raw_data.length) - { - net_nfc_util_alloc_data(&temp->raw_data, origin->raw_data.length); - memcpy(temp->raw_data.buffer, origin->raw_data.buffer, temp->raw_data.length); - } - - *result = temp; - - return NET_NFC_OK; -} - -static net_nfc_error_e _release_tag_info(net_nfc_target_info_s *info) -{ - net_nfc_tag_info_s *list = NULL; - - if (NULL == info) - return NET_NFC_NULL_PARAMETER; - - list = info->tag_info_list; - if (list != NULL) - { - int i; - - 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 NET_NFC_OK; -} - -API net_nfc_error_e net_nfc_release_tag_info(net_nfc_target_info_s *target_info) -{ - net_nfc_error_e result; - - if (NULL == target_info) - return NET_NFC_NULL_PARAMETER; - - result = _release_tag_info(target_info); - - _net_nfc_util_free_mem(target_info); - - return result; -} diff --git a/client/net_nfc_client_transceive.c b/client/net_nfc_client_transceive.c deleted file mode 100644 index e0bcc85..0000000 --- a/client/net_nfc_client_transceive.c +++ /dev/null @@ -1,437 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "net_nfc_typedef_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 devType, data_s *data) -{ - GVariant *variant; - data_s transceive_info = { NULL, }; - - RETV_IF(NULL == data, 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) - { - NFC_ERR("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) -{ - gboolean ret; - GError *error = NULL; - data_s resp = { NULL, }; - GVariant *out_data = NULL; - net_nfc_error_e out_result; - nfc_transceive_data_callback callback; - NetNfcCallback *func_data = user_data; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_transceive_call_transceive_data_finish( - NET_NFC_GDBUS_TRANSCEIVE(source_object), - (gint *)&out_result, - &out_data, - res, - &error); - - if (FALSE == ret) - { - NFC_ERR("Can not finish transceive: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback != NULL) - { - data_s resp = { NULL, }; - - net_nfc_util_gdbus_variant_to_data_s(out_data, &resp); - - ((nfc_transceive_data_callback)func_data->callback)( - out_result, - &resp, - func_data->user_data); - - net_nfc_util_free_data(&resp); - } - - g_free(func_data); -} - -static void transceive_call(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - net_nfc_error_e out_result; - nfc_transceive_callback callback; - NetNfcCallback *func_data = user_data; - - g_assert(user_data != NULL); - - ret = net_nfc_gdbus_transceive_call_transceive_finish( - NET_NFC_GDBUS_TRANSCEIVE(source_object), - (gint *)&out_result, - res, - &error); - - if (FALSE == ret) - { - NFC_ERR("Can not finish transceive: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - if (func_data->callback) - { - callback = (nfc_transceive_callback)func_data->callback; - callback(out_result, func_data->user_data); - } - - g_free(func_data); -} - -API net_nfc_error_e net_nfc_client_transceive(net_nfc_target_handle_s *handle, - data_s *rawdata, nfc_transceive_callback callback, void *user_data) -{ - GVariant *arg_data; - NetNfcCallback *funcdata; - net_nfc_target_info_s *target_info; - - if (NULL == transceive_proxy) - { - NFC_ERR("Can not get TransceiveProxy"); - - return NET_NFC_NOT_INITIALIZED; - } - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == rawdata, NET_NFC_NULL_PARAMETER); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - target_info = net_nfc_client_tag_get_client_target_info(); - - if (NULL == target_info) - { - NFC_ERR("target_info is NULL"); - return NET_NFC_NOT_CONNECTED; - } - - if (NULL == target_info->handle) - { - NFC_ERR("target_info->handle is NULL"); - return NET_NFC_NOT_CONNECTED; - } - - NFC_DBG("send request :: transceive = [%p]", handle); - - arg_data = transceive_data_to_transceive_variant(target_info->devType, rawdata); - if (NULL == arg_data) - return NET_NFC_INVALID_PARAM; - - funcdata = g_try_new0(NetNfcCallback, 1); - if (NULL == funcdata) - { - g_variant_unref(arg_data); - - return NET_NFC_ALLOC_FAIL; - } - - funcdata->callback = (gpointer)callback; - funcdata->user_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_s *handle, - data_s *rawdata, nfc_transceive_data_callback callback, void *user_data) -{ - GVariant *arg_data; - NetNfcCallback *funcdata; - net_nfc_target_info_s *target_info; - - RETV_IF(NULL == transceive_proxy, NET_NFC_NOT_INITIALIZED); - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == rawdata, NET_NFC_NULL_PARAMETER); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - target_info = net_nfc_client_tag_get_client_target_info(); - - if (NULL == target_info) - { - NFC_ERR("target_info is NULL"); - return NET_NFC_NOT_CONNECTED; - } - - if (NULL == target_info->handle) - { - NFC_ERR("target_info->handle is NULL"); - return NET_NFC_NOT_CONNECTED; - } - - NFC_DBG("send request :: transceive = [%p]", handle); - - arg_data = transceive_data_to_transceive_variant(target_info->devType, rawdata); - if (NULL == arg_data) - return NET_NFC_INVALID_PARAM; - - funcdata = g_try_new0(NetNfcCallback, 1); - if (NULL == funcdata) - { - g_variant_unref(arg_data); - - return NET_NFC_ALLOC_FAIL; - } - - funcdata->callback = (gpointer)callback; - funcdata->user_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_s *handle, - data_s *rawdata) -{ - gboolean ret; - GVariant *arg_data; - GError *error = NULL; - net_nfc_target_info_s *target_info; - net_nfc_error_e out_result = NET_NFC_OK; - - RETV_IF(NULL == transceive_proxy, NET_NFC_NOT_INITIALIZED); - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == rawdata, NET_NFC_NULL_PARAMETER); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - target_info = net_nfc_client_tag_get_client_target_info(); - - if (NULL == target_info) - { - NFC_ERR("target_info is NULL"); - return NET_NFC_NOT_CONNECTED; - } - - if (NULL == target_info->handle) - { - NFC_ERR("target_info->handle is NULL"); - return NET_NFC_NOT_CONNECTED; - } - - NFC_DBG("send request :: transceive = [%p]", handle); - - arg_data = transceive_data_to_transceive_variant(target_info->devType, rawdata); - if (NULL == arg_data) - return NET_NFC_ALLOC_FAIL; - - ret = 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); - - if (FALSE == ret) - { - NFC_ERR("Transceive (sync call) failed: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - return out_result; -} - -API net_nfc_error_e net_nfc_client_transceive_data_sync( - net_nfc_target_handle_s *handle, data_s *rawdata, data_s **response) -{ - gboolean ret; - GVariant *arg_data; - GError *error = NULL; - GVariant *out_data = NULL; - net_nfc_target_info_s *target_info; - net_nfc_error_e out_result = NET_NFC_OK; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == rawdata, NET_NFC_NULL_PARAMETER); - - RETV_IF(NULL == transceive_proxy, NET_NFC_NOT_INITIALIZED); - - /* prevent executing daemon when nfc is off */ - RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); - - target_info = net_nfc_client_tag_get_client_target_info(); - if (NULL == target_info) - { - NFC_ERR("target_info is NULL"); - return NET_NFC_NOT_CONNECTED; - } - - if (NULL == target_info->handle) - { - NFC_ERR("target_info->handle is NULL"); - return NET_NFC_NOT_CONNECTED; - } - - NFC_DBG("send request :: transceive = [%p]", handle); - - arg_data = transceive_data_to_transceive_variant(target_info->devType, rawdata); - if (NULL == arg_data) - return NET_NFC_ALLOC_FAIL; - - ret = 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); - - if (FALSE == ret) - { - NFC_ERR("Transceive (sync call) failed: %s", error->message); - g_error_free(error); - - out_result = NET_NFC_IPC_FAIL; - } - - 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) - { - NFC_WARN("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 (NULL == transceive_proxy) - { - NFC_ERR("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; - } -} diff --git a/client/nfc.pc.in b/client/nfc.pc.in deleted file mode 100644 index 9f70c68..0000000 --- a/client/nfc.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -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} diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt deleted file mode 100644 index 52f958d..0000000 --- a/common/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -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 libtzplatform-config) - -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} STATIC ${COMMON_SRCS}) -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_INSTALL_DIR}/pkgconfig) - -FOREACH(hfile ${COMMON_HEADER}) - INSTALL(FILES ${hfile} DESTINATION include/${NFC_COMMON}) -ENDFOREACH(hfile) - diff --git a/common/include/net_nfc_oem_controller.h b/common/include/net_nfc_oem_controller.h deleted file mode 100644 index c00d4b2..0000000 --- a/common/include/net_nfc_oem_controller.h +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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__ diff --git a/common/include/net_nfc_typedef.h b/common/include/net_nfc_typedef.h deleted file mode 100644 index 6d7aa7f..0000000 --- a/common/include/net_nfc_typedef.h +++ /dev/null @@ -1,646 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 -#include -#include -#include -#include -#include - -/** - 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 - */ - -/** - @defgroup NET_NFC_MANAGER The description of NFC Manager - @defgroup NET_NFC_TYPEDEF Defines and structures - @defgroup NET_NFC_MANAGER_API NFC Manager - @defgroup NET_NFC_MANAGER_INFO Tag Information and data APIs - @defgroup NET_NFC_MANAGER_TAG Tag Read/Write APIs - @defgroup NET_NFC_MANAGER_NDEF NDEF Message APIs - @defgroup NET_NFC_MANAGER_RECORD NDEF Record APIs - @defgroup NET_NFC_MANAGER_LLCP NFC LLCP APIs - @defgroup NET_NFC_MANAGER_APDU Internal APDU APIs - @defgroup NET_NFC_MANAGER_EXCHANGE App Exchanger APIs - - - @addtogroup NET_NFC_MANAGER - @{ -

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

- - NFC Manager APIs are defined in , - -

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

- - @} - */ - -/** - @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,
This events is received after calling the "net_nfc_tranceive" -
if the operation is success, the data parameter should cast into data_s *or it return NULL*/ - NET_NFC_MESSAGE_READ_NDEF, /**< Type: Response Event,
This events is received after calling the "net_nfc_read_tag" -
if the operation is success, the data parameter should cast into ndef_message_s* or it return NULL */ - NET_NFC_MESSAGE_WRITE_NDEF, /**< Type: Response Event,
This events is received after calling the "net_nfc_write_ndef" -
data pointer always returns NULL */ - NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF, /**< Type: Response Event,
This events is received after calling the "net_nfc_make_read_only_ndef" -
data pointer always returns NULL */ - NET_NFC_MESSAGE_IS_TAG_CONNECTED, /**< Type: Response Event,
This events is received after calling the "net_nfc_is_tag_conneced" -
data pointer always returns NULL */ - NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO, /**< Type: Response Event,
This events is received after calling the "net_nfc_get_current_tag_infof" -
if the operation is success, the data parameter should cast into net_nfc_target_info_s* or it return NULL */ - NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE, /**< Type: Response Event,
This events is received after calling the "net_nfc_get_current_target_handle" -
if the operation is success, the data parameter should cast into net_nfc_target_handle_s* or it return NULL */ - NET_NFC_MESSAGE_TAG_DISCOVERED, /**< Type: Notify Event,
When a tag or SE is detected, you got this event. -
The data contains the target info , need to cast to net_nfc_target_info_s* */ - NET_NFC_MESSAGE_NOTIFY, /**< This Notify Event
when the unexpected error has occurred, this event is delivered. data pointer always returns NULL */ - NET_NFC_MESSAGE_TAG_DETACHED, /**< Type: Notify Event,
When a tag or SE is disappeared, you got this event. -
The data contains the target info , need to cast to net_nfc_target_info_s* but it does not have detail target info -
please, do not use "net_nfc_get_tag_info_keys" when you got this event*/ - /*10*/ NET_NFC_MESSAGE_FORMAT_NDEF, /**< Type: Response Event
After complete "net_nfc_format_ndef", this event is delivered */ - NET_NFC_MESSAGE_LLCP_DISCOVERED,/**< Type: Notify Event
When LLCP is discovered and remote device is support llcp, you receive this event -
data pointer contains the remote llcp configuration info. Cast to net_nfc_llcp_config_info_s* */ - NET_NFC_MESSAGE_P2P_DETACHED, /**< Type: Notify Event
When LLCP is de-activated by removing the device, you receive this event*/ - NET_NFC_MESSAGE_LLCP_CONFIG, /**< Type: Response Event.
The operation of "net_nfc_set_llcp_local_configure" is completed */ - - NET_NFC_MESSAGE_P2P_DISCOVERED, /**< Type: Notify Event
The remove device is detected and ready for transferring data to remote side */ - NET_NFC_MESSAGE_P2P_SEND, /**< Type: Response Event,
This events is received after calling the "net_nfc_send_exchanger_data" */ - NET_NFC_MESSAGE_P2P_RECEIVE, /**< Type: Notify Event,
When llcp server socket receive some data, this event is delivered. */ - - NET_NFC_MESSAGE_SE_START_TRANSACTION, /**< Type: Notify Event, indicates external reader start transaction*/ - NET_NFC_MESSAGE_SE_END_TRANSACTION, /**< Type: Notify Event, indicates external reader end transaction*/ - NET_NFC_MESSAGE_SE_TYPE_TRANSACTION, /**< Type: Notify Event, Indicates external reader trying to access secure element */ - /*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_SE_CARD_EMULATION_CHANGED, /**< Type: Notify Event, indicates card emulation mode is changed*/ - NET_NFC_MESSAGE_CONNECTION_HANDOVER, /**< Type: Response Event.
The result of connection handover. If it has been completed successfully, this event will include the information of alternative carrier. */ - - NET_NFC_MESSAGE_SET_SE, - NET_NFC_MESSAGE_GET_SE, - NET_NFC_MESSAGE_OPEN_INTERNAL_SE, - NET_NFC_MESSAGE_CLOSE_INTERNAL_SE, - /*30*/ NET_NFC_MESSAGE_SEND_APDU_SE, - 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; - - -/** - 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; - -#define NET_NFC_APPLICATION_RECORD "tizen.org:app" -/* - ************************************** - LLCP defines - ************************************** - */ -/** - These events are delivered to the each socket callback. These events are separated events that comes from "net_nfc_set_response_callback" callback - */ -typedef enum -{ - /* start number should be larger than "net_nfc_message_e" - because to make seperate with net_nfc_message_e event it may conflict in - the dispatcher and ipc part */ - NET_NFC_MESSAGE_LLCP_LISTEN = 1000, /**< Type: Response Event
this event indicates "net_nfc_listen_llcp" requested is completed*/ - NET_NFC_MESSAGE_LLCP_ACCEPTED, /**< Type: Notify Event.
Remote socket is accepted to listening socket -
data pointer contains the remote socket info (Cast to net_nfc_llcp_socket_option_s*)*/ - NET_NFC_MESSAGE_LLCP_CONNECT, /**< Type: Response Event.
"net_nfc_connect_llcp_with" request is completed and your socket is connected to remote site with url*/ - NET_NFC_MESSAGE_LLCP_CONNECT_SAP, /**< Type: Response Event.
"net_nfc_connect_llcp_with_sap" request is completed and your socket is connected to remote site with sap number*/ - NET_NFC_MESSAGE_LLCP_SEND, /**< Type: Response Event,
"net_nfc_send_llcp" operation is completed (connection mode)*/ - NET_NFC_MESSAGE_LLCP_SEND_TO, /**< Type: Response Event,
"net_nfc_send_llcp_to"operation is completed (connectionless mode)*/ - NET_NFC_MESSAGE_LLCP_RECEIVE, /**< Type: Response Event,
"net_nfc_receive_llcp" operation is completed (connection mode) -
data pointer contains received data (Cast to data_s*)*/ - NET_NFC_MESSAGE_LLCP_RECEIVE_FROM, /**< Type: Response Event,
"net_nfc_receive_llcp_from" operation is completed (connectionless mode)*/ - NET_NFC_MESSAGE_LLCP_DISCONNECT, /**< Type: Response Event,
"net_nfc_disconnect_llcp" request is completed */ - NET_NFC_MESSAGE_LLCP_ERROR, /**< Type: Notify Event,
when the socket is disconnected, you may receive this event */ - NET_NFC_MESSAGE_LLCP_CONNECT_REQ, /**< Type: Notify Event,
when the peer requests connect, you may receive this event */ - NET_NFC_MESSAGE_LLCP_ACCEPT, /**< Type: Response Event
this event indicates "net_nfc_accept_llcp" requested is completed*/ - NET_NFC_MESSAGE_LLCP_REJECT, /**< Type: Response Event
this event indicates "net_nfc_reject_llcp" requested is completed*/ - NET_NFC_MESSAGE_LLCP_REJECTED, /**< Type: Notify Event,
when the socket is rejected, you may receive this event */ - NET_NFC_MESSAGE_LLCP_CLOSE, /**< Type: Response Event,
"net_nfc_close_llcp_socket" request is completed */ - -} net_nfc_llcp_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; - -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 enum -{ - 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 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_PHDC_UNKNOWN = 0x00, - NET_NFC_PHDC_MANAGER , - NET_NFC_PHDC_AGENT, -} net_nfc_phdc_role_e; - - -/** - This structure is just data, to express bytes array - */ -typedef struct -{ - uint8_t *buffer; - uint32_t length; -} data_s; - -/** - ndef_record_s structure has the NDEF record data. it is only a record not a message - */ -typedef struct _ndef_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 _ndef_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; - -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_tag_info_s -{ - char *key; - data_s *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_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_connection_handover_info_s -{ - net_nfc_conn_handover_carrier_type_e type; - data_s data; -}net_nfc_connection_handover_info_s; - -typedef uint8_t sap_t; - -typedef uint32_t net_nfc_llcp_socket_t; - -typedef void *net_nfc_snep_handle_h; - -typedef void *net_nfc_phdc_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); - -// handover - -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_conn_handover_carrier_type_e type; - int length; - GList *data; -} net_nfc_carrier_config_s; - -/* 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 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; - -typedef enum -{ - NET_NFC_NO_LAUNCH_APP_SELECT = 0, - NET_NFC_LAUNCH_APP_SELECT, -} net_nfc_launch_popup_state_e; - -/** - @} - */ - -#endif //__NET_NFC_TYPEDEF_H__ diff --git a/common/include/net_nfc_typedef_internal.h b/common/include/net_nfc_typedef_internal.h deleted file mode 100644 index a9c7db6..0000000 --- a/common/include/net_nfc_typedef_internal.h +++ /dev/null @@ -1,553 +0,0 @@ -/* - * 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; - -typedef struct _net_nfc_current_target_info_s -{ - net_nfc_target_handle_s *handle; - uint32_t devType; - int number_of_keys; - data_s target_info_values; -}net_nfc_current_target_info_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 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; - -/** - Enum value to stop or start the discovery mode - */ - -#define NET_NFC_MAX_UID_LENGTH 0x0AU /**< Maximum UID length expected */ -#define NET_NFC_MAX_ATR_LENGTH 0x30U /**< Maximum ATR_RES (General Bytes) */ -#define NET_NFC_ATQA_LENGTH 0x02U /**< ATQA length */ -#define NET_NFC_ATQB_LENGTH 0x0BU /**< ATQB length */ - -#define NET_NFC_PUPI_LENGTH 0x04U /**< PUPI length */ -#define NET_NFC_APP_DATA_B_LENGTH 0x04U /**< Application Data length for Type B */ -#define NET_NFC_PROT_INFO_B_LENGTH 0x03U /**< Protocol info length for Type B */ - -#define NET_NFC_MAX_ATR_LENGTH 0x30U /**< Maximum ATR_RES (General Bytes) */ -#define NET_NFC_MAX_UID_LENGTH 0x0AU /**< Maximum UID length expected */ -#define NET_NFC_FEL_ID_LEN 0x08U /**< Felica current ID Length */ -#define NET_NFC_FEL_PM_LEN 0x08U /**< Felica current PM Length */ -#define NET_NFC_FEL_SYS_CODE_LEN 0x02U /**< Felica System Code Length */ - -#define NET_NFC_15693_UID_LENGTH 0x08U /**< Length of the Inventory bytes for */ - -typedef struct _net_nfc_sIso14443AInfo_t -{ - uint8_t Uid[NET_NFC_MAX_UID_LENGTH]; /**< UID information of the TYPE A Tag Discovered */ - uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_MAX_UID_LENGTH i.e., 10 */ - uint8_t AppData[NET_NFC_MAX_ATR_LENGTH]; /**< Application data information of the tag discovered (= Historical bytes for type A) */ - uint8_t AppDataLength; /**< Application data length */ - uint8_t Sak; /**< SAK informationof the TYPE A Tag Discovered */ - uint8_t AtqA[NET_NFC_ATQA_LENGTH]; /**< ATQA informationof the TYPE A Tag Discovered */ - uint8_t MaxDataRate; /**< Maximum data rate supported by the TYPE A Tag Discovered */ - uint8_t Fwi_Sfgt; /**< Frame waiting time and start up frame guard time as defined in ISO/IEC 14443-4[7] for type A */ -} net_nfc_sIso14443AInfo_t; - -/** \ingroup grp_hal_nfci - * - * \brief Remote Device Reader B RF Gate Information Container - * - * The Reader B structure includes the available information - * related to the discovered ISO14443B remote device. This information - * is updated for every device discovery. - * \note None. - * - */ -typedef struct _net_nfc_sIso14443BInfo_t -{ - union net_nfc_uAtqBInfo - { - struct net_nfc_sAtqBInfo - { - uint8_t Pupi[NET_NFC_PUPI_LENGTH]; /**< PUPI information of the TYPE B Tag Discovered */ - uint8_t AppData[NET_NFC_APP_DATA_B_LENGTH]; /**< Application Data of the TYPE B Tag Discovered */ - uint8_t ProtInfo[NET_NFC_PROT_INFO_B_LENGTH]; /**< Protocol Information of the TYPE B Tag Discovered */ - } AtqResInfo; - uint8_t AtqRes[NET_NFC_ATQB_LENGTH]; /**< ATQB Response Information of TYPE B Tag Discovered */ - } AtqB; - - uint8_t HiLayerResp[NET_NFC_MAX_ATR_LENGTH]; /**< Higher Layer Response information in answer to ATRRIB Command for Type B */ - uint8_t HiLayerRespLength; /**< Higher Layer Response length */ - uint8_t Afi; /**< Application Family Identifier of TYPE B Tag Discovered */ - uint8_t MaxDataRate; /**< Maximum data rate supported by the TYPE B Tag Discovered */ -} net_nfc_sIso14443BInfo_t; - -/** \ingroup grp_hal_nfci - * - * \brief Remote Device Reader B prime RF Gate Information Container - * - */ -typedef struct _net_nfc_sIso14443BPrimeInfo_t -{ - void *BPrimeCtxt; -} net_nfc_sIso14443BPrimeInfo_t; - -/** \ingroup grp_hal_nfci - * - * \brief Remote Device Jewel Reader RF Gate Information Container - * - * The Jewel Reader structure includes the available information - * related to the discovered Jewel remote device. This information - * is updated for every device discovery. - * \note None. - * - */ -typedef struct _net_nfc_sJewelInfo_t -{ - uint8_t Uid[NET_NFC_MAX_UID_LENGTH]; /**< UID information of the TYPE A Tag Discovered */ - uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_MAX_UID_LENGTH i.e., 10 */ - uint8_t HeaderRom0; /**< Header Rom byte zero */ - uint8_t HeaderRom1; /**< Header Rom byte one */ - -} net_nfc_sJewelInfo_t; - -/** \ingroup grp_hal_nfci - * - * \brief Remote Device Felica Reader RF Gate Information Container - * - * The Felica Reader structure includes the available information - * related to the discovered Felica remote device. This information - * is updated for every device discovery. - * \note None. - * - */ -typedef struct _net_nfc_sFelicaInfo_t -{ - uint8_t IDm[(NET_NFC_FEL_ID_LEN + 2)]; /**< Current ID of Felica tag */ - uint8_t IDmLength; /**< IDm length, shall not be greater than NET_NFC_FEL_ID_LEN i.e., 8 */ - uint8_t PMm[NET_NFC_FEL_PM_LEN]; /**< Current PM of Felica tag */ - uint8_t SystemCode[NET_NFC_FEL_SYS_CODE_LEN]; /**< System code of Felica tag */ -} net_nfc_sFelicaInfo_t; - -/** \ingroup grp_hal_nfci - * - * \brief Remote Device Reader 15693 RF Gate Information Container - * - * The Reader A structure includes the available information - * related to the discovered ISO15693 remote device. This information - * is updated for every device discovery. - * \note None. - * - */ - -typedef struct _net_nfc_sIso15693Info_t -{ - uint8_t Uid[NET_NFC_15693_UID_LENGTH]; /**< UID information of the 15693 Tag Discovered */ - uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_15693_UID_LENGTH i.e., 8 */ - uint8_t Dsfid; /**< DSF information of the 15693 Tag Discovered */ - uint8_t Flags; /**< Information about the Flags in the 15693 Tag Discovered */ - uint8_t Afi; /**< Application Family Identifier of 15693 Tag Discovered */ -} net_nfc_sIso15693Info_t; - -/** \ingroup grp_hal_nfci - * - * \brief NFC Data Rate Supported between the Reader and the Target - * - * The \ref Halnet_nfc_eDataRate enum lists all the Data Rate - * values to be used to determine the rate at which the data is transmitted - * to the target. - * - * \note None. - */ - -/** \ingroup grp_hal_nfci - * - * \brief NFCIP1 Data rates - * - */ -typedef enum net_nfc_eDataRate_t -{ - net_nfc_eDataRate_106 = 0x00U, - net_nfc_eDataRate_212, - net_nfc_eDataRate_424, - net_nfc_eDataRate_RFU -} net_nfc_eDataRate_t; - -/** \ingroup grp_hal_nfci - * - * \brief NFCIP1 Gate Information Container - * - * The NFCIP1 structure includes the available information - * related to the discovered NFCIP1 remote device. This information - * is updated for every device discovery. - * \note None. - * - */ -typedef struct _net_nfc_sNfcIPInfo_t -{ - /* Contains the random NFCID3I conveyed with the ATR_REQ. - always 10 bytes length - or contains the random NFCID3T conveyed with the ATR_RES. - always 10 bytes length */ - uint8_t NFCID[NET_NFC_MAX_UID_LENGTH]; - uint8_t NFCID_Length; - /* ATR_RES = General bytes length, Max length = 48 bytes */ - uint8_t ATRInfo[NET_NFC_MAX_ATR_LENGTH]; - uint8_t ATRInfo_Length; - /**< SAK information of the tag discovered */ - uint8_t SelRes; - /**< ATQA information of the tag discovered */ - uint8_t SenseRes[NET_NFC_ATQA_LENGTH]; - /**< Is Detection Mode of the NFCIP Target Active */ - uint8_t nfcip_Active; - /**< Maximum frame length supported by the NFCIP device */ - uint16_t MaxFrameLength; - /**< Data rate supported by the NFCIP device */ - net_nfc_eDataRate_t nfcip_Datarate; - -} net_nfc_sNfcIPInfo_t; - -typedef union net_nfc_remoteDevInfo_t -{ - net_nfc_sIso14443AInfo_t Iso14443A_Info; - net_nfc_sIso14443BInfo_t Iso14443B_Info; - net_nfc_sIso14443BPrimeInfo_t Iso14443BPrime_Info; - net_nfc_sNfcIPInfo_t NfcIP_Info; - net_nfc_sFelicaInfo_t Felica_Info; - net_nfc_sJewelInfo_t Jewel_Info; - net_nfc_sIso15693Info_t Iso15693_Info; -} net_nfc_remoteDevInfo_t; - -typedef struct _net_nfc_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 enum -{ - NET_NFC_CLIENT_INACTIVE_STATE = 0x00, - NET_NFC_CLIENT_ACTIVE_STATE, -} client_state_e; - -typedef enum -{ - CHECK_FOREGROUND = 0x00, - NO_CHECK_FOREGROUND, -} net_nfc_launch_popup_check_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 -{ - uint32_t length; - uint32_t request_type; - uint32_t client_fd; - uint32_t flags; - uint32_t user_param; - // TODO: above value MUST be same with NET_NFC_REQUEST_MSG_HEADER -} net_nfc_request_msg_t; - -typedef struct _net_nfc_request_target_detected_t -{ - uint32_t length; - uint32_t request_type; - uint32_t client_fd; - uint32_t flags; - uint32_t user_param; - // TODO: above value MUST be same with NET_NFC_REQUEST_MSG_HEADER - - net_nfc_target_handle_s *handle; - uint32_t devType; - int number_of_keys; - data_s target_info_values; -} net_nfc_request_target_detected_t; - -typedef struct _net_nfc_request_se_event_t -{ - uint32_t length; - uint32_t request_type; - uint32_t client_fd; - uint32_t flags; - uint32_t user_param; - // TODO: above value MUST be same with 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 -{ - uint32_t length; - uint32_t request_type; - uint32_t client_fd; - uint32_t flags; - uint32_t user_param; - // TODO: above value MUST be same with 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 -{ - uint32_t length; - uint32_t request_type; - uint32_t client_fd; - uint32_t flags; - uint32_t user_param; - // TODO: above value MUST be same with 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; - data_s service_name; -} net_nfc_request_listen_socket_t; - -typedef struct _net_nfc_request_receive_socket_t -{ - uint32_t length; - uint32_t request_type; - uint32_t client_fd; - uint32_t flags; - uint32_t user_param; - // TODO: above value MUST be same with 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; - data_s data; -} net_nfc_request_receive_socket_t; - -typedef struct _net_nfc_request_receive_from_socket_t -{ - uint32_t length; - uint32_t request_type; - uint32_t client_fd; - uint32_t flags; - uint32_t user_param; - // TODO: above value MUST be same with 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; - data_s data; -} net_nfc_request_receive_from_socket_t; - -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, /** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/common/net_nfc_debug_internal.h b/common/net_nfc_debug_internal.h deleted file mode 100644 index 4416d0c..0000000 --- a/common/net_nfc_debug_internal.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 -#include -#include -#include -#include -#include - -#define NFC_DEBUGGING - -#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" - -#ifdef API -#undef API -#endif -#define API __attribute__((visibility("default"))) - -const char* net_nfc_get_log_tag(); - -#define DBG(fmt, arg...) SLOG(LOG_DEBUG, net_nfc_get_log_tag(), fmt, ##arg) -#define INFO(fmt, arg...) SLOG(LOG_INFO, net_nfc_get_log_tag(), fmt, ##arg) -#define WARN(fmt, arg...) SLOG(LOG_WARN, net_nfc_get_log_tag(), fmt, ##arg) -#define ERR(fmt, arg...) SLOG(LOG_ERROR, net_nfc_get_log_tag(), fmt, ##arg) - - -#ifdef NFC_DEBUGGING - -#define NFC_FN_CALL DBG(">>>>>>>> called") -#define NFC_FN_END DBG("<<<<<<<< ended") -#define NFC_DBG(fmt, arg...) DBG(fmt, ##arg) -#define NFC_WARN(fmt, arg...) WARN(LOG_COLOR_BROWN fmt LOG_COLOR_END, ##arg) -#define NFC_ERR(fmt, arg...) ERR(LOG_COLOR_RED fmt LOG_COLOR_END, ##arg) -#define NFC_INFO(fmt, arg...) INFO(LOG_COLOR_BLUE fmt LOG_COLOR_END, ##arg) -#define NFC_SECURE_DBG(fmt, arg...) \ - SECURE_SLOG(LOG_DEBUG, net_nfc_get_log_tag(), fmt, ##arg) -#define NFC_SECURE_ERR(fmt, arg...) \ - SECURE_SLOG(LOG_ERROR, net_nfc_get_log_tag(), fmt, ##arg) - -#else /* NFC_DEBUGGING */ - -#define NFC_FN_CALL -#define NFC_FN_END -#define NFC_DBG(fmt, arg...) -#define NFC_WARN(fmt, arg...) -#define NFC_ERR(fmt, arg...) ERR(fmt, ##arg) -#define NFC_INFO(fmt, arg...) -#define NFC_VERBOSE(fmt, arg...) -#define NFC_SECURE_DBG(fmt, arg...) -#define NFC_SECURE_ERR(fmt, arg...) \ - SECURE_SLOG(LOG_ERROR, net_nfc_get_log_tag(), fmt, ##arg) - -#endif /* NFC_DEBUGGING */ - - -#define DEBUG_MSG_PRINT_BUFFER(buffer, length) \ - do { \ - int i = 0, offset = 0; \ - char temp_buffer[4096] = { 0, }; \ - NFC_INFO("BUFFER [%d] = {", 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_INFO("\t%s", temp_buffer); \ - offset = 0; \ - } \ - } \ - NFC_INFO("\t%s", temp_buffer); \ - NFC_INFO("}"); \ - } 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) - -#define RET_IF(expr) \ - do { \ - if (expr) { \ - NFC_ERR("(%s)", #expr); \ - return; \ - }\ - } while(0) -#define RETV_IF(expr, val) \ - do {\ - if (expr) { \ - NFC_ERR("(%s)", #expr); \ - return (val); \ - } \ - } while(0) -#define RETM_IF(expr, fmt, arg...) \ - do {\ - if (expr) { \ - NFC_ERR(fmt, ##arg); \ - return; \ - }\ - } while(0) -#define RETVM_IF(expr, val, fmt, arg...) \ - do {\ - if (expr) { \ - NFC_ERR(fmt, ##arg); \ - return (val); \ - } \ - } while(0) - - -#endif //__NET_NFC_DEBUG_INTERNAL_H__ diff --git a/common/net_nfc_util.c b/common/net_nfc_util.c deleted file mode 100644 index c62a25b..0000000 --- a/common/net_nfc_util.c +++ /dev/null @@ -1,376 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// libc header -#include -#include -#include -#include - -// platform header -#include -#include - -// nfc-manager header -#include "net_nfc_util_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 */ -static const char *log_tag = LOG_CLIENT_TAG; - -const char *net_nfc_get_log_tag() -{ - return log_tag; -} - -void net_nfc_change_log_tag() -{ - log_tag = LOG_SERVER_TAG; -} - -API void __net_nfc_util_free_mem(void **mem, char *filename, unsigned int line) -{ - if (NULL == mem) - { - SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in mem free util, mem is NULL", - filename, line); - return; - } - - if (NULL == *mem) - { - 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 (NULL == mem || 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 (NULL == *mem) - { - 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 (NULL == output || NULL == origin) - { - 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 (NULL == *output) - SECURE_LOGD("FILE: %s, LINE:%d, strdup failed", filename, line); -} - -API bool net_nfc_util_alloc_data(data_s *data, uint32_t length) -{ - RETV_IF(0 == length, false); - RETV_IF(NULL == data, false); - - _net_nfc_util_alloc_mem(data->buffer, length); - if (NULL == data->buffer) - return false; - - data->length = length; - - return true; -} - -API void net_nfc_util_free_data(data_s *data) -{ - RET_IF(NULL == data); - RET_IF(NULL == data->buffer); - - _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 (NET_NFC_CONN_HANDOVER_CARRIER_BT== carrier_type) - { - 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 (NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS == carrier_type) - { - 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) - { - net_nfc_conn_handover_carrier_state_e ret; - - ret = net_nfc_util_get_cps(NET_NFC_CONN_HANDOVER_CARRIER_BT); - - if (ret != 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) - { - int ch; - int i = 0; - int count = 0; - unsigned char temp[BLUETOOTH_ADDRESS_LENGTH * 2] = { 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) -{ - int i = 0; - char *temp = NULL; - bool result = false; - - _net_nfc_util_alloc_mem(temp, buffer_length); - if (NULL == temp) - 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; - uint8_t *temp = buffer; - int msg_length = length - 2; - - // 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_B == CRC_type) - 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) -{ - RETV_IF(0 == index, NULL); - RETV_IF(index >= NET_NFC_SCHEMA_MAX, NULL); - - return schema[index]; -} - diff --git a/common/net_nfc_util_defines.h b/common/net_nfc_util_defines.h deleted file mode 100644 index 2be9279..0000000 --- a/common/net_nfc_util_defines.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 tzplatform_mkpath(TZ_SYS_ETC, ".bd_addr") - -#endif //__NET_NFC_UTIL_DEFINES_H__ diff --git a/common/net_nfc_util_gdbus.c b/common/net_nfc_util_gdbus.c deleted file mode 100644 index c375dc3..0000000 --- a/common/net_nfc_util_gdbus.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" -#include "net_nfc_util_ndef_message.h" - -void net_nfc_util_gdbus_variant_to_buffer(GVariant *variant, uint8_t **buffer, - size_t *length) -{ - guint size = 0; - GVariantIter *iter; - guint8 *buf = NULL; - - RET_IF(NULL == variant); - - 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); - - if (length) - *length = size; - - if (buffer) - *buffer = buf; - else - g_free(buf); - } -} - -data_s *net_nfc_util_gdbus_variant_to_data(GVariant *variant) -{ - guint size = 0; - GVariantIter *iter; - guint8 *buf = NULL; - data_s *result = NULL; - - RETV_IF(NULL == variant, 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) -{ - guint size = 0; - guint8 element; - GVariantIter *iter; - guint8 *buf = NULL; - - RET_IF(NULL == data); - RET_IF(NULL == variant); - - data->buffer = NULL; - data->length = 0; - - 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); -} - -ndef_message_s *net_nfc_util_gdbus_variant_to_ndef_message(GVariant *variant) -{ - data_s data = { NULL, 0 }; - ndef_message_s *temp = NULL; - ndef_message_s *message = NULL; - - RETV_IF(NULL == variant, NULL); - - net_nfc_util_gdbus_variant_to_data_s(variant, &data); - - if (NULL == data.buffer || data.length <= 0) - return NULL; - - if (net_nfc_util_create_ndef_message(&temp) == NET_NFC_OK) - { - if (net_nfc_util_convert_rawdata_to_ndef_message(&data, temp) == NET_NFC_OK) - { - message = temp; - } - else - { - NFC_ERR("net_nfc_create_ndef_message_from_rawdata failed"); - - net_nfc_util_free_ndef_message(temp); - } - } - else - { - NFC_ERR("net_nfc_util_create_ndef_message failed"); - } - - net_nfc_util_free_data(&data); - - return message; -} - - -GVariant *net_nfc_util_gdbus_ndef_message_to_variant( - const ndef_message_s *message) -{ - size_t length; - net_nfc_error_e ret; - data_s *data = NULL; - GVariant *variant = NULL; - - length = net_nfc_util_get_ndef_message_length((ndef_message_s *)message); - if (length > 0) - { - data_s temp = { NULL, 0 }; - - if (net_nfc_util_alloc_data(&temp, length) == true) - { - ret = net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s *)message, - &temp); - if (NET_NFC_OK == ret) - { - data = &temp; - } - else - { - NFC_ERR("can not convert ndef_message to rawdata"); - - net_nfc_util_free_data(&temp); - } - } - else - { - NFC_ERR("net_nfc_util_alloc_data failed"); - } - } - else - { - NFC_ERR("message length is 0"); - } - - variant = net_nfc_util_gdbus_data_to_variant(data); - - if (data != NULL) - net_nfc_util_free_data(data); - - return variant; -} diff --git a/common/net_nfc_util_gdbus_internal.h b/common/net_nfc_util_gdbus_internal.h deleted file mode 100644 index e3d5868..0000000 --- a/common/net_nfc_util_gdbus_internal.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -#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); - -ndef_message_s *net_nfc_util_gdbus_variant_to_ndef_message(GVariant *variant); - -GVariant *net_nfc_util_gdbus_ndef_message_to_variant( - const ndef_message_s *message); - -#endif //__NET_NFC_UTIL_GDBUS_INTERNAL_H__ diff --git a/common/net_nfc_util_handover.c b/common/net_nfc_util_handover.c deleted file mode 100755 index 19b5db0..0000000 --- a/common/net_nfc_util_handover.c +++ /dev/null @@ -1,1630 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "net_nfc_typedef_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; - -void net_nfc_convert_byte_order(unsigned char *array, int size) -{ - int i; - unsigned char tmp_char; - - for ( i = 0; i < size/2; i++) - { - tmp_char = array[i]; - array[i] = array[size-1-i]; - array[size-1-i] = tmp_char; - } -} - - -static int __property_equal_to(gconstpointer key1, gconstpointer key2) -{ - const net_nfc_carrier_property_s *arg1 = key1; - const net_nfc_carrier_property_s *arg2 = 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 (NULL == found) - return NULL; - - return (net_nfc_carrier_property_s *)found->data; -} - -static void __find_nth_group(gpointer data, gpointer user_data) -{ - search_index *nth = user_data; - net_nfc_carrier_property_s *info = data; - - RET_IF(NULL == info); - RET_IF(NULL == user_data); - - 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 = data; - - RET_IF(NULL == info); - - if (info->is_group) - { - NFC_DBG("FREE: group is found"); - net_nfc_util_free_carrier_group(info); - } - else - { - NFC_DBG("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; - uint16_t random_num; - data_s payload = { 0 }; - data_s typeName = { 0 }; - uint8_t rand_buffer[2] = { 0, 0 }; - - RETV_IF(NULL == record, 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; - - NFC_DBG("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) -{ - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - RETV_IF(type < 0, NET_NFC_OUT_OF_BOUND); - RETV_IF(type >= NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, NET_NFC_OUT_OF_BOUND); - - _net_nfc_util_alloc_mem(*config, sizeof(net_nfc_carrier_config_s)); - if (NULL == *config) - 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; - - NFC_DBG("ADD property: [ATTRIB:0x%X, SIZE:%d]", attribute, size); - - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == data, 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 (NULL == elem) - return NET_NFC_ALLOC_FAIL; - - elem->attribute = attribute; - elem->length = size; - elem->is_group = false; - - _net_nfc_util_alloc_mem(elem->data, size); - if (NULL == elem->data) - { - _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); - - NFC_DBG("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; - - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - - elem = __find_property_by_attrubute(config->data, attribute); - if (NULL == elem) - 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(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; - - RETV_IF(NULL == size, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - - elem = __find_property_by_attrubute(config->data, attribute); - if (NULL == elem) - { - *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) -{ - RETV_IF(NULL == group, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == config, 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+4; - - 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) -{ - RETV_IF(NULL == group, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == config, 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(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; - - RETV_IF(NULL == group, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - RETV_IF(index < 0, NET_NFC_OUT_OF_BOUND); - - result.current = 0; - result.target = index; - result.found = NULL; - - g_list_foreach(config->data, __find_nth_group, &result); - - if (NULL == result.found) - 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) -{ - RETV_IF(NULL == config, 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) -{ - RETV_IF(NULL == group, NET_NFC_NULL_PARAMETER); - - _net_nfc_util_alloc_mem(*group, sizeof(net_nfc_carrier_property_s)); - if (NULL == *group) - 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; - - NFC_DBG("ADD group property: [ATTRIB:0x%X, SIZE:%d]", attribute, size); - - RETV_IF(NULL == group, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == data, 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 (NULL == elem) - return NET_NFC_ALLOC_FAIL; - - elem->attribute = attribute; - elem->length = size; - elem->is_group = false; - - _net_nfc_util_alloc_mem(elem->data, size); - if (NULL == elem->data) - { - _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); - - NFC_DBG("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; - - RETV_IF(NULL == size, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == group, NET_NFC_NULL_PARAMETER); - - elem = __find_property_by_attrubute((GList*)(group->data), attribute); - if (NULL == elem) - { - *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; - - RETV_IF(NULL == group, NET_NFC_NULL_PARAMETER); - - elem = __find_property_by_attrubute((GList*)(group->data), attribute); - if (NULL == elem) - 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) -{ - RETV_IF(NULL == group, 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) -{ - int inc = 0; - uint8_t *current; - data_s *payload = user_data; - net_nfc_carrier_property_s *info = data; - - RET_IF(NULL == info); - RET_IF(NULL == user_data); - - current = payload->buffer + payload->length; - inc = __net_nfc_get_size_of_attribute(info->attribute); - - if (info->is_group) - { - NFC_DBG("[WIFI]Found Group make recursive"); - *(uint16_t *)current = info->attribute; - net_nfc_convert_byte_order(current,2); - *(uint16_t *)(current + inc) = info->length; - net_nfc_convert_byte_order((current + inc),2); - payload->length += (inc + inc); - g_list_foreach((GList *)info->data, __make_serial_wifi, payload); - } - else - { - NFC_DBG("[WIFI]Element is found attrib:0x%X length:%d current:%d", - info->attribute, info->length, payload->length); - *(uint16_t *)current = info->attribute; - net_nfc_convert_byte_order(current,2); - *(uint16_t *)(current + inc) = info->length; - net_nfc_convert_byte_order((current + inc),2); - memcpy(current + inc + inc, info->data, info->length); - payload->length += (inc + inc + info->length); - } -} - -static void __make_serial_bt(gpointer data, gpointer user_data) -{ - int inc = 0; - uint8_t *current; - data_s *payload = user_data; - net_nfc_carrier_property_s *info = data; - - RET_IF(NULL == info); - RET_IF(NULL == user_data); - - current = payload->buffer + payload->length; /* payload->length is zero */ - - if (info->is_group) - { - NFC_DBG("[BT]Found Group. call recursive"); - g_list_foreach((GList *)info->data, __make_serial_bt, payload); - } - else - { - if (info->attribute != NET_NFC_BT_ATTRIBUTE_ADDRESS) - { - NFC_DBG("[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 - { - NFC_DBG("[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 }; - - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - - _net_nfc_util_alloc_mem(payload.buffer, config->length); - if (NULL == payload.buffer) - return NET_NFC_ALLOC_FAIL; - - payload.length = 0; /* this should be zero because this will be used as current position of data written */ - - if (NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS == config->type) - { - 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 (NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS == config->type) - { - 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 (NET_NFC_CONN_HANDOVER_CARRIER_BT == config->type) - { - 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; - } - - NFC_DBG("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 (NULL == elem) - 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 (NULL == elem->data) - { - _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) -{ - uint8_t *last = NULL; - uint8_t *current = data; - net_nfc_carrier_property_s *elem = 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 (NULL == elem) - 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 (NULL == elem->data) - { - _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 (NULL == elem) - 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 (NULL == elem->data) - { - _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 - { - NFC_DBG("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_carrier_record(ndef_record_s ** record) -{ - data_s payload = {NULL,0}; - - data_s type = { NULL, 0 }; - uint8_t *buffer_ptr = NULL; - - _net_nfc_util_alloc_mem(payload.buffer,26);//hardcoded as of now - if (payload.buffer == NULL) - return NET_NFC_ALLOC_FAIL; - - buffer_ptr = payload.buffer; - - //copy ctf - buffer_ptr[0]= NET_NFC_RECORD_MIME_TYPE; - - //copy the MIME type length - buffer_ptr[1] = strlen(CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME); - - //copy the MIME - memcpy(&buffer_ptr[2],CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME,(payload.buffer)[1]); - payload.buffer[25] = '\0'; - - payload.length =26; - type.buffer = (uint8_t *)CH_CAR_RECORD_TYPE; - type.length = strlen(CH_CAR_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; -} -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 - NFC_ERR("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 - NFC_ERR("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 - { - NFC_ERR("net_nfc_util_convert_ndef_message_to_rawdata failed [%d]", error); - _net_nfc_util_free_mem(tdata.buffer); - } - } - else - { - NFC_ERR("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) - { - NFC_ERR("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) - { - NFC_ERR("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) - { - NFC_ERR("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) - { - NFC_ERR("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) - { - NFC_ERR("__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) - { - NFC_ERR("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) - { - NFC_ERR("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) - { - NFC_DBG("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) - { - NFC_DBG("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) - { - NFC_DBG("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) - { - NFC_DBG("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) - { - NFC_DBG("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) - { - NFC_DBG("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) - { - NFC_DBG("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) - { - NFC_DBG("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) - { - NFC_DBG("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) - { - NFC_DBG("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, CH_CAR_RECORD_TYPE, (size_t)record->type_s.length) == 0) - { - NFC_DBG("CH_CAR_RECORD_TYPE"); - - char ctf = record->payload_s.buffer[0] & 0x07; - char ctype_length = record->payload_s.buffer[1]; - switch(ctf) - { - case NET_NFC_RECORD_MIME_TYPE: /* Media Type as defined in [RFC 2046] */ - if (strncmp((char *)&record->payload_s.buffer[2], - CONN_HANDOVER_BT_CARRIER_MIME_NAME, - (size_t)ctype_length) == 0) - { - *type = NET_NFC_CONN_HANDOVER_CARRIER_BT; - } - else if (strncmp((char *)&record->payload_s.buffer[2], - CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME, - (size_t)ctype_length) == 0) - { - *type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS; - } - else if (strncmp((char *)&record->payload_s.buffer[2], - CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME, - (size_t)ctype_length) == 0) - { - *type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS; - } - else - { - *type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; - } - break; - case NET_NFC_RECORD_WELL_KNOWN_TYPE: /* NFC Forum Well-known Type*/ - case NET_NFC_RECORD_URI: /* Absolute URIs as defined in [RFC 3986] */ - case NET_NFC_RECORD_EXTERNAL_RTD: /* NFC Forum external type */ - default: - *type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; - break; - } - - } - else - { - NFC_DBG("Other record 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 ret; - - ret = net_nfc_util_get_carrier_config_record(message, index, &record); - if (ret != NET_NFC_OK) - return ret; - - 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; - - 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 - { - NFC_ERR("_net_nfc_util_create_ndef_message failed [%d]", error); - } - - net_nfc_util_free_ndef_message(inner_msg); - } - else - { - NFC_ERR("_net_nfc_util_create_ndef_message failed [%d]", error); - error = NET_NFC_ALLOC_FAIL; - } - - return error; -} - diff --git a/common/net_nfc_util_internal.h b/common/net_nfc_util_internal.h deleted file mode 100644 index 6dfe3ef..0000000 --- a/common/net_nfc_util_internal.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 -#include -#include - -/* For multi-user support */ -#include - -#include "net_nfc_typedef_internal.h" - -#define NET_NFC_MANAGER_DATA_PATH tzplatform_mkpath(TZ_SYS_DATA, "nfc-manager-daemon") -#define NET_NFC_MANAGER_DATA_PATH_MESSAGE "message" -#define NET_NFC_MANAGER_NDEF_FILE_NAME "ndef-message.txt" - - -typedef enum -{ - CRC_A = 0x00, - CRC_B, -} CRC_type_e; - -void net_nfc_change_log_tag(); - -/* 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); -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__ diff --git a/common/net_nfc_util_ndef_message.c b/common/net_nfc_util_ndef_message.c deleted file mode 100644 index 1bbb629..0000000 --- a/common/net_nfc_util_ndef_message.c +++ /dev/null @@ -1,780 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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) -{ - uint8_t *last = NULL; - uint8_t *current = NULL; - uint8_t ndef_header = 0; - ndef_record_s *newRec = NULL; - ndef_record_s *prevRec = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == ndef, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == rawdata, NET_NFC_NULL_PARAMETER); - RETV_IF(rawdata->length < 3, NET_NFC_INVALID_FORMAT); - - current = rawdata->buffer; - last = current + rawdata->length; - - 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 (NULL == newRec) - { - 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 (NULL == newRec->type_s.buffer) - { - 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 (NULL == newRec->id_s.buffer) - { - 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: - - NFC_ERR("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++; - - NFC_DBG("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 - NFC_DBG("========== NDEF Message ====================================\n"); - NFC_DBG("Total NDEF Records count: %d\n", msg->recordCount); - current = msg->records; - for (idx = 0; idx < msg->recordCount; idx++) - { - if (current == NULL) - { - NFC_ERR("Message Record is NULL!! unexpected error"); - NFC_DBG("============================================================\n"); - return; - } - NFC_DBG("---------- Record -----------------------------------------\n"); - NFC_DBG("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); - NFC_DBG("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'; - NFC_DBG("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) - { - NFC_DBG("Payload: "); - for (idx2 = 0; idx2 < current->payload_s.length; idx2++) - { - if (idx2 % 16 == 0) - NFC_DBG("\n\t"); - NFC_DBG("%02X ", current->payload_s.buffer[idx2]); - } - NFC_DBG("\n"); - } - current = current->next; - } - // 123456789012345678901234567890123456789012345678901234567890 - NFC_DBG("============================================================\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; -} - diff --git a/common/net_nfc_util_ndef_record.c b/common/net_nfc_util_ndef_record.c deleted file mode 100644 index 669052c..0000000 --- a/common/net_nfc_util_ndef_record.c +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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) -{ - RETV_IF(NULL == record, 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, - const data_s *typeName, const data_s *id, const data_s *payload, - ndef_record_s **record) -{ - ndef_record_s *record_temp = NULL; - - RETV_IF(NULL == typeName, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == payload, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - - RETV_IF(recordType < NET_NFC_RECORD_EMPTY, NET_NFC_OUT_OF_BOUND); - RETV_IF(recordType > NET_NFC_RECORD_UNCHAGNED, NET_NFC_OUT_OF_BOUND); - - /* empty_tag */ - if (NET_NFC_RECORD_EMPTY == recordType) - { - 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 (NULL == record_temp) - 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 (NULL == record_temp->type_s.buffer) - { - _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 (NULL == 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->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 (NULL == record_temp->id_s.buffer) - { - _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) -{ - data_s type_data; - net_nfc_error_e error; - data_s payload_data = { NULL, 0 }; - - RETV_IF(NULL == uri, NET_NFC_NULL_PARAMETER); - - payload_data.length = strlen((char *)uri) + 1; - - RETV_IF(1 == payload_data.length, NET_NFC_INVALID_PARAM); - - _net_nfc_util_alloc_mem(payload_data.buffer, payload_data.length); - if (NULL == payload_data.buffer) - 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) -{ - int offset = 0; - data_s type_data; - int controll_byte; - data_s payload_data; - - RETV_IF(NULL == text, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == lang_code_str, NET_NFC_NULL_PARAMETER); - - RETVM_IF(encode < NET_NFC_ENCODE_UTF_8 || NET_NFC_ENCODE_UTF_16 < encode , - NET_NFC_OUT_OF_BOUND, "encode(%d) is invalid", encode); - - payload_data.length = strlen((char *)text) + strlen(lang_code_str) + 1; - - _net_nfc_util_alloc_mem(payload_data.buffer, payload_data.length); - if (NULL == payload_data.buffer) - { - return NET_NFC_ALLOC_FAIL; - } - - controll_byte = strlen(lang_code_str) & 0x3F; - if (NET_NFC_ENCODE_UTF_16 == encode) - { - 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) -{ - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - RETV_IF(length < 1, 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; - - RETV_IF(NULL == Record, 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; - - RETV_IF(NULL == uri, NET_NFC_INVALID_PARAM); - RETV_IF(NULL == record, NET_NFC_INVALID_PARAM); - - *uri = NULL; - - if (NET_NFC_RECORD_WELL_KNOWN_TYPE == record->TNF && - (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 - { - NFC_ERR("invalid payload in record"); - } - } - else if (NET_NFC_RECORD_URI == record->TNF) - { - 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 - { - NFC_ERR("no uri record"); - result = NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE; - } - - return result; -} diff --git a/common/net_nfc_util_openssl.c b/common/net_nfc_util_openssl.c deleted file mode 100644 index 0e75387..0000000 --- a/common/net_nfc_util_openssl.c +++ /dev/null @@ -1,873 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include - -#include "net_nfc_typedef_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 - { - NFC_ERR("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 -// { -// NFC_ERR("X509_STORE_add_lookup failed"); -// } -// } -// else -// { -// NFC_ERR("X509_LOOKUP_load_file failed"); -// } -// } -// else -// { -// NFC_ERR("X509_STORE_add_lookup failed"); -// } -// -// X509_STORE_free(cert_ctx); -// } -// else -// { -// NFC_ERR("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 - NFC_ERR("X509_STORE_new failed"); - } - else - { - NFC_ERR("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) -{ - X509 *x509 = NULL; - bool result = false; - - 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 - NFC_ERR("X509_STORE_CTX_init failed"); - - X509_STORE_CTX_free(store_ctx); - } - else - { - NFC_ERR("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 - NFC_ERR("Mac verify error (wrong password?) in PKCS12 file"); - - PKCS12_free(p12); - } - else - { - NFC_ERR("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 (NULL == file) - { - NFC_ERR("no keyfile specified\n"); - return pkey; - } - - if (OPENSSL_FORMAT_ENGINE == format) - { - if (e != NULL) - { - pkey = ENGINE_load_private_key(e, file, NULL/*ui_method*/, (void *)pass); - if (!pkey) - NFC_ERR("cannot load key from engine"); - } - else - { - NFC_ERR("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) - NFC_ERR("_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 : - NFC_ERR("bad input format specified for key file"); - break; - } - } - else - { - NFC_ERR("Error opening %s", file); - } - - BIO_free(key); - } - else - { - NFC_ERR("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 (NULL == file) - { - NFC_ERR("no keyfile specified"); - return pkey; - } - - if (OPENSSL_FORMAT_ENGINE == format) - { - if (e != NULL) - pkey = ENGINE_load_public_key(e, file, NULL/*ui_method*/, (void *)pass); - else - NFC_ERR("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 : - NFC_ERR("bad input format specified for key file"); - break; - } - } - else - { - NFC_ERR("Error opening %s %s", key_descrip, file); - } - - BIO_free(key); - } - else - { - NFC_ERR("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) -{ - EVP_PKEY *pkey; - ENGINE *engine; - int result = 0; - const EVP_MD *md = NULL; - - 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) -{ - EVP_PKEY *pkey; - int result = 0; - ENGINE *engine; - const EVP_MD *md = NULL; - - 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); - - NFC_DBG("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); - } - } - } - - NFC_DBG("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 - { - NFC_ERR("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) - { - int i; - int32_t ret = 0; - X509 *temp_x509; - uint32_t count = 0; - uint32_t offset = 0; - uint32_t temp_len = 0; - uint8_t *temp_buf = NULL; - - 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); - } - } - } - - NFC_DBG("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 - { - NFC_ERR("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) -{ - BUF_MEM *bptr; - BIO *b64, *bmem; - bool ret = false; - - RETV_IF(0 == buf_len, ret); - RETV_IF(NULL == buffer, ret); - - b64 = BIO_new(BIO_f_base64()); - bmem = BIO_new(BIO_s_mem()); - - if (false == new_line_char) - 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 - { - NFC_ERR("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) -{ - char *temp; - bool ret = false; - unsigned int length = 0; - - RETV_IF(NULL == buffer, ret); - RETV_IF((length = strlen(buffer)) == 0, 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 (false == new_line_char) - 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 - { - NFC_ERR("not enough result buffer"); - } - - _net_nfc_util_free_mem(temp); - } - else - { - NFC_ERR("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; - bool ret = false; - unsigned char *temp; - - RETV_IF(0 == buf_len, ret); - RETV_IF(buffer == NULL, ret); - RETV_IF(algorithm == NULL, 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) - NFC_ERR("EVP_DigestUpdate failed"); - - EVP_DigestFinal(&mdCtx, temp, &resultLen); - - if (*out_len >= resultLen) - { - *out_len = resultLen; - memcpy(result, temp, *out_len); - ret = true; - } - else - { - NFC_ERR("not enough result buffer"); - } - - _net_nfc_util_free_mem(temp); - } - else - { - NFC_ERR("alloc failed"); - } - } - else - { - NFC_ERR("EVP_get_digestbyname(\"%s\") returns NULL", algorithm); - } - - return ret; -} diff --git a/common/net_nfc_util_openssl_internal.h b/common/net_nfc_util_openssl_internal.h deleted file mode 100644 index 28aa669..0000000 --- a/common/net_nfc_util_openssl_internal.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -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__ diff --git a/common/net_nfc_util_sign_record.c b/common/net_nfc_util_sign_record.c deleted file mode 100644 index 4fef23d..0000000 --- a/common/net_nfc_util_sign_record.c +++ /dev/null @@ -1,403 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "net_nfc_debug_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) -{ - uint32_t len = 0; - bool result = false; - ndef_record_s *current_record = NULL; - - RETV_IF(NULL == begin_record, result); - RETV_IF(begin_record == end_record, 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) -{ - int ret; - uint32_t length = 0; - uint8_t *buffer = NULL; - net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; - - RETV_IF(NULL == sign_record, NET_NFC_INVALID_PARAM); - RETV_IF(NULL == begin_record, NET_NFC_INVALID_PARAM); - RETV_IF(begin_record == sign_record, NET_NFC_INVALID_PARAM); - - /* get signed data */ - if (_get_records_data_buffer(begin_record, sign_record, &buffer, &length) == true) - { - 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; - - NFC_DBG("record version : %d", sign_info->version); - NFC_DBG("signature URI present? : %s", sign_info->uri_present ? "true" : "false"); - NFC_DBG("signature type : %d", sign_info->sign_type); - NFC_DBG("signature length : %d", sign_info->signature.length); - - if (true == sign_info->uri_present) - { - /* TODO */ - /* receive the signature data directed by uri */ - NFC_ERR("NOT IMPLEMENTED (sign_info->uri_present == true)"); - _net_nfc_util_free_mem(buffer); - return result; - } - - /* 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"); - NFC_DBG("certificate format : %d", chain_info->cert_format); - NFC_DBG("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; - NFC_DBG("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 */ - ret = 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); - - if (true == ret) - { - 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)) - { - NFC_DBG("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 (true == chain_info->uri_present) - { - /* TODO : Need to implement */ - NFC_ERR("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; - - //NFC_DBG("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; - } - - NFC_DBG("verifying signature %d", result); - } - else - { - NFC_ERR("verifying signature failed"); - } - } - else - { - NFC_ERR("certificate not found"); - } - - _net_nfc_util_free_mem(buffer); - } - else - { - if(buffer != NULL) - _net_nfc_util_free_mem(buffer); - - NFC_ERR("_get_records_data_buffer failed"); - } - - return result; -} - -net_nfc_error_e net_nfc_util_verify_signature_ndef_message(ndef_message_s *msg) -{ - ndef_record_s *begin_record = NULL; - ndef_record_s *current_record = NULL; - net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; - - - begin_record = msg->records; - current_record = msg->records; - - while (current_record != NULL) - { - if (NULL == begin_record) - 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) -{ - uint32_t cert_len = 0; - uint32_t data_len = 0; - uint32_t cert_count = 0; - uint8_t *data_buffer = NULL; - uint8_t *cert_buffer = NULL; - data_s payload = { NULL, 0 }; - uint8_t signature[1024] = { 0, }; - uint32_t sign_len = sizeof(signature); - net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; - ndef_record_s *begin_record = NULL, *end_record = NULL, *record = NULL; - - - net_nfc_util_get_record_by_index(msg, begin_index, &begin_record); - net_nfc_util_get_record_by_index(msg, end_index, &end_record); - - NFC_DBG("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 */ - NFC_ERR("num_of_certs is greater than 15 [%d]", cert_count); - } - - /* create record */ - data_s type = { (uint8_t *)"Sig", 3 }; - - net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, - &payload, &record); - - /* get last record index */ - net_nfc_util_append_record_by_index(msg, end_index + 1, record); - - _net_nfc_util_free_mem(payload.buffer); - _net_nfc_util_free_mem(cert_buffer); - _net_nfc_util_free_mem(data_buffer); - - return result; -} - -net_nfc_error_e net_nfc_util_sign_ndef_message(ndef_message_s *msg, - char *cert_file, char *password) -{ - net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; - - if (msg->recordCount > 0) - { - net_nfc_util_sign_records(msg, 0, msg->recordCount - 1, cert_file, password); - - result = NET_NFC_OK; - } - - return result; -} diff --git a/common/nfc-common.pc.in b/common/nfc-common.pc.in deleted file mode 100644 index 9e0e227..0000000 --- a/common/nfc-common.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix}/bin -libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDE_INSTALL_DIR@/@NFC_COMMON@ - -Name: @NFC_COMMON@ -Description: NFC Common Headers -Version: @FULLVER@ -Requires: -Libs: -Cflags: -I${includedir} diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt deleted file mode 100755 index 6e33b84..0000000 --- a/daemon/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -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) - -IF(X11_SUPPORT) - SET(WIN_PKG "ecore-x") -ENDIF(X11_SUPPORT) -IF(WAYLAND_SUPPORT) - SET(WIN_PKG "${WIN_PKG} ecore-wayland") -ENDIF(WAYLAND_SUPPORT) -IF(ARM_TARGET) - 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 pmapi wifi-direct - libtzplatform-config ${WIN_PKG}) -ELSE(ARM_TARGET) -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 pmapi libtzplatform-config ${WIN_PKG}) -ENDIF(ARM_TARGET) - -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/system-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) diff --git a/daemon/net_nfc_server.c b/daemon/net_nfc_server.c deleted file mode 100644 index e6448fb..0000000 --- a/daemon/net_nfc_server.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include - -#include "net_nfc_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_phdc.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_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) -{ - GVariant *_ret; - guint pid = 0; - GError *error = NULL; - - _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) -{ - RET_IF(NULL == name); - RET_IF(NULL == old_owner); - RET_IF(NULL == new_owner); - - 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() -{ - RET_IF(NULL == connection); - - /* 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() -{ - RET_IF(NULL == connection); - - /* 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 (NULL == connection) - { - NFC_ERR("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) - { - NFC_ERR("Can not init manager"); - return; - } - - if (net_nfc_server_tag_init(connection) == FALSE) - { - NFC_ERR("Can not init tag"); - return; - } - - if (net_nfc_server_ndef_init(connection) == FALSE) - { - NFC_ERR("Can not init ndef"); - return; - } - - if (net_nfc_server_llcp_init(connection) == FALSE) - { - NFC_ERR("Can not init llcp"); - return; - } - - if (net_nfc_server_p2p_init(connection) == FALSE) - { - NFC_ERR("Can not init p2p"); - return; - } - - if (net_nfc_server_transceive_init(connection) == FALSE) - { - NFC_ERR("Can not initialize transceive"); - return; - } - - if (net_nfc_server_handover_init(connection) == FALSE) - { - NFC_ERR("Can not initialize handover"); - return; - } - - if (net_nfc_server_se_init(connection) == FALSE) - { - NFC_ERR("Can not init se"); - return; - } - - if (net_nfc_server_snep_init(connection) == FALSE) - { - NFC_ERR("Can not init snep"); - return; - } - - if (net_nfc_server_system_handler_init(connection) == FALSE) - { - NFC_ERR("Can not init system handler"); - return; - } - - if (net_nfc_server_phdc_init(connection) == FALSE) - { - NFC_ERR("Can not init phdc"); - return; - } - - if (net_nfc_server_controller_thread_init() == FALSE) - { - NFC_ERR("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_handover_deinit(); - net_nfc_server_se_deinit(); - net_nfc_server_snep_deinit(); - net_nfc_server_system_handler_deinit(); - net_nfc_server_phdc_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() -{ - NFC_DBG("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; - - NFC_DBG("bus path : %s", path); - - net_nfc_server_gdbus_init(); - - net_nfc_server_controller_init(); - - if (vconf_get_bool(VCONFKEY_NFC_STATE, &state) != 0) - { - NFC_DBG("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) -{ - NFC_INFO("name : %s", name); -} - -static void on_name_lost(GDBusConnection *connnection, const gchar *name, - gpointer user_data) -{ - NFC_INFO("name : %s", name); - - net_nfc_manager_quit(); -} - - -int main(int argc, char *argv[]) -{ - guint id = 0; - void *handle = NULL; - GError *error = NULL; - gboolean use_daemon = FALSE; - GOptionContext *option_context; - - net_nfc_change_log_tag(); - - 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) - { - NFC_ERR("can not parse option: %s", error->message); - g_error_free(error); - - g_option_context_free(option_context); - return 0; - } - - NFC_DBG("start nfc manager"); - NFC_INFO("use_daemon : %d", use_daemon); - - net_nfc_app_util_clean_storage(MESSAGE_STORAGE); - - handle = net_nfc_controller_onload(); - if (NULL == handle) - { - NFC_ERR("load plugin library is failed"); - - if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_OFF) != 0) - NFC_ERR("VCONFKEY_NFC_FEATURE set to %d failed", VCONFKEY_NFC_FEATURE_OFF); - - if (vconf_set_bool(VCONFKEY_NFC_STATE, 0) != 0) - NFC_ERR("VCONFKEY_NFC_STATE set to %d failed", 0); - - goto EXIT; - } - - if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_ON) != 0) - NFC_ERR("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); - - g_option_context_free(option_context); - - return 0; -} \ No newline at end of file diff --git a/daemon/net_nfc_server.h b/daemon/net_nfc_server.h deleted file mode 100644 index 972fc84..0000000 --- a/daemon/net_nfc_server.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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__ diff --git a/daemon/net_nfc_server_common.c b/daemon/net_nfc_server_common.c deleted file mode 100644 index eb2c6d4..0000000 --- a/daemon/net_nfc_server_common.c +++ /dev/null @@ -1,430 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "net_nfc_debug_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 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 (NULL == controller_async_queue) - { - 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); -} - -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; - } -} - -static void _controller_llcp_event_cb(gpointer user_data) -{ - net_nfc_request_llcp_msg_t *req_msg = (net_nfc_request_llcp_msg_t *)user_data; - - RET_IF(NULL == req_msg); - - switch (req_msg->request_type) - { - case NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED: - net_nfc_server_llcp_deactivated(NULL); - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_LISTEN: - { - net_nfc_request_listen_socket_t *msg = - (net_nfc_request_listen_socket_t *)user_data; - - net_nfc_controller_llcp_incoming_cb(msg->client_socket, - msg->result, NULL, (void *)req_msg->user_param); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR: - case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR: - net_nfc_controller_llcp_socket_error_cb(req_msg->llcp_socket, - req_msg->result, NULL, (void *)req_msg->user_param); - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_SEND: - case NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO: - net_nfc_controller_llcp_sent_cb(req_msg->llcp_socket, - req_msg->result, NULL, (void *)req_msg->user_param); - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE: - { - net_nfc_request_receive_socket_t *msg = - (net_nfc_request_receive_socket_t *)user_data; - data_s data = { msg->data.buffer, msg->data.length }; - - net_nfc_controller_llcp_received_cb(msg->client_socket, - msg->result, &data, (void *)req_msg->user_param); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM: - { - net_nfc_request_receive_from_socket_t *msg = - (net_nfc_request_receive_from_socket_t *)user_data; - data_s data = { msg->data.buffer, msg->data.length }; - - /* FIXME : pass sap */ - net_nfc_controller_llcp_received_cb(msg->client_socket, - msg->result, &data, (void *)req_msg->user_param); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT: - case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP: - net_nfc_controller_llcp_connected_cb(req_msg->llcp_socket, - req_msg->result, NULL, (void *)req_msg->user_param); - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT: - net_nfc_controller_llcp_disconnected_cb(req_msg->llcp_socket, - req_msg->result, NULL, (void *)req_msg->user_param); - break; - - default: - break; - } - - /* FIXME : should be removed when plugins would be fixed*/ - _net_nfc_util_free_mem(req_msg); -} - -/* FIXME : net_nfc_dispatcher_queue_push() need to be removed */ -static void controller_llcp_event_cb(void *info, void *user_context) -{ - if(net_nfc_server_controller_async_queue_push( - _controller_llcp_event_cb, info) == FALSE) - { - NFC_ERR("Failed to push onto the queue"); - } -} - -static void controller_init_thread_func(gpointer user_data) -{ - net_nfc_error_e result; - - if (net_nfc_controller_init(&result) == false) - { - NFC_ERR("net_nfc_controller_init failed, [%d]", result); - - net_nfc_manager_quit(); - return; - } - - NFC_INFO("net_nfc_controller_init success, [%d]", result); - - if (net_nfc_controller_register_listener(controller_target_detected_cb, - controller_se_transaction_cb, - controller_llcp_event_cb, - &result) == false) - { - NFC_ERR("net_nfc_contorller_register_listener failed [%d]", - result); - } - - NFC_INFO("net_nfc_contorller_register_listener success"); - - result = net_nfc_server_llcp_set_config(NULL); - - if (result != NET_NFC_OK) - NFC_ERR("net_nfc_server_llcp_set config failed, [%d]", result); - - NFC_INFO("net_nfc_server_llcp_set_config success"); -} - -#ifndef ESE_ALWAYS_ON -static void controller_deinit_thread_func(gpointer user_data) -{ - net_nfc_error_e result; - - if (net_nfc_controller_configure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, - NET_NFC_ALL_DISABLE, &result) == false) - { - NFC_ERR("net_nfc_controller_configure_discovery failed, [%d]", result); - } - - net_nfc_server_free_target_info(); - - if (net_nfc_controller_deinit() == false) - { - NFC_ERR("net_nfc_controller_deinit failed, [%d]", result); - return; - } - - NFC_INFO("net_nfc_controller_deinit success"); - - 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) - NFC_ERR("%s does not exist", "VCONFKEY_NFC_STATE"); - - if (state == 0) - return; - - if (vconf_get_int(VCONFKEY_PM_STATE, &pm_state) != 0) - NFC_ERR("%s does not exist", "VCONFKEY_PM_STATE"); - - NFC_DBG("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) - { - NFC_DBG("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) - { - NFC_DBG("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 (NULL == controller_thread) - { - NFC_ERR("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) - { - NFC_ERR("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) - { - NFC_ERR("Failed to push onto the queue"); - } -} - -#ifndef ESE_ALWAYS_ON -void net_nfc_server_controller_deinit(void) -{ - int ret; - - ret = net_nfc_server_controller_async_queue_push(controller_deinit_thread_func, NULL); - if (FALSE == ret) - { - NFC_ERR("Failed to push onto the queue"); - } -} -#endif - -gboolean net_nfc_server_controller_async_queue_push( - net_nfc_server_controller_func func, gpointer user_data) -{ - ControllerFuncData *func_data; - - if(NULL == controller_async_queue) - { - NFC_ERR("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) - { - NFC_ERR("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; -} diff --git a/daemon/net_nfc_server_common.h b/daemon/net_nfc_server_common.h deleted file mode 100644 index 8029f30..0000000 --- a/daemon/net_nfc_server_common.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -#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__ diff --git a/daemon/net_nfc_server_context.c b/daemon/net_nfc_server_context.c deleted file mode 100644 index e3f47ba..0000000 --- a/daemon/net_nfc_server_context.c +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "vconf.h" -#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_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 - int result; - data_s priv = { NULL, 0 }; - - RETV_IF(NULL == right, false); - RETV_IF(NULL == object, false); - RETV_IF(NULL == privilege, 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) - { - NFC_ERR("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); - NFC_DBG("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); - - NFC_DBG("current client count = [%d]", - net_nfc_server_gdbus_get_client_count_no_lock()); - } - else - { - NFC_ERR("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) - { - NFC_DBG("clean up client context, [%s, %d]", info->id, info->pid); - - g_hash_table_remove(client_contexts, id); - - _cleanup_client_context(info); - - NFC_DBG("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) -{ - char *id; - GHashTableIter iter; - net_nfc_client_context_info_t *info; - - RET_IF(NULL == cb); - - 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) -{ - char *id; - GHashTableIter iter; - net_nfc_client_context_info_t *info = NULL, *temp; - net_nfc_launch_popup_state_e state = NET_NFC_LAUNCH_APP_SELECT; - - 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 (NET_NFC_NO_LAUNCH_APP_SELECT == temp->launch_popup_state_no_check) - { - state = NET_NFC_NO_LAUNCH_APP_SELECT; - break; - } - - if (pid == temp->pgid) - { - 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) - { - char *id; - GHashTableIter iter; - 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; -} diff --git a/daemon/net_nfc_server_context.h b/daemon/net_nfc_server_context.h deleted file mode 100644 index 6b9b033..0000000 --- a/daemon/net_nfc_server_context.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 -#include -#include - -#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__ diff --git a/daemon/net_nfc_server_controller.c b/daemon/net_nfc_server_controller.c deleted file mode 100644 index d0c8079..0000000 --- a/daemon/net_nfc_server_controller.c +++ /dev/null @@ -1,1324 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 -#include -#include -#include -#include -#include -#include -#include -#include - -#include /*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_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) -{ - struct stat st; - void *handle = NULL; - net_nfc_error_e result; - char path[PATH_MAX] = { '\0' }; - - bool (*onload)(net_nfc_oem_interface_s *interfaces); - - snprintf(path, PATH_MAX, "%s/%s", dir_path, filename); - NFC_DBG("path : %s", path); - - if (stat(path, &st) == -1) - { - NFC_ERR("stat failed : file not found"); - goto ERROR; - } - - if (S_ISREG(st.st_mode) == 0) - { - NFC_ERR("S_ISREG(st.st_mode) == 0"); - goto ERROR; - } - - handle = dlopen(path, RTLD_LAZY); - if (NULL == handle) - { - char buffer[1024]; - NFC_ERR("dlopen failed, [%d] : %s", - errno, strerror_r(errno, buffer, sizeof(buffer))); - goto ERROR; - } - - onload = dlsym(handle, "onload"); - if (NULL == onload) - { - char buffer[1024]; - NFC_ERR("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) - { - NFC_ERR("onload failed"); - goto ERROR; - } - - if (net_nfc_controller_support_nfc(&result) == false) - { - NFC_ERR("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 (NULL == dirp) - { - NFC_ERR("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) - { - NFC_DBG("loaded default plugin : %s", NET_NFC_DEFAULT_PLUGIN); - return handle; - } - else - { - NFC_ERR("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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - return false; - } -} - -bool net_nfc_controller_deinit(void) -{ - if (g_interface.deinit != NULL) - { - return g_interface.deinit(); - } - else - { - NFC_ERR("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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - return false; - } -} - -bool net_nfc_controller_unregister_listener() -{ - if (g_interface.unregister_listener != NULL) - { - return g_interface.unregister_listener(); - } - else - { - NFC_ERR("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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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); - - NFC_DBG("pm_lock_state [%d]!!", ret_val); - - if (g_interface.secure_element_open != NULL) - { - return g_interface.secure_element_open(element_type, handle, result); - } - else - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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); - NFC_DBG("pm_unlock_state [%d]!!", ret_val); - - if (g_interface.secure_element_close != NULL) - { - return g_interface.secure_element_close(handle, result); - } - else - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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); - - NFC_DBG("net_nfc_controller_connect pm_lock_state [%d]!!", ret_val); - - if (g_interface.connect != NULL) - { - return g_interface.connect(handle, result); - } - else - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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); - - NFC_ERR("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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - return false; - } -} - -bool net_nfc_controller_exception_handler() -{ - if (g_interface.exception_handler != NULL) - { - return g_interface.exception_handler(); - } - else - { - NFC_ERR("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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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; -} - -static socket_info_t* _get_socket_info(net_nfc_llcp_socket_t socket) -{ - GSList *item; - socket_info_t *result; - - 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; -} - -static socket_info_t* _add_socket_info(net_nfc_llcp_socket_t socket) -{ - socket_info_t *result; - - _net_nfc_util_alloc_mem(result, sizeof(socket_info_t)); - 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 (NULL == info) - { - NFC_ERR("_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 (true == ret) - { - info->socket = *socket; - info->err_cb = cb; - info->err_param = user_param; - } - else - { - _remove_socket_info(-1); - } - - return ret; - } - else - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("_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 (NULL == info) - { - NFC_ERR("_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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 (NULL == info) - { - NFC_ERR("_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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 (true == ret) - _remove_socket_info(socket); - - return ret; - } - else - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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; - - RET_IF(NULL == param); - - 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); - - NFC_DBG("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 (NULL == param) - { - NFC_ERR("_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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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); - - NFC_DBG("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) { - NFC_ERR("_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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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; - - RET_IF(NULL == param); - - 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); - - NFC_DBG("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(net_nfc_llcp_param_t)); - if (NULL == param) - { - NFC_ERR("_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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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; - - RET_IF(NULL == param); - - 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 (NULL == param) - { - NFC_ERR("_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) - { - NFC_ERR("_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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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; - - RET_IF(NULL == param); - - 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 (NULL == param) - { - NFC_ERR("_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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 (NULL == param) - { - NFC_ERR("_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 (NULL == param->data.buffer) - { - NFC_ERR("_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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 (NULL == param) - { - NFC_ERR("_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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - 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 - { - NFC_ERR("interface is null"); - *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; - return false; - } -} diff --git a/daemon/net_nfc_server_controller.h b/daemon/net_nfc_server_controller.h deleted file mode 100644 index 9e8f4c6..0000000 --- a/daemon/net_nfc_server_controller.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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); - -#endif //__NET_NFC_SERVER_CONTROLLER_H__ diff --git a/daemon/net_nfc_server_handover.c b/daemon/net_nfc_server_handover.c deleted file mode 100644 index fafc6b0..0000000 --- a/daemon/net_nfc_server_handover.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_server_controller.h" -#include "net_nfc_server_common.h" -#include "net_nfc_server_context.h" -#include "net_nfc_server_handover.h" -#include "net_nfc_server_process_handover.h" - -static NetNfcGDbusHandover *handover_skeleton = NULL; - -static void handover_request_thread_func(gpointer user_data) -{ - net_nfc_error_e result; - HandoverRequestData *handover_data = user_data; - - g_assert(handover_data != NULL); - g_assert(handover_data->handoverobj != NULL); - g_assert(handover_data->invocation != NULL); - - result = net_nfc_server_handover_default_client_start( - GUINT_TO_POINTER(handover_data->handle), (void *)handover_data); - if (result != NET_NFC_OK) - { - net_nfc_gdbus_handover_complete_request( - handover_data->handoverobj, - handover_data->invocation, - result, - NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, - net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); - - 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) -{ - gboolean result; - HandoverRequestData *data; - - NFC_INFO(">>> 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) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(HandoverRequestData,1); - if(NULL == data) - { - NFC_ERR("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->invocation = g_object_ref(invocation); - data->handle = arg_handle; - data->type = arg_type; - - result = net_nfc_server_controller_async_queue_push( - handover_request_thread_func, data); - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Handover.ThreadError", - "can not push to controller thread"); - - g_object_unref(data->invocation); - g_object_unref(data->handoverobj); - - g_free(data); - } - - return result; -} - -gboolean net_nfc_server_handover_init(GDBusConnection *connection) -{ - gboolean ret; - 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); - - ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(handover_skeleton), - connection, "/org/tizen/NetNfcService/Handover", &error); - - if (FALSE == ret) - { - 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; - } -} diff --git a/daemon/net_nfc_server_handover.h b/daemon/net_nfc_server_handover.h deleted file mode 100644 index 0620d6c..0000000 --- a/daemon/net_nfc_server_handover.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 -#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__ diff --git a/daemon/net_nfc_server_handover_bss.c b/daemon/net_nfc_server_handover_bss.c deleted file mode 100755 index 11d52d7..0000000 --- a/daemon/net_nfc_server_handover_bss.c +++ /dev/null @@ -1,1081 +0,0 @@ -/* - * 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 - -#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" -#include - -static gboolean _net_nfc_handover_bss_process_carrier_record( - gpointer user_data); - -static void _net_nfc_handover_bss_get_carrier_record( - net_nfc_handover_bss_create_context_t *context); - -static net_nfc_error_e _net_nfc_handover_bss_create_carrier_record( - ndef_record_s **record); - -#ifdef TARGET -static net_nfc_error_e _net_nfc_handover_bss_create_config_record( - ndef_record_s **record); - -static int _net_nfc_handover_process_wifi_direct_setup( - net_nfc_handover_bss_get_context_t *context); - -static gboolean _net_nfc_handover_bss_wfd_get_carrier_record( - net_nfc_handover_bss_get_context_t *context); - -static void _net_nfc_wifi_process_error( - int error, - net_nfc_handover_bss_get_context_t *context); - -static int _net_nfc_handover_process_wifi_group_setup( - net_nfc_handover_bss_get_context_t *context); - -#endif - - -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: - NFC_ERR("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: - NFC_ERR("Invalid Encryption type"); - retval = 0; - } - return retval; -} - -wifi_ap_h _net_nfc_handover_bss_create_ap(net_nfc_carrier_config_s *config) -{ - int err = WIFI_ERROR_NONE; - data_s temp = { NULL, 0 }; - wifi_ap_h ap_handle = NULL; - - // Sets SSID - err = net_nfc_util_get_carrier_config_property(config, - NET_NFC_WIFI_ATTRIBUTE_SSID,(uint16_t *)&temp.length, &temp.buffer); - - NFC_DBG("SSID = [%s] err %d",temp.buffer, err); - - err = wifi_ap_create((char*)temp.buffer, &ap_handle); - if(err != WIFI_ERROR_NONE) - { - NFC_ERR("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]; - - NFC_DBG("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) - { - NFC_ERR("set security type failed"); - goto error; - } - } - else - { - NFC_ERR("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) - { - NFC_ERR("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]; - NFC_DBG("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 - { - NFC_ERR("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(NULL == context) - { - NFC_ERR("Invalid context"); - return; - } - if (WIFI_ERROR_NONE == errorCode) - { - NFC_ERR("WIFI activated succesfully"); - context->result = NET_NFC_OK; - } - else - { - NFC_ERR("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) -{ - char* essid = NULL; - int err = WIFI_ERROR_NONE; - data_s temp_ssid = { NULL, 0 }; - net_nfc_handover_bss_process_context_t *context = user_data; - - if(NULL == context) - { - NFC_ERR("Invalid 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) - { - NFC_ERR("Wifi get carrier config failed"); - context->result = NET_NFC_OPERATION_FAIL; - context->step = NET_NFC_LLCP_STEP_RETURN; - g_idle_add(_net_nfc_handover_bss_process_carrier_record, context); - return false; - } - - wifi_ap_get_essid(ap_handle, &essid); - - NFC_DBG("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 error_code, void* user_data) -{ - net_nfc_handover_bss_process_context_t *context = user_data; - - if(NULL == context) - { - NFC_ERR("Invalid context"); - return; - } - if(error_code != WIFI_ERROR_NONE) - { - NFC_ERR("Wifi scan failed"); - context->result = NET_NFC_OPERATION_FAIL; - context->step = NET_NFC_LLCP_STEP_RETURN; - g_idle_add(_net_nfc_handover_bss_process_carrier_record, context); - } - else - { - context->result = NET_NFC_OK; - context->step = NET_NFC_LLCP_STEP_02; - - } -} - -void _net_nfc_handover_bss_on_wifi_scan_completed(wifi_error_e error_code, - void* user_data) -{ - int err = WIFI_ERROR_NONE; - net_nfc_handover_bss_process_context_t *context = user_data; - - if(error_code != WIFI_ERROR_NONE) - { - NFC_ERR("Wifi scan failed"); - context->result = NET_NFC_OPERATION_FAIL; - context->step = NET_NFC_LLCP_STEP_RETURN; - g_idle_add(_net_nfc_handover_bss_process_carrier_record, 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) - { - NFC_ERR("wifi_foreach_found_aps failed Err[%x]",err); - context->result = NET_NFC_OPERATION_FAIL; - context->step = NET_NFC_LLCP_STEP_RETURN; - g_idle_add(_net_nfc_handover_bss_process_carrier_record, context); - } - if(NULL == context->ap_handle) - { - wifi_security_type_e sec_type; - wifi_encryption_type_e enc_type; - - context->ap_handle = _net_nfc_handover_bss_create_ap(context->config); - - wifi_ap_get_encryption_type(context->ap_handle, &enc_type); - NFC_DBG("Encryption type %x",enc_type); - - wifi_ap_get_security_type(context->ap_handle, &sec_type); - NFC_DBG("Authentication type %x", sec_type); - } - else - { - data_s temp = { NULL, 0 }; - wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE; - wifi_encryption_type_e enc_type = WIFI_ENCRYPTION_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); - - NFC_ERR("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); - NFC_DBG("Encryption type %x",enc_type); - wifi_ap_get_security_type(context->ap_handle, &sec_type); - NFC_DBG("Authentication type %x", sec_type); - } - context->step = NET_NFC_LLCP_STEP_03; - g_idle_add(_net_nfc_handover_bss_process_carrier_record, context); - - } - -} - -void _net_nfc_handover_bss_on_wifi_connected(wifi_error_e error_code, void* user_data) -{ - net_nfc_handover_bss_process_context_t *context = user_data; - - if(NULL == context) - { - NFC_ERR("Invalid context"); - return; - } - - if(WIFI_ERROR_NONE == error_code) - { - NFC_ERR("WIFI Connected succesfully"); - context->result = NET_NFC_OK; - } - else - { - NFC_ERR("Failed to connect WIFI"); - context->result = NET_NFC_OPERATION_FAIL; - } - - context->step = NET_NFC_LLCP_STEP_RETURN; - g_idle_add(_net_nfc_handover_bss_process_carrier_record,context); -} - -static gboolean _net_nfc_handover_bss_process_carrier_record( - gpointer user_data) -{ - NFC_DBG("[%s:%d] START", __func__, __LINE__); - - net_nfc_handover_bss_process_context_t *context = user_data; - - if(NULL == context) - { - NFC_ERR("Invalid context"); - NFC_ERR("Handover Failed"); - return FALSE; - } - - if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY) - { - NFC_ERR("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; - NFC_DBG("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 */ - NFC_DBG("Wifi is enabled already, go next step"); - context->result = NET_NFC_OK; - context->step = NET_NFC_LLCP_STEP_02; - g_idle_add(_net_nfc_handover_bss_process_carrier_record, context); - } - } - else - { - NFC_ERR("Wifi init failed"); - context->result = NET_NFC_OPERATION_FAIL; - context->step = NET_NFC_LLCP_STEP_RETURN; - g_idle_add(_net_nfc_handover_bss_process_carrier_record, context); - } - } - break; - - case NET_NFC_LLCP_STEP_02: - { - - int err = WIFI_ERROR_NONE; - NFC_DBG("STEP [2]"); - err = wifi_scan(_net_nfc_handover_bss_on_wifi_scan_completed, context); - if(err != WIFI_ERROR_NONE) - { - NFC_ERR("Wifi scan failed"); - context->result = NET_NFC_OPERATION_FAIL; - context->step = NET_NFC_LLCP_STEP_RETURN; - g_idle_add(_net_nfc_handover_bss_process_carrier_record, context); - } - } - - break; - case NET_NFC_LLCP_STEP_03 : - { - NFC_DBG("Connect with WIFI"); - int err = wifi_connect(context->ap_handle, - _net_nfc_handover_bss_on_wifi_connected, context); - NFC_DBG("Connect with WIFI err [%x]",err); - if(err != WIFI_ERROR_NONE) - { - NFC_ERR("Wifi Connect failed"); - context->result = NET_NFC_OPERATION_FAIL; - context->step = NET_NFC_LLCP_STEP_RETURN; - g_idle_add(_net_nfc_handover_bss_process_carrier_record, context); - } - } - break; - case NET_NFC_LLCP_STEP_RETURN : - { - NFC_DBG("STEP return"); - if(NET_NFC_OK == context->result) - { - NFC_DBG("Handover completed succesfully"); - } - else - { - NFC_ERR("Handover Failed"); - } - wifi_deinitialize(); - context->cb(context->result, NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS, - NULL, context->user_param); - } - 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(_net_nfc_handover_bss_process_carrier_record, context); - } - else - { - result = NET_NFC_ALLOC_FAIL; - } - return result; -} - -#ifdef TARGET -void -_net_nfc_wifi_direct_power_changed(int err, wifi_direct_device_state_e device_state, void* user_data) -{ - - if(device_state == WIFI_DIRECT_DEVICE_STATE_ACTIVATED && err == WIFI_DIRECT_ERROR_NONE) - { - int err = wifi_direct_start_discovery(true, 0); - NFC_DBG("wifi direct is enabled %d",err); - } - else - { - NFC_ERR("wifi direct power state error"); - net_nfc_handover_bss_create_context_t* context = - (net_nfc_handover_bss_create_context_t*)user_data; - - context->step = NET_NFC_LLCP_STEP_RETURN; - context->result = NET_NFC_OPERATION_FAIL; - g_idle_add((GSourceFunc)_net_nfc_handover_bss_wfd_get_carrier_record, - (gpointer)context); - } -} - -void -_net_nfc_wifi_scan_completed_cb(int err, wifi_direct_discovery_state_e discovery_state, void* user_data) -{ - - net_nfc_handover_bss_create_context_t* context = - (net_nfc_handover_bss_create_context_t*) user_data; - - if(discovery_state == WIFI_DIRECT_ONLY_LISTEN_STARTED && err == WIFI_DIRECT_ERROR_NONE) - { - g_idle_add((GSourceFunc)_net_nfc_handover_bss_wfd_get_carrier_record, - (gpointer)context); - } - else - { - NFC_ERR("wifi scan error"); - context->step = NET_NFC_LLCP_STEP_RETURN; - context->result = NET_NFC_OPERATION_FAIL; - g_idle_add((GSourceFunc)_net_nfc_handover_bss_wfd_get_carrier_record, - (gpointer)context); - } - -} - -void -_net_nfc_wifi_direct_connection_changed(wifi_direct_error_e error_code, - wifi_direct_connection_state_e connection_state, - const char* mac_address, - void *user_data) -{ - - net_nfc_handover_bss_create_context_t* context = - (net_nfc_handover_bss_create_context_t*) user_data; - - if(connection_state == WIFI_DIRECT_GROUP_CREATED - && error_code == WIFI_DIRECT_ERROR_NONE) - { - g_idle_add((GSourceFunc)_net_nfc_handover_bss_wfd_get_carrier_record, - (gpointer)context); - } - else - { - NFC_ERR("_net_nfc_wifi_direct_connection_changed failed" - "[%d] [%d]",error_code,connection_state); - - context->step = NET_NFC_LLCP_STEP_RETURN; - context->result = NET_NFC_OPERATION_FAIL; - g_idle_add((GSourceFunc)_net_nfc_handover_bss_wfd_get_carrier_record, - (gpointer)context); - } -} - -#endif - -static net_nfc_error_e _net_nfc_handover_bss_create_carrier_record( - ndef_record_s **record) -{ - net_nfc_error_e result; - - result = net_nfc_util_create_handover_carrier_record(record); - - if (NET_NFC_OK == result) - NFC_ERR("net_nfc_util_create_ndef_record_with_carrier_config [%d]",result); - else - NFC_ERR("net_nfc_util_create_carrier_config failed [%d]", result); - - return result; -} - - -#ifdef TARGET -/*TO DO : This is a work around and needs to be replaced by WIFI-DIRECT API*/ -static int _net_nfc_handover_getpassword(uint8_t** password ) -{ - - char data[256]; - int ret_val; - - ret_val = system("wpa_cli -g /var/run/wpa_supplicant/p2p-wlan0-0 p2p_get_passphrase " - "> /tmp/nfc_p2p_passphrase.txt"); - - NFC_INFO("system command returned with [%d]",ret_val); - - FILE *f = fopen("/tmp/nfc_p2p_passphrase.txt","r"); - if(f != NULL) - { - int cnt; - int readlength; - readlength = fread(data, 1 , 255, f); - for(cnt = 0; cnt < readlength; cnt++) - { - if(data[cnt] == '\n') - { - break; - } - } - _net_nfc_util_alloc_mem(*password,(readlength - cnt)+1); - memcpy(*password, &data[cnt+1], (readlength - cnt)); - fclose(f); - return (readlength-cnt); - } - else - return 0; -} - - -static net_nfc_error_e _net_nfc_handover_bss_create_config_record( - ndef_record_s **record) -{ - int pw_length = 0; - char* ssid = NULL; - net_nfc_error_e result; - char* mac_address = NULL; - data_s enc_type = {NULL,0}; - data_s mac_data = {NULL,0}; - data_s ssid_data = {NULL,0}; - data_s auth_data = {NULL,0}; - data_s version_data = {NULL,0}; - data_s net_index_data = {NULL,0}; - net_nfc_carrier_config_s *config = NULL; - net_nfc_carrier_property_s *cred_config = NULL; - -#if 0 - char *passphrase = NULL; -#else - uint8_t *password = NULL; -#endif - - - _net_nfc_util_alloc_mem(version_data.buffer,1); - if(version_data.buffer) - { - version_data.length = 1; - *version_data.buffer = 0x01; - - result = net_nfc_util_create_carrier_config(&config, - NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS); - - if (NET_NFC_OK == result) - { - result = net_nfc_util_add_carrier_config_property( - config, - NET_NFC_WIFI_ATTRIBUTE_VERSION, - version_data.length, version_data.buffer); - - if (result != NET_NFC_OK) - { - NFC_ERR("net_nfc_util_add_carrier_config_property failed" - "[%d]", result); - } - } - - _net_nfc_util_free_mem(version_data.buffer); - } - - result = net_nfc_util_create_carrier_config_group(&cred_config, - NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL); - - if (NET_NFC_OK == result) - { - _net_nfc_util_alloc_mem(net_index_data.buffer,1); - if(net_index_data.buffer) - { - net_index_data.length = 1; - *net_index_data.buffer = 1; - - - net_nfc_util_add_carrier_config_group_property( - cred_config, - NET_NFC_WIFI_ATTRIBUTE_NET_INDEX, - net_index_data.length, net_index_data.buffer); - - _net_nfc_util_free_mem(net_index_data.buffer); - } - - wifi_direct_get_ssid(&ssid); - - _net_nfc_util_alloc_mem(ssid_data.buffer,strlen(ssid)+2); - if(ssid_data.buffer) - { - ssid_data.length = strlen(ssid); - memcpy(ssid_data.buffer,ssid, strlen(ssid)); - - net_nfc_util_add_carrier_config_group_property( - cred_config, - NET_NFC_WIFI_ATTRIBUTE_SSID, - ssid_data.length, ssid_data.buffer); - - _net_nfc_util_free_mem(version_data.buffer); - } - - _net_nfc_util_alloc_mem(auth_data.buffer,2); - if(auth_data.buffer) - { - auth_data.length = 1; - *auth_data.buffer = 20; - - net_nfc_util_add_carrier_config_group_property( - cred_config, - NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE, - auth_data.length, auth_data.buffer); - - _net_nfc_util_free_mem(auth_data.buffer); - } - - _net_nfc_util_alloc_mem(enc_type.buffer,2); - if(enc_type.buffer) - { - enc_type.length = 1; - *enc_type.buffer = 8; - - net_nfc_util_add_carrier_config_group_property( - cred_config, - NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE, - enc_type.length, enc_type.buffer); - - _net_nfc_util_free_mem(enc_type.buffer); - } - /*TO DO : This is a work around,to be replaced by WIFI-DIRECT API*/ -#if 0 - pw_length = wifi_direct_get_passphrase(&passphrase); - NFC_DBG("wifi_direct_get_passphrase[%s]", passphrase); -#else - pw_length = _net_nfc_handover_getpassword(&password); - NFC_DBG("_net_nfc_handover_getpassword[%s]", password); -#endif - - net_nfc_util_add_carrier_config_group_property( - cred_config, - NET_NFC_WIFI_ATTRIBUTE_NET_KEY, - pw_length, password); - - _net_nfc_util_free_mem(password); - - wifi_direct_get_mac_address(&mac_address); - - _net_nfc_util_alloc_mem(mac_data.buffer,strlen(mac_address)+2); - if(mac_data.buffer) - { - mac_data.length = strlen(mac_address); - memcpy(mac_data.buffer,mac_address,strlen(mac_address)); - - if ((result = net_nfc_util_add_carrier_config_group_property( - cred_config, - NET_NFC_WIFI_ATTRIBUTE_MAC_ADDR, - mac_data.length, mac_data.buffer)) != NET_NFC_OK) - { - NFC_ERR("net_nfc_util_add_carrier" - "_config_property failed" - "[%d]", result); - } - } - - _net_nfc_util_free_mem(mac_data.buffer); - - } - net_nfc_util_append_carrier_config_group(config, cred_config); - - result = net_nfc_util_create_ndef_record_with_carrier_config(record, config); - - if (result != NET_NFC_OK) - { - NFC_ERR("net_nfc_util_create_ndef_record_with_carrier_config failed [%d]",result); - } - - return result; -} -#endif - - -static void _net_nfc_handover_bss_get_carrier_record( - net_nfc_handover_bss_create_context_t *context) -{ - LOGD("[%s:%d] START", __func__, __LINE__); - - if(context != NULL) - { - if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY) - NFC_ERR("context->result is error [%d]", context->result); - - context->result = NET_NFC_OK; - context->cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE; - - /* Create carrier record */ - context->result =_net_nfc_handover_bss_create_carrier_record(&context->carrier); - - if (context->result!= NET_NFC_OK) - NFC_ERR("create_bss_config_record failed [%d]", context->result); - - /* complete and return to upper step */ - context->cb(context->result, context->cps, context->carrier, 0, NULL, - context->user_param); - } -} - -#ifdef TARGET -static void _net_nfc_wifi_process_error(int error, - net_nfc_handover_bss_get_context_t *context) -{ - NFC_ERR("_net_nfc_wifi_process_error - [%d]",error); - - context->step = NET_NFC_LLCP_STEP_RETURN; - context->result = NET_NFC_OPERATION_FAIL; - - g_idle_add((GSourceFunc)_net_nfc_handover_bss_wfd_get_carrier_record, - (gpointer)context); - - return; -} - -static int _net_nfc_handover_process_wifi_direct_setup( - net_nfc_handover_bss_get_context_t *context) -{ - int err = WIFI_DIRECT_ERROR_NONE; - err = wifi_direct_initialize(); - if(err != WIFI_DIRECT_ERROR_NONE) - { - NFC_ERR("wifi_direct_initialize err value %d",err); - return err; - } - - err = wifi_direct_set_device_state_changed_cb(_net_nfc_wifi_direct_power_changed, - context); - - if(err != WIFI_DIRECT_ERROR_NONE) - { - NFC_ERR("wifi_direct_set_device_state_changed_cb err value %d",err); - return err; - } - - err = wifi_direct_set_discovery_state_changed_cb(_net_nfc_wifi_scan_completed_cb, - context); - - if(err != WIFI_DIRECT_ERROR_NONE) - { - NFC_ERR("wifi_direct_set_discovery_state_changed_cb err value %d",err); - return err; - } - - err = wifi_direct_set_connection_state_changed_cb( - _net_nfc_wifi_direct_connection_changed, context); - - if (err != WIFI_DIRECT_ERROR_NONE) - { - NFC_ERR("wifi_direct_set_connection_state_changed_cb err value %d",err); - return err; - } - else - { - context->step = NET_NFC_LLCP_STEP_02; - context->result = NET_NFC_OK; - - wifi_direct_state_e status = WIFI_DIRECT_STATE_DEACTIVATED; - - err = wifi_direct_get_state(&status); - NFC_ERR("status value %d",status); - - if (status != WIFI_DIRECT_STATE_ACTIVATED) - { - wifi_direct_activate(); - } - else - { - NFC_DBG("wifi direct is enabled already"); - - /* do next step */ - g_idle_add((GSourceFunc)_net_nfc_handover_bss_wfd_get_carrier_record, - (gpointer)context); - } - return WIFI_DIRECT_ERROR_NONE; - - } -} - -static int _net_nfc_handover_process_wifi_group_setup( - net_nfc_handover_bss_get_context_t *context) -{ - int err = WIFI_DIRECT_ERROR_NONE; - bool group_owner = false; - - err = wifi_direct_is_group_owner(&group_owner); - NFC_ERR("error value %d",err); - - context->step = NET_NFC_LLCP_STEP_03; - context->result = NET_NFC_OK; - - if(WIFI_DIRECT_ERROR_NONE == err) - { - if(true == group_owner) - { - NFC_DBG("Already group owner, continue next step"); - g_idle_add((GSourceFunc)_net_nfc_handover_bss_wfd_get_carrier_record, - (gpointer)context); - } - else - { - err = wifi_direct_create_group(); - if (err != WIFI_DIRECT_ERROR_NONE) - { - NFC_ERR("wifi_direct_create_group failed [%d]",err); - return err; - } - } - } - else - { - NFC_ERR("wifi_direct_is_group_owner failed [%d]",err); - return err; - } - - return err; -} - -static gboolean _net_nfc_handover_bss_wfd_get_carrier_record( - net_nfc_handover_bss_get_context_t *context) -{ - LOGD("[%s:%d] START", __func__, __LINE__); - if(NULL == context) - { - NFC_ERR("Invalid context"); - return FALSE; - } - - if(context != NULL) - { - int err = WIFI_DIRECT_ERROR_NONE; - - if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY) - { - NFC_ERR("context->result is error [%d]", context->result); - - context->step = NET_NFC_LLCP_STEP_RETURN; - } - - switch (context->step) - { - case NET_NFC_LLCP_STEP_01 : - NFC_ERR("NET_NFC_LLCP_STEP_01"); - err = _net_nfc_handover_process_wifi_direct_setup(context); - if(err != WIFI_DIRECT_ERROR_NONE) - { - NFC_ERR("_net_nfc_handover_process_wifi_direct_setup failed"); - _net_nfc_wifi_process_error(err,context); - } - break; - case NET_NFC_LLCP_STEP_02: - NFC_ERR("NET_NFC_LLCP_STEP_02"); - err = _net_nfc_handover_process_wifi_group_setup(context); - if(err != WIFI_DIRECT_ERROR_NONE) - { - NFC_ERR("_net_nfc_handover_process_wifi_group_setup failed"); - _net_nfc_wifi_process_error(err,context); - } - break; - case NET_NFC_LLCP_STEP_03 : - NFC_ERR("NET_NFC_LLCP_STEP_03"); - context->step = NET_NFC_LLCP_STEP_RETURN; - - /* append config to ndef message */ - context->result =_net_nfc_handover_bss_create_config_record(&context->carrier); - if (context->result != NET_NFC_OK) - { - NFC_ERR("_net_nfc_handover_bss_create_config_record failed" - "[%d]", context->result); - } - - g_idle_add((GSourceFunc)_net_nfc_handover_bss_wfd_get_carrier_record, - (gpointer)context); - - break; - case NET_NFC_LLCP_STEP_RETURN : - NFC_ERR("NET_NFC_LLCP_STEP_RETURN"); - /* unregister current callback */ - wifi_direct_unset_connection_state_changed_cb(); - wifi_direct_unset_device_state_changed_cb(); - wifi_direct_unset_discovery_state_changed_cb(); - wifi_direct_deinitialize(); - - /* 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 TRUE; -} -#endif - -net_nfc_error_e net_nfc_server_handover_bss_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_bss_create_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_handover_bss_get_carrier_record(context); - } - else - { - result = NET_NFC_ALLOC_FAIL; - } - - return result; -} - -#ifdef TARGET -net_nfc_error_e net_nfc_server_handover_bss_wfd_get_carrier_record( - net_nfc_server_handover_get_carrier_record_cb cb, void *user_param) -{ - net_nfc_handover_bss_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; - context->cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE; - - g_idle_add((GSourceFunc)_net_nfc_handover_bss_wfd_get_carrier_record, - (gpointer)context); - - return NET_NFC_OK; - } - else - { - return NET_NFC_ALLOC_FAIL; - } - -} -#endif diff --git a/daemon/net_nfc_server_handover_bss.h b/daemon/net_nfc_server_handover_bss.h deleted file mode 100755 index 33fbe17..0000000 --- a/daemon/net_nfc_server_handover_bss.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 -#ifdef TARGET -#include -#endif - -#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); -net_nfc_error_e net_nfc_server_handover_bss_get_carrier_record( - net_nfc_server_handover_get_carrier_record_cb cb, - void *user_param); -typedef struct _net_nfc_handover_bss_create_context_t -{ - int step; - net_nfc_error_e result; - net_nfc_server_handover_get_carrier_record_cb cb; - net_nfc_conn_handover_carrier_state_e cps; - 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_create_context_t; - -typedef struct _net_nfc_handover_bss_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_bss_get_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); - -#ifdef TARGET -net_nfc_error_e net_nfc_server_handover_bss_wfd_get_carrier_record( - net_nfc_server_handover_get_carrier_record_cb cb, - void *user_param); -#endif -#endif //__NET_NFC_SERVER_HANDOVER_BSS_H__ diff --git a/daemon/net_nfc_server_handover_bt.c b/daemon/net_nfc_server_handover_bt.c deleted file mode 100755 index d5385ba..0000000 --- a/daemon/net_nfc_server_handover_bt.c +++ /dev/null @@ -1,769 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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) -{ - data_s hash = { NULL, 0 }; - data_s randomizer = { NULL, 0 }; - net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; - - LOGD("[%s:%d] START", __func__, __LINE__); - - RETV_IF(NULL == oob, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == config, NET_NFC_NULL_PARAMETER); - - memset(oob, 0, sizeof(bt_oob_data_t)); - - result = net_nfc_util_get_carrier_config_property( - config, - NET_NFC_BT_ATTRIBUTE_OOB_HASH_C, - (uint16_t *)&hash.length, - &hash.buffer); - - if (NET_NFC_OK == result) - { - if (hash.length == 16) - { - NFC_DBG("hash.length == 16"); - - net_nfc_convert_byte_order(hash.buffer, 16); - - oob->hash_len = MIN(sizeof(oob->hash), hash.length); - memcpy(oob->hash, hash.buffer, oob->hash_len); - } - else - { - NFC_ERR("hash.length error : [%d] bytes", hash.length); - } - } - - result = net_nfc_util_get_carrier_config_property( - config, - NET_NFC_BT_ATTRIBUTE_OOB_HASH_R, - (uint16_t *)&randomizer.length, - &randomizer.buffer); - - if (NET_NFC_OK == result) - { - if (randomizer.length == 16) - { - NFC_DBG("randomizer.length == 16"); - - net_nfc_convert_byte_order(randomizer.buffer, 16); - - oob->randomizer_len = MIN(sizeof(oob->randomizer), randomizer.length); - memcpy(oob->randomizer, randomizer.buffer, oob->randomizer_len); - } - else - { - NFC_ERR("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; - - if (context == NULL) - { - NFC_ERR("user_data is null"); - return; - } - - switch (event) - { - case BLUETOOTH_EVENT_ENABLED : - NFC_DBG("BLUETOOTH_EVENT_ENABLED"); - if (context->step == NET_NFC_LLCP_STEP_02) - { - _net_nfc_handover_bt_get_carrier_record(context); - } - else - { - NFC_ERR("step is incorrect"); - } - break; - - case BLUETOOTH_EVENT_DISABLED : - NFC_DBG("BLUETOOTH_EVENT_DISABLED"); - break; - - default : - NFC_ERR("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_convert_byte_order(bt_addr.addr, 6); - - 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) - { - NFC_ERR("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) - { - NFC_DBG("oob.hash_len [%d]", oob.hash_len); - NFC_DBG("oob.randomizer_len [%d]", oob.randomizer_len); - - net_nfc_convert_byte_order(oob.hash, 16); - - 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) - { - NFC_ERR("net_nfc_util_add_carrier" - "_config_property failed" - " [%d]",result); - } - - net_nfc_convert_byte_order(oob.randomizer, 16); - - 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) - { - NFC_ERR("net_nfc_util_add_carrier" - "_config_property failed" - " [%d]",result); - } - } - else - { - NFC_ERR("abnormal oob data, skip... [%d]", result); - } - } - - if ((result = net_nfc_util_create_ndef_record_with_carrier_config( - record, - config)) != NET_NFC_OK) - { - NFC_ERR("net_nfc_util_create_ndef_record" - "_with_carrier_config failed" - "[%d]",result); - } - - net_nfc_util_free_carrier_config(config); - } - else - { - NFC_ERR("net_nfc_util_create_carrier_config failed " - "[%d]", result); - } - } - else - { - NFC_ERR("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) - { - NFC_ERR("context->result is error" - " [%d]", context->result); - - context->step = NET_NFC_LLCP_STEP_RETURN; - } - - switch (context->step) - { - case NET_NFC_LLCP_STEP_01 : - NFC_DBG("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 - { - NFC_DBG("bluetooth is enabled already"); - - /* do next step */ - g_idle_add((GSourceFunc) - _net_nfc_handover_bt_get_carrier_record, - (gpointer)context); - } - } - else - { - NFC_ERR("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 : - NFC_DBG("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) - { - NFC_ERR("_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 : - NFC_DBG("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; - - NFC_DBG("g pointer array count : [%d]", devinfo->len); - - for (i = 0; i < devinfo->len; i++) - { - ptr = g_ptr_array_index(devinfo, i); - if (ptr != NULL) - { - NFC_SECURE_DBG("Name [%s]", ptr->device_name.name); - NFC_DBG("Major Class [%d]", ptr->device_class.major_class); - NFC_DBG("Minor Class [%d]", ptr->device_class.minor_class); - NFC_DBG("Service Class [%d]", ptr->device_class.service_class); - NFC_DBG("%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) - { - NFC_DBG("Found!!!"); - result = true; - break; - } - } - } - } - else - { - NFC_ERR("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; - - if (context == NULL) - { - NFC_ERR("user_data is null"); - return; - } - - switch (event) - { - case BLUETOOTH_EVENT_ENABLED : - NFC_DBG("BLUETOOTH_EVENT_ENABLED"); - if (context->step == NET_NFC_LLCP_STEP_02) - { - _net_nfc_handover_bt_process_carrier_record(context); - } - else - { - NFC_ERR("step is incorrect"); - } - break; - - case BLUETOOTH_EVENT_DISABLED : - NFC_DBG("BLUETOOTH_EVENT_DISABLED"); - break; - - case BLUETOOTH_EVENT_BONDING_FINISHED : - NFC_DBG("BLUETOOTH_EVENT_BONDING_FINISHED, result [0x%04x]", param->result); - if (context->step == NET_NFC_LLCP_STEP_03) - { - if (param->result < BLUETOOTH_ERROR_NONE) - { - NFC_ERR("bond failed"); - context->result = NET_NFC_OPERATION_FAIL; - } - - _net_nfc_handover_bt_process_carrier_record(context); - } - else - { - NFC_ERR("step is incorrect"); - } - break; - - default : - NFC_ERR("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) - { - NFC_ERR("context->result is error" - " [%d]", context->result); - context->step = NET_NFC_LLCP_STEP_RETURN; - } - - switch (context->step) - { - case NET_NFC_LLCP_STEP_01 : - NFC_DBG("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 */ - NFC_DBG("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 - { - NFC_ERR("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 }; - - NFC_DBG("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_convert_byte_order(temp.buffer, 6); - - memcpy(context->addr.addr, - temp.buffer, - MIN(sizeof(context->addr.addr), - temp.length)); - - if (_net_nfc_handover_bt_check_bond_device - (&context->addr) == true) - { - NFC_DBG("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 - { - NFC_ERR("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 : - { - NFC_DBG("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; - - if (context == NULL) - { - NFC_ERR("user_data is null"); - return; - } - - switch (event) - { - case BLUETOOTH_EVENT_ENABLED : - NFC_DBG("BLUETOOTH_EVENT_ENABLED"); - break; - - case BLUETOOTH_EVENT_DISABLED : - NFC_DBG("BLUETOOTH_EVENT_DISABLED"); - break; - - case BLUETOOTH_EVENT_BONDING_FINISHED : - NFC_DBG("BLUETOOTH_EVENT_BONDING_FINISHED, result [0x%04x]",param->result); - - if (param->result < BLUETOOTH_ERROR_NONE) - { - NFC_ERR("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 : - NFC_ERR("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; -} - diff --git a/daemon/net_nfc_server_handover_bt.h b/daemon/net_nfc_server_handover_bt.h deleted file mode 100644 index d10cd41..0000000 --- a/daemon/net_nfc_server_handover_bt.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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__ diff --git a/daemon/net_nfc_server_llcp.c b/daemon/net_nfc_server_llcp.c deleted file mode 100644 index 9b50ae3..0000000 --- a/daemon/net_nfc_server_llcp.c +++ /dev/null @@ -1,2427 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 /*for pm lock*/ - -#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_tag.h" -#include "net_nfc_server_llcp.h" -#include "net_nfc_server_p2p.h" -#include "net_nfc_server_process_snep.h" -#include "net_nfc_server_process_npp.h" -#include "net_nfc_server_process_handover.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 _llcp_client_data -{ - GDBusConnection *connection; - char *id; - net_nfc_target_handle_s *handle; - net_nfc_llcp_socket_t socket; - void *user_data; -} -llcp_client_data; - - -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; - guint16 miu; - guint8 rw; - guint type; - guint sap; - gchar *service_name; -}; - -typedef struct _LlcpAcceptData LlcpAcceptData; - -struct _LlcpAcceptData -{ - NetNfcGDbusLlcp *llcp; - GDBusMethodInvocation *invocation; - - guint handle; - guint client_socket; -}; - -typedef struct _LlcpConnectData LlcpConnectData; - -struct _LlcpConnectData -{ - NetNfcGDbusLlcp *llcp; - GDBusMethodInvocation *invocation; - - guint32 handle; - guint32 client_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; - guint16 miu; - guint8 rw; - guint type; - guint sap; -}; - -typedef struct _LlcpSendData LlcpSendData; - -struct _LlcpSendData -{ - NetNfcGDbusLlcp *llcp; - GDBusMethodInvocation *invocation; - - guint32 handle; - guint32 client_socket; - - data_s data; -}; - -typedef struct _LlcpSendToData LlcpSendToData; - -struct _LlcpSendToData -{ - NetNfcGDbusLlcp *llcp; - GDBusMethodInvocation *invocation; - - guint32 handle; - guint32 client_socket; - guint8 sap; - - data_s data; -}; - -typedef struct _LlcpReceiveData LlcpReceiveData; - -struct _LlcpReceiveData -{ - NetNfcGDbusLlcp *llcp; - GDBusMethodInvocation *invocation; - - guint32 handle; - guint32 client_socket; - guint32 req_length; -}; - -typedef struct _LlcpCloseData LlcpCloseData; - -struct _LlcpCloseData -{ - NetNfcGDbusLlcp *llcp; - GDBusMethodInvocation *invocation; - - guint32 handle; - guint32 client_socket; -}; - -typedef struct _LlcpDisconnectData LlcpDisconnectData; - -struct _LlcpDisconnectData -{ - NetNfcGDbusLlcp *llcp; - GDBusMethodInvocation *invocation; - - guint32 handle; - guint32 client_socket; -}; - -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_socket_error_cb(net_nfc_llcp_socket_t socket, - net_nfc_error_e result, data_s *data, void *extra, void *user_param) -{ - gboolean ret; - GError *error = NULL; - llcp_client_data *client_data = user_param; - - ret = g_dbus_connection_emit_signal( - client_data->connection, - client_data->id, - "/org/tizen/NetNfcService/Llcp", - "org.tizen.NetNfcService.Llcp", - "Error", - g_variant_new("(uui)", - GPOINTER_TO_UINT(client_data->handle), - socket, - result), - &error); - - if (FALSE == ret) - { - if (error != NULL && error->message != NULL) - NFC_ERR("g_dbus_connection_emit_signal failed : %s", error->message); - else - NFC_ERR("g_dbus_connection_emit_signal failed"); - } -} - -static void llcp_incoming_cb(net_nfc_llcp_socket_t socket, - net_nfc_error_e result, data_s *data, void *extra, void *user_param) -{ - gboolean ret; - GError *error = NULL; - llcp_client_data *client_data = user_param; - - ret = g_dbus_connection_emit_signal( - client_data->connection, - client_data->id, - "/org/tizen/NetNfcService/Llcp", - "org.tizen.NetNfcService.Llcp", - "Incoming", - g_variant_new("(uuu)", - GPOINTER_TO_UINT(client_data->handle), - client_data->socket, - socket), - &error); - - if (FALSE == ret) - { - if (error != NULL && error->message != NULL) - NFC_ERR("g_dbus_connection_emit_signal failed : %s", error->message); - else - NFC_ERR("g_dbus_connection_emit_signal failed"); - } -} - -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 = user_param; - - g_assert(llcp_data != NULL); - g_assert(llcp_data->llcp != NULL); - g_assert(llcp_data->invocation != NULL); - - net_nfc_gdbus_llcp_complete_connect(llcp_data->llcp, llcp_data->invocation, - result, socket); - - g_free(llcp_data->service_name); - - g_object_unref(llcp_data->invocation); - g_object_unref(llcp_data->llcp); - - 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 = user_param; - - g_assert(llcp_data != NULL); - g_assert(llcp_data->llcp != NULL); - g_assert(llcp_data->invocation != NULL); - - net_nfc_gdbus_llcp_complete_connect_sap(llcp_data->llcp, llcp_data->invocation, - result, 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) -{ - LlcpSendData *llcp_data = user_param; - - g_assert(llcp_data != NULL); - g_assert(llcp_data->llcp != NULL); - g_assert(llcp_data->invocation != NULL); - - net_nfc_gdbus_llcp_complete_send(llcp_data->llcp, llcp_data->invocation, - result, socket); - - net_nfc_util_free_data(&llcp_data->data); - - g_object_unref(llcp_data->invocation); - g_object_unref(llcp_data->llcp); - - g_free(llcp_data); -} - -static void llcp_send_to_cb(net_nfc_llcp_socket_t socket, - net_nfc_error_e result, data_s *data, void *extra, void *user_param) -{ - LlcpSendToData *llcp_data = user_param; - - g_assert(llcp_data != NULL); - g_assert(llcp_data->llcp != NULL); - g_assert(llcp_data->invocation != NULL); - - net_nfc_gdbus_llcp_complete_send_to(llcp_data->llcp, llcp_data->invocation, - result, socket); - - net_nfc_util_free_data(&llcp_data->data); - - 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) -{ - GVariant *variant; - LlcpReceiveData *llcp_data = user_param; - - g_assert(llcp_data != NULL); - g_assert(llcp_data->llcp != NULL); - g_assert(llcp_data->invocation != NULL); - - variant = net_nfc_util_gdbus_data_to_variant(data); - net_nfc_gdbus_llcp_complete_receive(llcp_data->llcp, llcp_data->invocation, - result, 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) -{ - GVariant *variant; - LlcpReceiveData *llcp_data = user_param; - - g_assert(llcp_data != NULL); - g_assert(llcp_data->llcp != NULL); - g_assert(llcp_data->invocation != NULL); - - variant = net_nfc_util_gdbus_data_to_variant(data); - net_nfc_gdbus_llcp_complete_receive_from(llcp_data->llcp, llcp_data->invocation, - result, (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) -{ - LlcpDisconnectData *llcp_data = user_param; - - g_assert(llcp_data != NULL); - g_assert(llcp_data->llcp != NULL); - g_assert(llcp_data->invocation != NULL); - - net_nfc_gdbus_llcp_complete_disconnect(llcp_data->llcp, llcp_data->invocation, - result, 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) -{ - net_nfc_error_e result; - LlcpConfigData *data = user_data; - net_nfc_llcp_config_info_s config; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - config.miu = data->miu; - config.wks = data->wks; - config.lto = data->lto; - config.option = data->option; - - result = net_nfc_server_llcp_set_config(&config); - - net_nfc_gdbus_llcp_complete_config(data->llcp, data->invocation, result); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); -} - -static void llcp_handle_listen_thread_func(gpointer user_data) -{ - bool ret; - net_nfc_error_e result; - llcp_client_data *client_data; - LlcpListenData *data = user_data; - net_nfc_llcp_socket_t socket = -1; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - client_data = g_try_new0(llcp_client_data, 1); - if (NULL == client_data) - { - result = NET_NFC_ALLOC_FAIL; - - goto ERROR; - } - - client_data->connection = g_dbus_method_invocation_get_connection(data->invocation); - client_data->id = g_strdup(g_dbus_method_invocation_get_sender(data->invocation)); - client_data->handle = (net_nfc_target_handle_s*)data->handle; - - ret = net_nfc_controller_llcp_create_socket(&socket, data->type, data->miu, data->rw, - &result, llcp_socket_error_cb, client_data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_create_socket failed [%d]", result); - - goto ERROR; - } - - client_data->socket = socket; - - if (net_nfc_controller_llcp_bind(socket, data->sap, &result) == false) - { - NFC_ERR("net_nfc_controller_llcp_bind failed [%d]", result); - - goto ERROR; - } - - ret = net_nfc_controller_llcp_listen(GUINT_TO_POINTER(data->handle), - (uint8_t *)data->service_name, - socket, - &result, - llcp_incoming_cb, - client_data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_listen failed [%d]", result); - - goto ERROR; - } - - net_nfc_gdbus_llcp_complete_listen(data->llcp, data->invocation, result, - GPOINTER_TO_UINT(socket)); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - - return; - -ERROR : - net_nfc_gdbus_llcp_complete_listen(data->llcp, data->invocation, result, -1); - - if (socket != -1) - net_nfc_controller_llcp_socket_close(socket, &result); - - g_free(client_data); - - g_free(data->service_name); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); -} - -static void llcp_handle_accept_thread_func(gpointer user_data) -{ - bool ret; - net_nfc_error_e result; - llcp_client_data *client_data; - LlcpAcceptData *data = user_data; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - client_data = g_try_new0(llcp_client_data, 1); - if (NULL == client_data) - { - result = NET_NFC_ALLOC_FAIL; - - goto ERROR; - } - - client_data->connection = g_dbus_method_invocation_get_connection(data->invocation); - client_data->id = g_strdup(g_dbus_method_invocation_get_sender(data->invocation)); - client_data->handle = (net_nfc_target_handle_s*)data->handle; - client_data->socket = data->client_socket; - - ret = net_nfc_controller_llcp_accept(data->client_socket, &result, - llcp_socket_error_cb, client_data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_accept failed [%d]", result); - - goto ERROR; - } - - net_nfc_gdbus_llcp_complete_accept(data->llcp, data->invocation, result); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - - return; - -ERROR : - net_nfc_gdbus_llcp_complete_accept(data->llcp, data->invocation, result); - - g_free(client_data); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); -} - -static void llcp_handle_reject_thread_func(gpointer user_data) -{ - bool ret; - net_nfc_error_e result; - LlcpAcceptData *data = user_data; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - ret = net_nfc_controller_llcp_reject(GUINT_TO_POINTER(data->handle), - data->client_socket, &result); - - if (false == ret) - NFC_ERR("net_nfc_controller_llcp_reject failed [%d]", result); - - net_nfc_gdbus_llcp_complete_reject(data->llcp, data->invocation, result); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); -} - - -static void llcp_handle_connect_thread_func(gpointer user_data) -{ - bool ret; - net_nfc_error_e result; - llcp_client_data *client_data; - LlcpConnectData *data = user_data; - net_nfc_llcp_socket_t socket = -1; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - client_data = g_try_new0(llcp_client_data, 1); - - if (NULL == client_data) - { - result = NET_NFC_ALLOC_FAIL; - - goto ERROR; - } - - client_data->connection = g_dbus_method_invocation_get_connection(data->invocation); - client_data->id = g_strdup(g_dbus_method_invocation_get_sender(data->invocation)); - client_data->handle = (net_nfc_target_handle_s*)data->handle; - - ret = net_nfc_controller_llcp_create_socket(&socket, data->type, data->miu, data->rw, - &result, llcp_socket_error_cb, client_data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_create_socket failed [%d]", result); - - goto ERROR; - } - - client_data->socket = socket; - - ret = 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); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_listen failed [%d]", result); - - goto ERROR; - } - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - - return; - -ERROR : - net_nfc_gdbus_llcp_complete_connect(data->llcp, data->invocation, result, -1); - - if (socket != -1) - net_nfc_controller_llcp_socket_close(socket, &result); - - g_free(client_data); - - g_free(data->service_name); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); -} - -static void llcp_handle_connect_sap_thread_func(gpointer user_data) -{ - bool ret; - llcp_client_data *client_data; - net_nfc_llcp_socket_t socket = -1; - net_nfc_error_e result = NET_NFC_OK; - LlcpConnectSapData *data = user_data; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - client_data = g_try_new0(llcp_client_data, 1); - if (NULL == client_data) - { - result = NET_NFC_ALLOC_FAIL; - - goto ERROR; - } - - client_data->connection = g_dbus_method_invocation_get_connection(data->invocation); - client_data->id = g_strdup(g_dbus_method_invocation_get_sender(data->invocation)); - client_data->handle = (net_nfc_target_handle_s*)data->handle; - - ret = net_nfc_controller_llcp_create_socket(&socket, data->type, data->miu, data->rw, - &result, llcp_socket_error_cb, client_data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_create_socket failed [%d]", result); - - goto ERROR; - } - - client_data->socket = socket; - - ret = net_nfc_controller_llcp_connect(GUINT_TO_POINTER(data->handle), socket, - data->sap, &result, llcp_connect_cb, data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_listen failed [%d]", result); - - goto ERROR; - } - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - - return; - -ERROR : - net_nfc_gdbus_llcp_complete_connect_sap(data->llcp, data->invocation, result, -1); - - if (socket != -1) - net_nfc_controller_llcp_socket_close(socket, &result); - - g_free(client_data); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); -} - -static void llcp_handle_send_thread_func(gpointer user_data) -{ - bool ret; - net_nfc_error_e result; - LlcpSendData *data = user_data; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - ret = net_nfc_controller_llcp_send(GUINT_TO_POINTER(data->handle), - data->client_socket, &data->data, &result, llcp_send_cb, data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_send failed [%d]", result); - - net_nfc_gdbus_llcp_complete_send(data->llcp, data->invocation, result, - data->client_socket); - - net_nfc_util_free_data(&data->data); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } -} - -static void llcp_handle_send_to_thread_func(gpointer user_data) -{ - bool ret; - net_nfc_error_e result; - LlcpSendToData *data = user_data; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - ret = net_nfc_controller_llcp_send_to(GUINT_TO_POINTER(data->handle), - data->client_socket, - &data->data, - data->sap, - &result, - llcp_send_to_cb, - data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_send_to failed [%d]", result); - - net_nfc_gdbus_llcp_complete_send_to(data->llcp, data->invocation, result, - data->client_socket); - - net_nfc_util_free_data(&data->data); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } -} - -static void llcp_handle_receive_thread_func(gpointer user_data) -{ - bool ret; - net_nfc_error_e result; - LlcpReceiveData *data = user_data; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - ret = net_nfc_controller_llcp_recv(GUINT_TO_POINTER(data->handle), - data->client_socket, - data->req_length, - &result, - llcp_receive_cb, - data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_recv failed [%d]", result); - - net_nfc_gdbus_llcp_complete_receive(data->llcp, data->invocation, result, - net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } -} - -static void llcp_handle_receive_from_thread_func(gpointer user_data) -{ - bool ret; - net_nfc_error_e result; - LlcpReceiveData *data = user_data; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - ret = net_nfc_controller_llcp_recv_from(GUINT_TO_POINTER(data->handle), - data->client_socket, - data->req_length, - &result, - llcp_receive_from_cb, - data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_recv_from failed [%d]", result); - - net_nfc_gdbus_llcp_complete_receive_from(data->llcp, data->invocation, result, -1, - net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } -} - -static void llcp_handle_close_thread_func(gpointer user_data) -{ - net_nfc_error_e result; - LlcpCloseData *data = user_data; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - net_nfc_controller_llcp_socket_close(data->client_socket, &result); - - net_nfc_gdbus_llcp_complete_close(data->llcp, data->invocation, result, - data->client_socket); -} - -static void llcp_handle_disconnect_thread_func(gpointer user_data) -{ - bool ret; - net_nfc_error_e result; - LlcpDisconnectData *data = user_data; - - g_assert(data != NULL); - g_assert(data->llcp != NULL); - g_assert(data->invocation != NULL); - - if (GUINT_TO_POINTER(data->handle) == 0) - { - int ret_val; - - net_nfc_server_free_target_info(); - ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER); - NFC_DBG("net_nfc_controller_disconnect pm_unlock_state[%d]!!", ret_val); - } - - ret = net_nfc_controller_llcp_disconnect(GUINT_TO_POINTER(data->handle), - data->client_socket, &result, llcp_disconnect_cb, data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_disconnect failed [%d]", result); - - net_nfc_gdbus_llcp_complete_disconnect(data->llcp, data->invocation, result, - data->client_socket); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } -} - - -static gboolean llcp_handle_config(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - GVariant *arg_config, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpConfigData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "w"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpConfigData, 1); - if (NULL == data) - { - 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); - - result = net_nfc_server_controller_async_queue_push( - llcp_handle_config_thread_func, data); - - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } - - return result; -} - -static gboolean llcp_handle_listen(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - guint32 arg_handle, - guint32 arg_client_socket, - guint16 arg_miu, - guint8 arg_rw, - gint32 arg_type, - guint8 arg_sap, - const gchar *arg_service_name, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpListenData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpListenData, 1); - if (NULL == data) - { - 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->miu = arg_miu; - data->rw = arg_rw; - data->type = arg_type; - data->sap = arg_sap; - data->service_name = g_strdup(arg_service_name); - - result = net_nfc_server_controller_async_queue_push(llcp_handle_listen_thread_func, - data); - - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - g_free(data->service_name); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } - - return result; -} - -static gboolean llcp_handle_accept(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - guint32 arg_handle, - guint32 arg_client_socket, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpAcceptData *data; - - NFC_INFO(">>> REQUEST from [%s]", - g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpAcceptData, 1); - if (NULL == data) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.MemoryError", "Out of 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; - - result = net_nfc_server_controller_async_queue_push(llcp_handle_accept_thread_func, - data); - - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } - - return result; -} - -static gboolean llcp_handle_reject(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - guint32 arg_handle, - guint32 arg_client_socket, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpAcceptData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpAcceptData, 1); - if (NULL == data) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.MemoryError", "Out of 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; - - result = net_nfc_server_controller_async_queue_push(llcp_handle_reject_thread_func, - data); - - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } - - return result; -} - -static gboolean llcp_handle_connect(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - guint32 arg_handle, - guint32 arg_client_socket, - guint16 arg_miu, - guint8 arg_rw, - gint32 arg_type, - const gchar *arg_service_name, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpConnectData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpConnectData, 1); - if (NULL == data) - { - 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->miu = arg_miu; - data->rw = arg_rw; - data->type = arg_type; - data->service_name = g_strdup(arg_service_name); - - result = net_nfc_server_controller_async_queue_push(llcp_handle_connect_thread_func, - data); - - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - g_free(data->service_name); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } - - return result; -} - -static gboolean llcp_handle_connect_sap(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - guint32 arg_handle, - guint32 arg_client_socket, - guint16 arg_miu, - guint8 arg_rw, - gint32 arg_type, - guint8 arg_sap, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpConnectSapData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpConnectSapData, 1); - if (NULL == data) - { - 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->miu = arg_miu; - data->rw = arg_rw; - data->type = arg_type; - data->sap = arg_sap; - - result = net_nfc_server_controller_async_queue_push( - llcp_handle_connect_sap_thread_func, data); - - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } - - return result; -} - -static gboolean llcp_handle_send(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - guint32 arg_handle, - guint32 arg_client_socket, - GVariant *arg_data, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpSendData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "w"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpSendData, 1); - if (NULL == data) - { - 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; - - net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data); - - result = net_nfc_server_controller_async_queue_push(llcp_handle_send_thread_func, - data); - - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - net_nfc_util_free_data(&data->data); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } - - return result; -} - -static gboolean llcp_handle_send_to(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - guint32 arg_handle, - guint32 arg_client_socket, - guint8 arg_sap, - GVariant *arg_data, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpSendToData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpSendToData, 1); - if (NULL == data) - { - 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->sap = arg_sap; - - net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data); - - result = net_nfc_server_controller_async_queue_push(llcp_handle_send_to_thread_func, - data); - - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - net_nfc_util_free_data(&data->data); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } - - return result; -} - -static gboolean llcp_handle_receive(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - guint32 arg_handle, - guint32 arg_client_socket, - guint32 arg_req_length, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpReceiveData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "w"); - - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpReceiveData, 1); - if (NULL == data) - { - 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->req_length = arg_req_length; - - result = net_nfc_server_controller_async_queue_push(llcp_handle_receive_thread_func, - data); - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } - - return result; -} - -static gboolean llcp_handle_receive_from(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - guint32 arg_handle, - guint32 arg_client_socket, - guint32 arg_req_length, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpReceiveData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "w"); - - /* check privilege and update client context */ - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpReceiveData, 1); - if (NULL == data) - { - 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->req_length = arg_req_length; - - result = net_nfc_server_controller_async_queue_push( - llcp_handle_receive_from_thread_func, data); - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } - - return result; -} - -static gboolean llcp_handle_close(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - guint32 arg_handle, - guint32 arg_client_socket, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpCloseData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "w"); - /* check privilege and update client context */ - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpCloseData, 1); - if (NULL == data) - { - 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; - - result = net_nfc_server_controller_async_queue_push(llcp_handle_close_thread_func, - data); - - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - g_object_unref(data->llcp); - g_object_unref(data->invocation); - - g_free(data); - } - - return result; -} - -static gboolean llcp_handle_disconnect(NetNfcGDbusLlcp *llcp, - GDBusMethodInvocation *invocation, - guint32 arg_handle, - guint32 arg_client_socket, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - LlcpDisconnectData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "w"); - /* check privilege and update client context */ - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(LlcpDisconnectData, 1); - if (NULL == data) - { - 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; - - result = net_nfc_server_controller_async_queue_push(llcp_handle_disconnect_thread_func, - data); - - if (FALSE == result) - { - g_dbus_method_invocation_return_dbus_error(invocation, - "org.tizen.NetNfcService.Llcp.ThreadError", - "can not push to controller thread"); - - g_object_unref(data->invocation); - g_object_unref(data->llcp); - - g_free(data); - } - - return result; -} - -void net_nfc_server_llcp_deactivated(gpointer user_data) -{ - gboolean ret; - net_nfc_target_handle_s *handle = user_data; - - if (handle != NULL) - { - net_nfc_error_e result = NET_NFC_OK; - - if (net_nfc_controller_disconnect(handle, &result) == false) - { - if (result != NET_NFC_NOT_CONNECTED) - net_nfc_controller_exception_handler(); - else - NFC_ERR("target was not connected."); - } - - net_nfc_server_set_state(NET_NFC_SERVER_IDLE); - } - else - { - NFC_ERR("the target was disconnected"); - } - - /* send p2p detatch */ - ret = net_nfc_server_controller_async_queue_push(net_nfc_server_p2p_detached, NULL); - - if (FALSE == ret) - NFC_ERR("can not push to controller thread"); - -} - -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 = user_param; - - g_assert(simple_data != NULL); - - 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 = user_param; - - g_assert(simple_data != NULL); - - if (result != NET_NFC_OK) - NFC_ERR("listen socket failed, [%d]", result); - - if (simple_data->callback) - { - simple_data->callback(result, simple_data->handle, socket, data, - simple_data->user_data); - } - - /* 'simple_data' will be freed in socket error callback */ -} - -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 = user_param; - - g_assert(simple_data != NULL); - - if (result != NET_NFC_OK) - NFC_ERR("connect socket failed, [%d]", result); - - if (simple_data->callback) - { - simple_data->callback(result, simple_data->handle, socket, data, - simple_data->user_data); - } - - /* 'simple_data' will be freed in socket error callback */ -} - -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 = user_param; - - g_assert(simple_data != NULL); - - 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 = user_param; - - g_assert(simple_data != NULL); - - 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) -{ - gboolean result; - 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-accept", - G_CALLBACK(llcp_handle_accept), NULL); - - g_signal_connect(llcp_skeleton, "handle-reject", - G_CALLBACK(llcp_handle_reject), 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); - - result = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(llcp_skeleton), - connection, "/org/tizen/NetNfcService/Llcp", &error); - if (FALSE == result) - { - g_error_free(error); - - net_nfc_server_llcp_deinit(); - } - - return result; -} - -void net_nfc_server_llcp_deinit(void) -{ - if (llcp_skeleton) - { - g_object_unref(llcp_skeleton); - llcp_skeleton = NULL; - } -} - -net_nfc_error_e net_nfc_server_llcp_set_config( - net_nfc_llcp_config_info_s *config) -{ - net_nfc_error_e result; - - if (NULL == config) - { - 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) -{ - bool ret; - net_nfc_llcp_socket_t socket = -1; - net_nfc_llcp_config_info_s config; - net_nfc_error_e result = NET_NFC_OK; - LlcpSimpleData *simple_data = NULL; - - if (NULL == handle) - return NET_NFC_NULL_PARAMETER; - - if (net_nfc_controller_llcp_get_remote_config(handle, &config, &result) == false) - { - NFC_ERR("net_nfc_controller_llcp_get_remote_config failed [%d]", result); - - goto ERROR; - } - - simple_data = g_try_new0(LlcpSimpleData, 1); - if (NULL == simple_data) - { - NFC_ERR("g_try_new0 failed"); - - result = NET_NFC_ALLOC_FAIL; - - goto ERROR; - } - - 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()); - - ret = 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); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_create_socket failed [%d]", result); - - goto ERROR; - } - - simple_data->socket = socket; - - if (net_nfc_controller_llcp_bind(socket, sap, &result) == false) - { - NFC_ERR("net_nfc_controller_llcp_bind failed [%d]", result); - - goto ERROR; - } - - ret = net_nfc_controller_llcp_listen(handle, (uint8_t *)san, socket, &result, - llcp_simple_listen_cb, simple_data); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_listen failed [%d]", result); - - goto ERROR; - } - - NFC_DBG("result [%d]", result); - - if (result == NET_NFC_BUSY) - result = NET_NFC_OK; - - return result; - -ERROR : - if (socket != -1) - { - net_nfc_error_e temp; - - net_nfc_controller_llcp_socket_close(socket, &temp); - } - - if (simple_data != NULL) - g_free(simple_data); - - 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) -{ - bool ret; - net_nfc_error_e result; - net_nfc_llcp_socket_t socket = -1; - net_nfc_llcp_config_info_s config; - LlcpSimpleData *simple_data = NULL; - - if (NULL == handle) - return NET_NFC_NULL_PARAMETER; - - if (net_nfc_controller_llcp_get_remote_config(handle, &config, &result) == false) - { - NFC_ERR("net_nfc_controller_llcp_get_remote_config failed [%d]", result); - - goto ERROR; - } - - simple_data = g_try_new0(LlcpSimpleData, 1); - if (NULL == simple_data) - { - NFC_ERR("g_try_new0 failed"); - - result = NET_NFC_ALLOC_FAIL; - - goto ERROR; - } - - 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()); - - ret = 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); - - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_create_socket failed [%d]", result); - - goto ERROR; - } - - simple_data->socket = socket; - - if (NULL == san) - { - ret = net_nfc_controller_llcp_connect(handle, simple_data->socket, sap, - &result, llcp_simple_connect_cb, simple_data); - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_connect failed [%d]", result); - - goto ERROR; - } - } - else - { - ret = net_nfc_controller_llcp_connect_by_url(handle, simple_data->socket, - (uint8_t *)san, &result, llcp_simple_connect_cb, simple_data); - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_connect_by_url failed [%d]", result); - - goto ERROR; - } - } - - NFC_DBG("result [%d]", result); - - if (result == NET_NFC_BUSY) - result = NET_NFC_OK; - - return result; - -ERROR : - if (socket != -1) - { - net_nfc_error_e temp; - - net_nfc_controller_llcp_socket_close(socket, &temp); - } - - if (simple_data != NULL) - g_free(simple_data); - - 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) -{ - bool ret; - net_nfc_error_e result; - LlcpSimpleData *simple_data; - - simple_data = g_try_new0(LlcpSimpleData, 1); - if (simple_data != NULL) - { - simple_data->handle = handle; - simple_data->socket = socket; - simple_data->error_callback = error_callback; - simple_data->user_data = user_data; - - ret = net_nfc_controller_llcp_accept(socket, &result, - llcp_simple_socket_error_cb, simple_data); - if (false == ret) - NFC_ERR("net_nfc_controller_llcp_accept failed [%d]", result); - } - else - { - NFC_ERR("g_try_new0 failed"); - - result = NET_NFC_ALLOC_FAIL; - } - - 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) -{ - bool ret; - net_nfc_error_e result; - LlcpSimpleData *simple_data; - - simple_data = g_try_new0(LlcpSimpleData, 1); - if (simple_data != NULL) - { - simple_data->handle = handle; - simple_data->socket = socket; - simple_data->callback = callback; - simple_data->user_data = user_data; - - ret = net_nfc_controller_llcp_send(handle, socket, data, &result, - llcp_simple_send_cb, simple_data); - - if (false == ret) - NFC_ERR("net_nfc_controller_llcp_send failed [%d]", result); - } - else - { - NFC_ERR("g_try_new0 failed"); - - result = NET_NFC_ALLOC_FAIL; - } - - if (NET_NFC_BUSY == result) - 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) -{ - bool ret; - net_nfc_error_e result; - LlcpSimpleData *simple_data; - - simple_data = g_try_new0(LlcpSimpleData, 1); - if (simple_data != NULL) - { - simple_data->handle = handle; - simple_data->socket = socket; - simple_data->callback = callback; - simple_data->user_data = user_data; - - ret = net_nfc_controller_llcp_recv(handle, socket, net_nfc_server_llcp_get_miu(), - &result, llcp_simple_receive_cb, simple_data); - if (false == ret) - { - NFC_ERR("net_nfc_controller_llcp_recv failed [%d]", result); - - g_free(simple_data); - } - } - else - { - NFC_ERR("g_try_new0 failed"); - - result = NET_NFC_ALLOC_FAIL; - } - - if (NET_NFC_BUSY == result) - 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 (NULL == service_table) - 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) -{ - net_nfc_error_e result; - service_t *service = NULL; - - RETV_IF(NULL == cb, NET_NFC_NULL_PARAMETER); - - _llcp_init(); - - if (_llcp_find_service(sap) == NULL) - { - NFC_DBG("new service, sap [%d]", sap); - - service = g_try_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 - { - NFC_ERR("alloc failed"); - - result = NET_NFC_ALLOC_FAIL; - } - } else { - NFC_ERR("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) -{ - gpointer key; - service_t *service; - GHashTableIter iter; - - if (NULL == service_table) - 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) -{ - service_t *service; - net_nfc_error_e result; - - 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 - { - NFC_ERR("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() -{ - gpointer key; - service_t *service; - GHashTableIter iter; - - if (NULL == service_table) - 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) -{ - bool ret; - net_nfc_target_handle_s *handle; - net_nfc_current_target_info_s *target; -#if 0 - net_nfc_error_e result; - net_nfc_target_type_e dev_type; -#endif - - target = net_nfc_server_get_target_info(); - - g_assert(target != NULL); /* raise exception!!! what;s wrong?? */ - - handle = target->handle; - - NFC_DBG("connection type = [%d]", handle->connection_type); -#if 0 - dev_type = target->devType; - - if (NET_NFC_NFCIP1_TARGET == dev_type) - { - NFC_DBG("LLCP : target, try to connect"); - - if (net_nfc_controller_connect(handle, &result) == false) - { - NFC_ERR("net_nfc_controller_connect is failed, [%d]", result); - - ret = net_nfc_controller_configure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, - NET_NFC_ALL_ENABLE, &result); - if (false == ret) - { - NFC_ERR("net_nfc_controller_configure_discovery is failed [%d]", result); - net_nfc_controller_exception_handler(); - } - - return; - } - } - - NFC_DBG("check LLCP"); - - if (net_nfc_controller_llcp_check_llcp(handle, &result) == false) - { - NFC_ERR("net_nfc_controller_llcp_check_llcp is failed [%d]", result); - return; - } - - NFC_DBG("activate LLCP"); - - if (net_nfc_controller_llcp_activate_llcp(handle, &result) == false) - { - NFC_ERR("%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) -{ - gboolean ret; - - ret = net_nfc_server_controller_async_queue_push( - net_nfc_server_llcp_process, NULL); - - if (FALSE == ret) - NFC_ERR("can not push to controller thread"); - -} diff --git a/daemon/net_nfc_server_llcp.h b/daemon/net_nfc_server_llcp.h deleted file mode 100644 index 5d6271f..0000000 --- a/daemon/net_nfc_server_llcp.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -#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(gpointer user_data); - -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__ diff --git a/daemon/net_nfc_server_manager.c b/daemon/net_nfc_server_manager.c deleted file mode 100644 index 474aa84..0000000 --- a/daemon/net_nfc_server_manager.c +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "net_nfc_debug_internal.h" -#include "net_nfc_typedef_internal.h" - -#include "net_nfc_gdbus.h" -#include "net_nfc_server_common.h" -#include "net_nfc_server_manager.h" -#include "net_nfc_server_se.h" -#include "net_nfc_server_llcp.h" -#include "net_nfc_server_context.h" -#include "net_nfc_server_controller.h" -#include "net_nfc_server_process_snep.h" -#include "net_nfc_server_process_npp.h" -#include "net_nfc_server_process_handover.h" - - -typedef struct _ManagerActivationData ManagerActivationData; - -struct _ManagerActivationData -{ - NetNfcGDbusManager *manager; - GDBusMethodInvocation *invocation; - gboolean is_active; -}; - - -static NetNfcGDbusManager *manager_skeleton = NULL; - - -/* reimplementation of net_nfc_service_init()*/ -static net_nfc_error_e manager_active(void) -{ - int ret; - int se_type; - net_nfc_error_e result; - - if (net_nfc_controller_is_ready(&result) == false) - { - NFC_ERR("net_nfc_controller_is_ready failed [%d]", result); - - return result; - } - - /* keep_SE_select_value */ - ret = vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_type); - if (0 == ret) - { - NFC_DBG("manager_active se_type [%d]",se_type); - result = net_nfc_server_se_change_se(se_type); - } - - /* 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) == TRUE) - { - /* vconf on */ - if (vconf_set_bool(VCONFKEY_NFC_STATE, TRUE) != 0) - { - NFC_ERR("vconf_set_bool is failed"); - - result = NET_NFC_OPERATION_FAIL; - } - } - else - { - NFC_ERR("net_nfc_controller_configure_discovery is failed, [%d]", result); - } - - return result; -} - -/* reimplementation of net_nfc_service_deinit()*/ -static net_nfc_error_e manager_deactive(void) -{ - bool ret; - net_nfc_error_e result; - - if (net_nfc_controller_is_ready(&result) == false) - { - NFC_ERR("net_nfc_controller_is_ready failed [%d]", result); - - return result; - } - - /* unregister all services */ - net_nfc_server_llcp_unregister_all(); - - /* keep_SE_select_value do not need to update vconf and gdbus_se_setting */ - result = net_nfc_server_se_disable_card_emulation(); - - ret = net_nfc_controller_configure_discovery(NET_NFC_DISCOVERY_MODE_STOP, - NET_NFC_ALL_DISABLE, &result); - - if (TRUE == ret) - { - /* vconf off */ - if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0) - { - NFC_ERR("vconf_set_bool is failed"); - - result = NET_NFC_OPERATION_FAIL; - } - } - else - { - NFC_ERR("net_nfc_controller_configure_discovery is failed, [%d]", result); - } - - return result; -} - -static void manager_handle_active_thread_func(gpointer user_data) -{ - net_nfc_error_e result; - ManagerActivationData *data = user_data; - - g_assert(data != NULL); - g_assert(data->manager != NULL); - g_assert(data->invocation != NULL); - - if (data->is_active) - result = manager_active(); - else - result = manager_deactive(); - - net_nfc_gdbus_manager_complete_set_active(data->manager, data->invocation, result); - - if (NET_NFC_OK == result) - { - NFC_INFO("nfc %s", data->is_active ? "activated" : "deactivated"); - - net_nfc_gdbus_manager_emit_activated(data->manager, data->is_active); - } - else - { - NFC_ERR("activation change failed, [%d]", result); - } - - 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_server_controller_deinit(); -} - - -static gboolean manager_handle_set_active(NetNfcGDbusManager *manager, - GDBusMethodInvocation *invocation, - gboolean arg_is_active, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - gboolean result; - ManagerActivationData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::admin", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - NFC_DBG("is_active %d", arg_is_active); - - data = g_try_new0(ManagerActivationData, 1); - if (NULL == data) - { - NFC_ERR("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; - - result = net_nfc_server_controller_async_queue_push( - manager_handle_active_thread_func, data); - if (FALSE == result) - { - 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->manager); - - g_free(data); - } - - return result; -} - -static gboolean manager_handle_get_server_state(NetNfcGDbusManager *manager, - GDBusMethodInvocation *invocation, GVariant *smack_privilege, gpointer user_data) -{ - bool ret; - guint32 state; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::admin", "r"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - state = net_nfc_server_get_state(); - - net_nfc_gdbus_manager_complete_get_server_state(manager, invocation, NET_NFC_OK, - state); - - return TRUE; -} - -/* server side */ -static void manager_active_thread_func(gpointer user_data) -{ - net_nfc_error_e ret; - ManagerActivationData *data = user_data; - - g_assert(data != NULL); - - if (data->is_active) - ret = manager_active(); - else - ret = manager_deactive(); - - if (NET_NFC_OK == ret) - { - NFC_INFO("nfc %s", data->is_active ? "activated" : "deactivated"); - - net_nfc_gdbus_manager_emit_activated(data->manager, data->is_active); - } - else - { - NFC_ERR("activation change failed, [%d]", ret); - } - - g_free(data); -} - -gboolean net_nfc_server_manager_init(GDBusConnection *connection) -{ - gboolean ret; - 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); - - ret = g_dbus_interface_skeleton_export( - G_DBUS_INTERFACE_SKELETON(manager_skeleton), - connection, - "/org/tizen/NetNfcService/Manager", - &error); - - if (FALSE == ret) - { - NFC_ERR("Can not skeleton_export %s", error->message); - - g_error_free(error); - - net_nfc_server_manager_deinit(); - - 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) -{ - bool ret; - ManagerActivationData *data; - - if (NULL == manager_skeleton) - { - NFC_ERR("net_nfc_server_manager is not initialized"); - - return; - } - - NFC_DBG("is_active %d", is_active); - - data = g_try_new0(ManagerActivationData, 1); - if (NULL == data) - { - NFC_ERR("Memory allocation failed"); - - return; - } - - data->manager = g_object_ref(manager_skeleton); - data->is_active = is_active; - - ret = net_nfc_server_controller_async_queue_push(manager_active_thread_func, data); - if (FALSE == ret) - { - NFC_ERR("can not push to controller thread"); - - g_object_unref(data->manager); - g_free(data); - } -} - -bool net_nfc_server_manager_get_active() -{ - int value; - - if (vconf_get_bool(VCONFKEY_NFC_STATE, &value) < 0) - return false; - - return (!!value); -} diff --git a/daemon/net_nfc_server_manager.h b/daemon/net_nfc_server_manager.h deleted file mode 100644 index 53b45b6..0000000 --- a/daemon/net_nfc_server_manager.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -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__ diff --git a/daemon/net_nfc_server_ndef.c b/daemon/net_nfc_server_ndef.c deleted file mode 100644 index d6ba1cb..0000000 --- a/daemon/net_nfc_server_ndef.c +++ /dev/null @@ -1,444 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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) -{ - net_nfc_error_e result; - GVariant *data_variant; - data_s *read_data = NULL; - ReadData *data = user_data; - net_nfc_target_handle_s *handle; - - 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) -{ - net_nfc_error_e result; - WriteData *data = user_data; - net_nfc_target_handle_s *handle; - - 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) -{ - net_nfc_error_e result; - net_nfc_target_handle_s *handle; - MakeReadOnlyData *data = user_data; - - 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) -{ - net_nfc_error_e result; - FormatData *data = user_data; - net_nfc_target_handle_s *handle; - - 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) -{ - bool ret; - ReadData *data; - gboolean result; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::tag", "r"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_new0(ReadData, 1); - if (NULL == data) - { - NFC_ERR("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 (FALSE == result) - { - 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) -{ - bool ret; - WriteData *data; - gboolean result; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::tag", "w"); - - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_new0(WriteData, 1); - if (NULL == data) - { - NFC_ERR("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 (FALSE == result) - { - 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) -{ - bool ret; - gboolean result; - MakeReadOnlyData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::tag", "w"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_new0(MakeReadOnlyData, 1); - if (NULL == data) - { - NFC_ERR("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 (FALSE == result) - { - 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) -{ - bool ret; - gboolean result; - FormatData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::tag", "w"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_new0(FormatData, 1); - if (NULL == data) - { - NFC_ERR("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 (FALSE == result) - { - 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 (FALSE == result) - { - 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; - } -} diff --git a/daemon/net_nfc_server_ndef.h b/daemon/net_nfc_server_ndef.h deleted file mode 100644 index 7b241b1..0000000 --- a/daemon/net_nfc_server_ndef.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -gboolean net_nfc_server_ndef_init(GDBusConnection *connection); - -void net_nfc_server_ndef_deinit(void); - -#endif //__NET_NFC_SERVER_NDEF_H__ diff --git a/daemon/net_nfc_server_p2p.c b/daemon/net_nfc_server_p2p.c deleted file mode 100644 index 3336e03..0000000 --- a/daemon/net_nfc_server_p2p.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_tag.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; - guint32 p2p_handle; - data_s data; -}; - -static NetNfcGDbusP2p *p2p_skeleton = NULL; - -static void p2p_send_data_thread_func(gpointer user_data) -{ - net_nfc_error_e result; - net_nfc_target_handle_s *handle; - P2pSendData *p2p_data = user_data; - - 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(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) -{ - bool ret; - gboolean result; - P2pSendData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "w"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_new0(P2pSendData, 1); - if(NULL == data) - { - NFC_ERR("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 (FALSE == result) - { - 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 (FALSE == result) - { - 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) -{ - NFC_INFO("====== p2p target detached ======"); - - /* release target information */ - net_nfc_server_free_target_info(); - - if (p2p_skeleton != NULL) - net_nfc_gdbus_p2p_emit_detached(p2p_skeleton); -} - -void net_nfc_server_p2p_discovered(net_nfc_target_handle_s *handle) -{ - NFC_INFO("====== p2p target discovered ======"); - - if (NULL == p2p_skeleton) - { - NFC_ERR("p2p_skeleton is not initialized"); - - return; - } - - net_nfc_gdbus_p2p_emit_discovered(p2p_skeleton, GPOINTER_TO_UINT(handle)); -} - -void net_nfc_server_p2p_received(data_s *user_data) -{ - GVariant *arg_data; - - if (NULL == p2p_skeleton) - { - NFC_ERR("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 = 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); -} diff --git a/daemon/net_nfc_server_p2p.h b/daemon/net_nfc_server_p2p.h deleted file mode 100644 index 33738a7..0000000 --- a/daemon/net_nfc_server_p2p.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -#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_s *handle); - -void net_nfc_server_p2p_received(data_s *user_data); - -void net_nfc_server_p2p_data_sent(net_nfc_error_e result, gpointer user_data); - -#endif //__NET_NFC_SERVER_P2P_H__ diff --git a/daemon/net_nfc_server_phdc.c b/daemon/net_nfc_server_phdc.c deleted file mode 100755 index 91f33f2..0000000 --- a/daemon/net_nfc_server_phdc.c +++ /dev/null @@ -1,675 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_tag.h" -#include "net_nfc_server_context.h" -#include "net_nfc_server_process_phdc.h" -#include "net_nfc_server_phdc.h" -#include "net_nfc_server_llcp.h" - -typedef struct _PhdcSendData PhdcSendData; - -struct _PhdcSendData -{ - NetNfcGDbusPhdc *phdc; - GDBusMethodInvocation *invocation; - guint32 phdc_handle; - data_s data; -}; - -static NetNfcGDbusPhdc *phdc_skeleton = NULL; - - -static gboolean _phdc_send_request_cb_(net_nfc_phdc_handle_h handle, - net_nfc_error_e result, net_nfc_server_phdc_indication_type indication, - gpointer *user_data) -{ - - NFC_DBG("phdc_send_request_cb_result [%d]",result); - - GVariant *parameter = (GVariant *)user_data; - - g_assert(parameter != NULL); - - NetNfcGDbusPhdc *object; - GDBusMethodInvocation *invocation; - net_nfc_phdc_handle_h phdc_handle; - GVariant *phdc_data ; - - g_variant_get(parameter, - "(uuu@a(y))", - (guint *)&object, - (guint *)&invocation, - (guint *)&phdc_handle, - (guint *)&phdc_data); - - net_nfc_gdbus_phdc_complete_send(object, invocation, (gint)result); - - g_variant_unref(phdc_data); - g_object_unref(invocation); - g_object_unref(object); - g_variant_unref(parameter); - - result = NET_NFC_OK; - return result; - -} - -static void phdc_send_data_thread_func(gpointer user_data) -{ - NetNfcGDbusPhdc *object; - GDBusMethodInvocation *invocation; - net_nfc_error_e result; - net_nfc_phdc_handle_h handle = NULL; - GVariant *phdc_data; - data_s data = { NULL, }; - - if (NULL == user_data) - { - NFC_ERR("cannot get PHDC client data"); - return; - } - - NFC_DBG(">>> phdc_send_data_thread_func"); - - g_variant_get((GVariant *)user_data, - "(uuu@a(y))", - (guint *)&object, - (guint *)&invocation, - (guint *)&handle, - &phdc_data); - - g_assert(object != NULL); - g_assert(invocation != NULL); - - net_nfc_util_gdbus_variant_to_data_s(phdc_data, &data); - - result = net_nfc_server_phdc_agent_request(handle, &data, - _phdc_send_request_cb_, user_data); - - if (result != NET_NFC_OK) - { - net_nfc_gdbus_phdc_complete_send(object, invocation, (gint)result); - - g_object_unref(invocation); - g_object_unref(object); - g_variant_unref(user_data); - } - - g_variant_unref(phdc_data); -} - -static gboolean phdc_handle_send(NetNfcGDbusPhdc *phdc, - GDBusMethodInvocation *invocation, //object for handling remote calls,provides a way to asynly return data - guint handle, - GVariant* user_data, - GVariant *smack_privilege) -{ - bool ret; - gboolean result; - GVariant *parameter = NULL; - - NFC_INFO(">>> REQUEST from [%s]",g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "w"); - - if(FALSE == ret) - { - NFC_ERR("permission denied, and finished request"); - result = NET_NFC_SECURITY_FAIL; - goto ERROR; - } - - parameter = g_variant_new("(uuu@a(y))", - GPOINTER_TO_UINT(g_object_ref(phdc)), - GPOINTER_TO_UINT(g_object_ref(invocation)), - handle, - user_data); - - if (NULL == parameter) - { - NFC_ERR("Memory allocation failed"); - result = NET_NFC_ALLOC_FAIL; - - goto ERROR; - } - - result = net_nfc_server_controller_async_queue_push(phdc_send_data_thread_func, parameter); - - if (FALSE == result) - { - /* return error if queue was blocked */ - NFC_ERR("controller is processing important message.."); - result = NET_NFC_BUSY; - - goto ERROR; - - } - - return TRUE; - - ERROR : - - if (parameter != NULL) - { - g_object_unref(invocation); - g_object_unref(phdc); - g_variant_unref(parameter); - } - - net_nfc_gdbus_phdc_complete_send(phdc, invocation, result); - return TRUE; -} - -void net_nfc_server_phdc_data_received_indication(data_s *arg_data) -{ - NFC_INFO("=net_nfc_server_phdc_transport_data_received_indication="); - - GVariant *data; - data = net_nfc_util_gdbus_data_to_variant(arg_data); - - if (NULL == phdc_skeleton) - { - NFC_ERR("phdc_skeleton is not initialized"); - return; - } - - net_nfc_gdbus_phdc_emit_phdc_received(phdc_skeleton, data); -} - -static void _emit_phdc_event_signal(GVariant *parameter, - net_nfc_phdc_handle_h handle, net_nfc_error_e result, uint32_t type) -{ - gboolean ret; - char *client_id = NULL; - void *user_data = NULL; - GError *error = NULL; - GDBusConnection *connection; - - g_variant_get(parameter, "(usu)", (guint *)&connection, &client_id, - (guint *)&user_data); - - ret = g_dbus_connection_emit_signal( - connection, - client_id, - "/org/tizen/NetNfcService/Phdc", - "org.tizen.NetNfcService.Phdc", - "PhdcEvent", - g_variant_new("(iuu)", (gint)result, type, - GPOINTER_TO_UINT(user_data)), &error); - - if (FALSE == ret) - { - if (error != NULL && error->message != NULL) - NFC_ERR("g_dbus_connection_emit_signal failed : %s", error->message); - else - NFC_ERR("g_dbus_connection_emit_signal failed"); - } - - g_free(client_id); -} - -static void _server_phdc_agent_cb_(net_nfc_phdc_handle_h handle, - net_nfc_error_e result, net_nfc_server_phdc_indication_type indication, data_s *data) -{ - if(NET_NFC_OK != result) - { - net_nfc_server_phdc_transport_disconnect_indication(); - return; - } - - RET_IF(NULL == handle); - - NFC_DBG(" handle [%p], result[%d]", handle, result); - - if( NET_NFC_PHDC_TARGET_CONNECTED == indication) - net_nfc_server_phdc_transport_connect_indication(handle); - else if(NET_NFC_PHDC_DATA_RECEIVED == indication) - net_nfc_server_phdc_data_received_indication(data); - - return; -} - - -static void _phdc_agent_activate_cb(int event, net_nfc_target_handle_s *handle, - uint32_t sap, const char *san, void *user_param) -{ - net_nfc_error_e result = NET_NFC_OK; - GVariant *parameter = (GVariant *)user_param; - char *client_id = NULL; - void *user_data = NULL; - GVariant *param = NULL; - GDBusConnection *connection = NULL; - - NFC_DBG("event [%d], handle [%p], sap [%d], san [%s]", event, handle, sap, san); - - if (NET_NFC_LLCP_START == event) - { - 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); - - /* start phdc agent service*/ - result = net_nfc_server_phdc_agent_start(handle, (char *)san, sap, - _server_phdc_agent_cb_, param); - - if (NET_NFC_OK == result) - { - _emit_phdc_event_signal(parameter, handle, result, event); - } - else - { - NFC_ERR("net_nfc_server_phdc_manager_start failed, [%d]", result); - g_variant_unref(param); - } - } - else - { - _emit_phdc_event_signal(parameter, handle, result, NET_NFC_LLCP_UNREGISTERED); - /* unregister server */ - g_variant_unref(parameter); - } - -} - -static void _server_phdc_manager_cb_(net_nfc_phdc_handle_h handle, - net_nfc_error_e result, net_nfc_server_phdc_indication_type indication, data_s *data) -{ - - if(NET_NFC_OK != result) - { - net_nfc_server_phdc_transport_disconnect_indication(); - return; - } - - RET_IF(NULL == handle); - - NFC_DBG("result [%d], data [%p]", result, data); - - if( NET_NFC_PHDC_TARGET_CONNECTED == indication) - net_nfc_server_phdc_transport_connect_indication(handle); - else if(NET_NFC_PHDC_DATA_RECEIVED == indication) - net_nfc_server_phdc_data_received_indication(data); - - return ; -} - - -static void _phdc_manager_activate_cb(int event, net_nfc_target_handle_s *handle, - uint32_t sap, const char *san, void *user_param) -{ - net_nfc_error_e result = NET_NFC_OK; - GVariant *parameter = (GVariant *)user_param; - char *client_id = NULL; - void *user_data = NULL; - GVariant *param = NULL; - GDBusConnection *connection = NULL; - - NFC_DBG("event [%d], handle [%p], sap [%d], san [%s]", event, handle, sap, san); - - if (NET_NFC_LLCP_START == event) - { - 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); - - /* start phdc manager service*/ - result = net_nfc_server_phdc_manager_start(handle, (char *)san, sap, - _server_phdc_manager_cb_, param); - - if (NET_NFC_OK == result) - { - _emit_phdc_event_signal(parameter, handle, result, event); - } - else - { - NFC_ERR("net_nfc_server_phdc_manager_start failed, [%d]", result); - g_variant_unref(param); - } - } - else - { - _emit_phdc_event_signal(parameter, handle, result, NET_NFC_LLCP_UNREGISTERED); - /* unregister server */ - g_variant_unref(parameter); - } - -} - -static void phdc_register_server_thread_func(gpointer user_data) -{ - gchar *arg_san = NULL; - guint arg_role; - guint arg_sap; - guint arg_user_data; - net_nfc_error_e result = NET_NFC_OK; - NetNfcGDbusPhdc *object = NULL; - g_assert(user_data != NULL); - GVariant *parameter = NULL; - GDBusConnection *connection = NULL; - GDBusMethodInvocation *invocation = NULL; - - g_variant_get((GVariant *)user_data, "(uuusu)", (guint *)&object, (guint *)&invocation, - &arg_role, &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) - { - if(!strcmp(arg_san,PHDC_SAN)) - { - arg_san = PHDC_SAN; - arg_sap = PHDC_SAP; - } - else if (!strcmp(arg_san,PHDS_SAN)) - { - arg_san = PHDS_SAN; - arg_sap = PHDS_SAP; - } - else - { - // anything else, as of now,defaulting to PHDC default server - arg_san = PHDC_SAN; - arg_sap = PHDC_SAP; - } - - if(NET_NFC_PHDC_MANAGER == arg_role) - { - result = net_nfc_server_llcp_register_service( - g_dbus_method_invocation_get_sender(invocation), arg_sap, - arg_san, _phdc_manager_activate_cb, parameter); - } - else if(NET_NFC_PHDC_AGENT == arg_role) - { - result = net_nfc_server_llcp_register_service( - g_dbus_method_invocation_get_sender(invocation), arg_sap, - arg_san, _phdc_agent_activate_cb, parameter); - } - - if (result != NET_NFC_OK) - { - NFC_ERR("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_phdc_complete_register_role(object, invocation, result); - - - g_variant_unref(user_data); - - -} - -static gboolean phdc_handle_register( - NetNfcGDbusPhdc *object, - GDBusMethodInvocation *invocation, - guint arg_role, - const gchar *arg_san, - guint arg_user_data, - GVariant *arg_privilege) -{ - bool ret; - gboolean result; - GVariant *parameter = NULL; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, arg_privilege, - "nfc-manager::p2p", "rw"); - if (FALSE == ret) - { - NFC_ERR("permission denied, and finished request"); - result = NET_NFC_SECURITY_FAIL; - goto ERROR; - } - - parameter = g_variant_new("(uuusu)", GPOINTER_TO_UINT(g_object_ref(object)), - GPOINTER_TO_UINT(g_object_ref(invocation)), arg_role, arg_san, arg_user_data); - - if (parameter == NULL) - { - NFC_ERR("Memory allocation failed"); - result = NET_NFC_ALLOC_FAIL; - goto ERROR; - } - if(net_nfc_server_controller_async_queue_push( - phdc_register_server_thread_func, parameter) == FALSE) - { - NFC_ERR("controller is processing important message."); - result = NET_NFC_ALLOC_FAIL; - goto ERROR; - } - - return TRUE; - - ERROR : - if (parameter != NULL) - { - g_object_unref(invocation); - g_object_unref(object); - g_variant_unref(parameter); - } - - net_nfc_gdbus_phdc_complete_register_role(object, - invocation, - result); - - return TRUE; -} - -static void phdc_unregister_server_thread_func(gpointer user_data) -{ - guint arg_role; - guint arg_sap; - gchar *arg_san = NULL; - net_nfc_error_e result; - NetNfcGDbusSnep *object = NULL; - GDBusMethodInvocation *invocation = NULL; - - g_assert(user_data != NULL); - - g_variant_get((GVariant *)user_data, "(uuus)", (guint *)&object, (guint *)&invocation, - &arg_role, &arg_san); - - g_assert(object != NULL); - g_assert(invocation != NULL); - - if(!strcmp(arg_san,PHDS_SAN)) - arg_sap = PHDS_SAP; - else - arg_sap = PHDC_SAP; - - 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 phdc_handle_unregister( - NetNfcGDbusPhdc *object, - GDBusMethodInvocation *invocation, - guint arg_role, - const gchar *arg_san, - GVariant *arg_privilege) -{ - bool ret; - gboolean result; - GVariant *parameter = NULL; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, arg_privilege, - "nfc-manager::p2p", "rw"); - - if (FALSE == ret) - { - NFC_ERR("permission denied, and finished request"); - result = NET_NFC_SECURITY_FAIL; - goto ERROR; - } - - parameter = g_variant_new("(uuus)", GPOINTER_TO_UINT(g_object_ref(object)), - GPOINTER_TO_UINT(g_object_ref(invocation)), arg_role, arg_san); - - if (parameter == NULL) - { - NFC_ERR("Memory allocation failed"); - result = NET_NFC_ALLOC_FAIL; - goto ERROR; - } - if(net_nfc_server_controller_async_queue_push( - phdc_unregister_server_thread_func, parameter) == FALSE) - { - NFC_ERR("controller is processing important message."); - result = NET_NFC_ALLOC_FAIL; - goto ERROR; - } - - return TRUE; - - ERROR : - if (parameter != NULL) - { - g_object_unref(invocation); - g_object_unref(object); - - g_variant_unref(parameter); - } - - net_nfc_gdbus_phdc_complete_register_role(object, - invocation, - result); - - return TRUE; -} - - -gboolean net_nfc_server_phdc_init(GDBusConnection *connection) -{ - gboolean result; - GError *error = NULL; - - if (phdc_skeleton) - net_nfc_server_phdc_deinit(); - - phdc_skeleton = net_nfc_gdbus_phdc_skeleton_new(); - - g_signal_connect(phdc_skeleton,"handle-send", G_CALLBACK(phdc_handle_send), NULL); - - g_signal_connect(phdc_skeleton,"handle-register-role", G_CALLBACK(phdc_handle_register), NULL); - - g_signal_connect(phdc_skeleton,"handle-unregister-role", G_CALLBACK(phdc_handle_unregister), NULL); - - result = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(phdc_skeleton), - connection, "/org/tizen/NetNfcService/Phdc", &error); - - if (FALSE == result) - { - g_error_free(error); - net_nfc_server_phdc_deinit(); - } - - return result; -} - -void net_nfc_server_phdc_deinit(void) -{ - if (phdc_skeleton) - { - g_object_unref(phdc_skeleton); - phdc_skeleton = NULL; - } -} - -void net_nfc_server_phdc_transport_disconnect_indication(void) -{ - NFC_INFO("====== phdc target disconnected ======"); - - /* release target information */ - net_nfc_server_free_target_info(); - - if (phdc_skeleton != NULL) - net_nfc_gdbus_phdc_emit_phdc_disconnect(phdc_skeleton); -} - - -void net_nfc_server_phdc_transport_connect_indication(net_nfc_phdc_handle_h handle) -{ - NFC_INFO("====== phdc target connected ======"); - - if (NULL == phdc_skeleton) - { - NFC_ERR("phdc_skeleton is not initialized"); - return; - } - - net_nfc_gdbus_phdc_emit_phdc_connect(phdc_skeleton, GPOINTER_TO_UINT(handle)); -} - -void net_nfc_server_phdc_data_sent(net_nfc_error_e result, gpointer user_data) -{ - PhdcSendData *data = (PhdcSendData *)user_data; - - g_assert(data != NULL); - g_assert(data->phdc != NULL); - g_assert(data->invocation != NULL); - - net_nfc_gdbus_phdc_complete_send(data->phdc, data->invocation, (gint)result); - - net_nfc_util_free_data(&data->data); - - g_object_unref(data->invocation); - g_object_unref(data->phdc); - - g_free(data); -} - diff --git a/daemon/net_nfc_server_phdc.h b/daemon/net_nfc_server_phdc.h deleted file mode 100755 index a772283..0000000 --- a/daemon/net_nfc_server_phdc.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_PHDC_H__ -#define __NET_NFC_SERVER_PHDC_H__ - -#include -#include "net_nfc_typedef_internal.h" - -gboolean net_nfc_server_phdc_init(GDBusConnection *connection); - -void net_nfc_server_phdc_deinit(void); - -/* server side */ -void net_nfc_server_phdc_transport_disconnect_indication(void); - -void net_nfc_server_phdc_transport_connect_indication(net_nfc_phdc_handle_h handle); - -void net_nfc_server_phdc_data_received_indication(data_s *arg_data); - -void net_nfc_server_phdc_data_sent(net_nfc_error_e result, gpointer user_data); - -#endif //__NET_NFC_SERVER_PHDC_H__ \ No newline at end of file diff --git a/daemon/net_nfc_server_process_handover.c b/daemon/net_nfc_server_process_handover.c deleted file mode 100755 index 41f158e..0000000 --- a/daemon/net_nfc_server_process_handover.c +++ /dev/null @@ -1,1708 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_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; - // TODO: above value MUST be same with 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_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; - // TODO: above value MUST be same with 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(net_nfc_error_e result, - net_nfc_conn_handover_carrier_type_e carrier, - data_s *ac_data, - void *user_param); - -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_bss_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); - -static void _net_nfc_server_handover_bss_process_carrier_record_cb( - net_nfc_error_e result, - net_nfc_conn_handover_carrier_type_e type, - data_s *data, - void *user_param); -static void _net_nfc_server_handover_get_response_process( - net_nfc_handover_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 void _net_nfc_server_handover_send_response( - net_nfc_error_e result, - net_nfc_conn_handover_carrier_type_e carrier, - data_s *ac_data, - void *user_param) -{ - HandoverRequestData *handover_data = user_param; - - g_assert(handover_data != NULL); - g_assert(handover_data->invocation != NULL); - g_assert(handover_data->handoverobj != NULL); - - net_nfc_gdbus_handover_complete_request( - handover_data->handoverobj, - handover_data->invocation, - result, - carrier, - net_nfc_util_gdbus_data_to_variant(ac_data)); - - if (handover_data->data) - { - g_free(handover_data->data->buffer); - g_free(handover_data->data); - } - - g_object_unref(handover_data->invocation); - 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) -{ - uint32_t length; - net_nfc_error_e result; - - RETV_IF(NULL == msg, NET_NFC_INVALID_PARAM); - RETV_IF(NULL == data, 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 = user_param; - - /* append record to ndef message */ - if (NET_NFC_OK == result) - { - 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); - - result = net_nfc_util_append_carrier_config_record(context->ndef_message, - record, cps); - - if (NET_NFC_OK == result) - { - NFC_DBG("net_nfc_util_append_carrier_config_record success"); - } - else - { - NFC_ERR("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_bss_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 = user_param; - - /* append record to ndef message */ - if (NET_NFC_OK == result) - { - ndef_record_s *record; - - net_nfc_util_create_record(carrier->TNF, &carrier->type_s, &carrier->id_s, - &carrier->payload_s, &record); - - result = net_nfc_util_append_carrier_config_record(context->ndef_message, - record, cps); - if (NET_NFC_OK == result) - { - NFC_DBG("net_nfc_util_append_carrier_config_record success"); - } - else - { - NFC_ERR("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 = user_param; - - if (NET_NFC_OK == result) - { - if (context->cb != NULL) - context->cb(result, type, data, context->user_param); - } - else - { - NFC_ERR("_handover_bt_process_carrier_record failed [%d]", result); - } - - _net_nfc_util_free_mem(context); -} - -static void _net_nfc_server_handover_bss_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 = user_param; - - if(context) - { - if (context->cb != NULL) - context->cb(result, type, data, context->user_param); - else - NFC_ERR("Invalid Callback"); - - _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__); - - RETV_IF(NULL == request, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == record, NET_NFC_NULL_PARAMETER); - - *record = NULL; - - result = net_nfc_util_get_alternative_carrier_record_count(request, &carrier_count); - if (NET_NFC_OK == result) - { - 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++) - { - result = net_nfc_util_get_alternative_carrier_type(request, idx, - &carrier_type); - - if ((NET_NFC_OK == result) && (carrier_type == priority)) - { - NFC_DBG("selected carrier type = [%d]", carrier_type); - net_nfc_util_get_carrier_config_record(request, idx, record); - result = NET_NFC_OK; - break; - } - } - } - } - else - { - NFC_ERR("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 (NULL == requestor) - 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 - { - NFC_ERR("record is not valid or is not available"); - net_nfc_util_free_ndef_message(*requestor); - result = NET_NFC_INVALID_PARAM; - } - } - else - { - NFC_ERR("_net_nfc_ndef_rawdata_to_ndef failed [%d]",result); - } - } else { - NFC_ERR("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 (NULL == selector) - return NET_NFC_NULL_PARAMETER; - - *selector = NULL; - - if ((result = net_nfc_util_create_ndef_message(selector)) == NET_NFC_OK) - { - result = net_nfc_util_convert_rawdata_to_ndef_message(data, *selector); - if (NET_NFC_OK == result) - { - /* if record is not Hs record, then */ - if (_net_nfc_server_handover_check_hs_record_validation(*selector) == true) - { - result = NET_NFC_OK; - } - else - { - NFC_ERR("record is not valid or is not available"); - net_nfc_util_free_ndef_message(*selector); - result = NET_NFC_INVALID_PARAM; - } - } - else - { - NFC_ERR("_net_nfc_ndef_rawdata_to_ndef failed [%d]",result); - } - } - else - { - NFC_ERR("_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) -{ - ndef_record_s *rec; - unsigned int count; - net_nfc_error_e ret; - - LOGD("[%s] START", __func__); - - if (NULL == message) - return false; - - rec = (ndef_record_s *)message->records; - - if (memcmp(rec->type_s.buffer, CH_REQ_RECORD_TYPE, rec->type_s.length) != 0) - { - NFC_ERR("This is not connection handover request message"); - goto ERROR; - } - - if (rec->payload_s.buffer[0] != CH_VERSION) - { - NFC_ERR("connection handover version is not matched"); - goto ERROR; - } - - ret = net_nfc_util_get_alternative_carrier_record_count(message, &count); - if (ret != NET_NFC_OK || 0 == count) - { - NFC_ERR("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) -{ - ndef_record_s *rec; - unsigned int count; - net_nfc_error_e ret; - - LOGD("[%s] START", __func__); - - if (NULL == message) - return false; - - rec = (ndef_record_s *)message->records; - - if (memcmp(rec->type_s.buffer, CH_SEL_RECORD_TYPE, rec->type_s.length) != 0) - { - NFC_ERR("This is not connection handover request message"); - goto ERROR; - } - - ret = net_nfc_util_get_alternative_carrier_record_count(message,&count); - if (ret != NET_NFC_OK || 0 == count) - { - NFC_ERR("there is no carrrier reference"); - goto ERROR; - } - - /* check version */ - if (rec->payload_s.buffer[0] != CH_VERSION) - { - NFC_ERR("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__); - - RETV_IF(NULL == context, 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_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 - { - NFC_ERR("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__); - net_nfc_error_e result = NET_NFC_OK; - - switch (context->current_type) - { - case NET_NFC_CONN_HANDOVER_CARRIER_BT : - NFC_DBG("[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 : - NFC_DBG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]"); - -#ifdef TARGET - if(memcmp(context->ndef_message->records->type_s.buffer ,CH_SEL_RECORD_TYPE, - context->ndef_message->records->type_s.length)==0) - { - result = net_nfc_server_handover_bss_wfd_get_carrier_record( - _net_nfc_server_handover_bss_get_carrier_record_cb, context); - } - else -#endif - { - result = net_nfc_server_handover_bss_get_carrier_record( - _net_nfc_server_handover_bss_get_carrier_record_cb, context); - } - NFC_DBG("[%d]",result); - break; - - // case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS : - // NFC_DBG("[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 : - NFC_DBG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]"); - g_idle_add((GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_step, - (gpointer)context); - break; - - default : - NFC_DBG("[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 - { - NFC_ERR("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 - { - NFC_ERR("alloc failed"); - result = NET_NFC_ALLOC_FAIL; - } - - LOGD("[%s:%d] END", __func__, __LINE__); - - 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 : - NFC_DBG("[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 : - NFC_DBG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]"); - net_nfc_server_handover_bss_process_carrier_record(carrier, - _net_nfc_server_handover_bss_process_carrier_record_cb, context); - break; - - case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN : - NFC_DBG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]"); - _net_nfc_util_free_mem(context); - break; - - default : - NFC_DBG("[unknown]"); - _net_nfc_util_free_mem(context); - break; - } - } - else - { - NFC_ERR("alloc failed"); - result = NET_NFC_ALLOC_FAIL; - } - - LOGD("[%s:%d] END", __func__, __LINE__); - - return result; -} - -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) -{ - uint32_t count; - net_nfc_error_e result; - - *record = NULL; - *type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; - - /* get requester message */ - result = net_nfc_util_get_alternative_carrier_record_count(request, &count); - if (NET_NFC_OK == result) - { - if (1/* power state */ || 1 == count) - { - ndef_record_s *temp; - - /* fill alternative carrier information */ - result = net_nfc_server_handover_get_carrier_record_by_priority_order( - request, &temp); - if (NET_NFC_OK == result) - { - result = net_nfc_util_get_alternative_carrier_type_from_record(temp, type); - if (NET_NFC_OK == result) - { - net_nfc_util_create_record(temp->TNF, &temp->type_s, &temp->id_s, - &temp->payload_s, record); - } - else - { - NFC_ERR("net_nfc_util_get_alternative" - "_carrier_type_from_record failed [%d]", result); - } - } - else - { - NFC_ERR("_handover_get_carrier_record_by_priority_order failed [%d]", result); - } - } - else /* low power && count > 1 */ - { - result = NET_NFC_INVALID_STATE; - } - } - else - { - NFC_ERR("net_nfc_util_get_alternative_carrier_record_count failed [%d]", result); - } - - return result; -} - -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 = user_param; - - RET_IF(NULL == context); - - NFC_DBG("_net_nfc_server_handover_server_create_carrier_config_cb result [%d]", - result); - - context->result = result; - - if (NET_NFC_OK == result) - { - result = _net_nfc_server_handover_convert_ndef_message_to_data( - selector, &context->data); - - NFC_DBG("selector message created, length [%d]", context->data.length); - - context->state = NET_NFC_LLCP_STEP_03; - } - else - { - NFC_ERR("_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; - - NFC_DBG("_net_nfc_server_handover_server_process_carrier_record_cb result [%d]", - result); - - context->result = result; - if (NET_NFC_OK == result) - 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; - - RET_IF(NULL == context); - - switch (context->state) - { - case NET_NFC_LLCP_STEP_02 : - NFC_DBG("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) - { - NFC_ERR("_net_nfc_server_handover_create_" - "selector_carrier_config failed [%d]",result); - } - break; - - case NET_NFC_LLCP_STEP_03 : - NFC_DBG("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) - { - NFC_ERR("net_nfc_server_handover_process_carrier_record failed [%d]",result); - } - break; - - case NET_NFC_LLCP_STEP_04 : - NFC_DBG("NET_NFC_LLCP_STEP_04"); - - /* response select message */ - // TODO: context->handle may is not valid type. we should find a right function or parameter - result = net_nfc_server_snep_server_send_get_response( - (net_nfc_snep_handle_h)context->handle, &context->data); - break; - - case NET_NFC_STATE_ERROR : - NFC_DBG("NET_NFC_STATE_ERROR"); - break; - - default : - NFC_ERR("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; - - RETV_IF(NULL == data, false); - RETV_IF(NULL == data->buffer, false); - - NFC_DBG("type [%d], data [%p], user_param [%p]", type, data, user_param); - - /* TODO : send select response to requester */ - result = _net_nfc_server_handover_create_requester_from_rawdata(&request, data); - - if (NET_NFC_OK == result) - { - ndef_record_s *record; - net_nfc_conn_handover_carrier_type_e type; - - result = _net_nfc_server_handover_select_carrier_record(request, &type, &record); - if (NET_NFC_OK == result) - { - 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 - { - NFC_ERR("_net_nfc_util_alloc_mem failed"); - result = NET_NFC_ALLOC_FAIL; - } - } - else - { - /* low power */ - } - - net_nfc_util_free_ndef_message(request); - } - else - { - NFC_ERR("it is not handover requester message, [%d]", result); - } - - return (NET_NFC_OK == result); -} - -//////////////////////////////////////////////////////////////////////////////// -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 = user_param; - - NFC_DBG("_net_nfc_server_handover_server_process_carrier_record_cb result [%d]", - result); - - context->result = result; - - if (NET_NFC_OK == result) - 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_conn_handover_carrier_type_e type; - net_nfc_handover_context_t *context = user_param; - - RET_IF(NULL == context); - - NFC_DBG("_net_nfc_server_handover_server_create_carrier_config_cb,result [%d]", - result); - - context->result = result; - - net_nfc_util_get_alternative_carrier_type_from_record(context->record, &type); - if (NET_NFC_OK == result) - { - result = _net_nfc_server_handover_convert_ndef_message_to_data( - selector, &context->data); - NFC_DBG("selector message created, length [%d]", context->data.length); - if(type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS) - context->state = NET_NFC_LLCP_STEP_04; - else - context->state = NET_NFC_LLCP_STEP_03; - } - else - { - NFC_ERR("_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_error_e ret; - ndef_message_s *request; - net_nfc_handover_context_t *context = user_param; - - NFC_DBG("_net_nfc_server_handover_server_recv_cb, socket [%x], result [%d]", - socket, result); - - context->result = result; - - if (NET_NFC_OK == result) - { - result = _net_nfc_server_handover_create_requester_from_rawdata(&request, data); - - if (NET_NFC_OK == result) - { - ndef_record_s *record; - - ret = _net_nfc_server_handover_select_carrier_record(request, - &context->type, &record); - - if (NET_NFC_OK == ret) - { - 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 - { - NFC_ERR("_net_nfc_server_handover_create" - "_requester_from_rawdata failed [%d]",result); - context->state = NET_NFC_MESSAGE_LLCP_ERROR; - } - } - else - { - NFC_ERR("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 = user_param; - - NFC_DBG("_net_nfc_server_handover_server_send_cb socket[%x], result[%d]", - socket, result); - - context->result = result; - - if (NET_NFC_OK == result) - { - 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 - { - NFC_ERR("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) -{ - RET_IF(NULL == context); - - switch (context->state) - { - case NET_NFC_LLCP_STEP_01 : - NFC_DBG("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 : - NFC_DBG("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) - { - NFC_ERR("_net_nfc_server_handover_create_selector" - "_carrier_configs failed [%d]", context->result); - } - break; - - case NET_NFC_LLCP_STEP_03 : - NFC_DBG("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) - { - NFC_ERR("_net_nfc_server_handover_process_carrier_" - "record failed [%d]",context->result); - } - break; - - case NET_NFC_LLCP_STEP_04 : - NFC_DBG("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 : - NFC_DBG("NET_NFC_STATE_ERROR"); - - /* error, invoke callback */ - NFC_ERR("handover_server failed, [%d]", context->result); - - /* restart?? */ - break; - - default : - NFC_ERR("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 = user_param; - - NFC_ERR("result [%d], socket [%x], user_param [%p]", result, socket, user_param); - - RET_IF(NULL == context); - - 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) -{ - net_nfc_handover_context_t *accept_context = NULL; - - NFC_DBG("result[%d], socket[%x], user_param[%p]", result, socket, user_param); - - _net_nfc_util_alloc_mem(accept_context, sizeof(*accept_context)); - if (NULL == accept_context) - { - NFC_ERR("_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) - { - NFC_ERR("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 (NET_NFC_OK == result) - NFC_DBG("start handover server, san[%s], sap[%d]", CH_SAN, CH_SAP); - else - NFC_ERR("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; - - NFC_DBG("event [%d], handle [%p], sap [%d], san [%s]", event, handle, sap, san); - - if (NET_NFC_LLCP_START == event) - { - /* 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 (NET_NFC_OK == result) - NFC_DBG("start handover server, san [%s], sap [%d]", CH_SAN, CH_SAP); - else - NFC_ERR("net_nfc_service_llcp_server failed, [%d]", result); - - } - else if (NET_NFC_LLCP_UNREGISTERED == event) - { - /* 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 = user_param; - - RET_IF(NULL == context); - - 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 = user_param; - - NFC_DBG("_net_nfc_server_handover_server_process_carrier_record_cb, result[%d]", - result); - - context->result = result; - - net_nfc_util_free_data(&context->data); - - if (NET_NFC_OK == result) - { - if(context->type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS) - { - context->state = NET_NFC_LLCP_STEP_RETURN; - } - else - { - 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 = user_param; - - RET_IF(NULL == context); - - context->result = result; - - if (NET_NFC_OK == result) - { - ndef_record_s *record; - ndef_message_s *selector; - - result = net_nfc_server_handover_create_selector_from_rawdata(&selector, data); - - if (NET_NFC_OK == result) - { - result = net_nfc_server_handover_get_carrier_record_by_priority_order( - selector, &record); - - if (NET_NFC_OK == result) - { - 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 - { - NFC_ERR("_get_carrier_record_by_priority_order failed, [%d]",result); - context->state = NET_NFC_STATE_ERROR; - } - } - else - { - NFC_ERR("_net_nfc_server_handover_create" - "_selector_from_rawdata failed, [%d]",result); - context->state = NET_NFC_STATE_ERROR; - } - } - else - { - NFC_ERR("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 = user_param; - - RET_IF(NULL == context); - - context->result = result; - - net_nfc_util_free_data(&context->data); - - if (NET_NFC_OK == result) - { - context->state = NET_NFC_LLCP_STEP_03; - } - else - { - NFC_ERR("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 = user_param; - - RET_IF(NULL == context); - - context->result = result; - - if (msg != NULL) - { - result = _net_nfc_server_handover_convert_ndef_message_to_data(msg, &context->data); - if (NET_NFC_OK == result) - { - context->state = NET_NFC_LLCP_STEP_02; - } - else - { - NFC_ERR("_net_nfc_server_handover_convert_ndef_" - "message_to_data failed [%d]",result); - context->state = NET_NFC_STATE_ERROR; - context->result = result; - } - } - else - { - NFC_ERR("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; - - RET_IF(NULL == context); - - switch (context->state) - { - case NET_NFC_LLCP_STEP_01 : - NFC_DBG("NET_NFC_LLCP_STEP_01"); - - result = _net_nfc_server_handover_create_requester_carrier_configs( - context->type, - _net_nfc_server_handover_client_create_carrier_configs_cb, - context); - if (result != NET_NFC_OK) - { - NFC_ERR("_net_nfc_server_handover_create_requester" - "_carrier_configs failed [%d]",result); - } - break; - - case NET_NFC_LLCP_STEP_02 : - NFC_DBG("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 : - NFC_DBG("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 : - NFC_DBG("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) - NFC_ERR("net_nfc_server_handover_process_carrier_record failed [%d]",result); - break; - - case NET_NFC_LLCP_STEP_05 : - NFC_DBG("NET_NFC_LLCP_STEP_05"); - - /* start post process */ - if (NET_NFC_CONN_HANDOVER_CARRIER_BT == context->type) - { - net_nfc_server_handover_bt_post_process(&context->data, - _net_nfc_server_handover_client_post_process_cb, context); - } - else - { - NFC_ERR("not supported..."); - } - break; - - case NET_NFC_LLCP_STEP_RETURN : - NFC_DBG("NET_NFC_LLCP_STEP_RETURN"); - - /* complete and invoke callback */ - _net_nfc_server_handover_send_response(context->result, context->type, - &context->data, context->user_param); - - 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 : - NFC_ERR("NET_NFC_STATE_ERROR"); - - _net_nfc_server_handover_send_response(context->result, context->type, - NULL, context->user_param); - 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) -{ - NFC_DBG("result [%d], socket [%x], user_param [%p]", result, socket, user_param); - - HandoverRequestData *handover_data = NULL; - handover_data = (HandoverRequestData *)user_param; - if (NET_NFC_OK == result) - { - 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->type = handover_data->type; - context->user_param = user_param; - _net_nfc_server_handover_client_process(context); - } - else - { - NFC_ERR("_net_nfc_util_alloc_mem failed"); - result = NET_NFC_ALLOC_FAIL; - } - } - else - { - NFC_ERR("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) -{ - NFC_ERR("result [%d], socket [%x], user_param [%p]", result, socket, user_param); - - if (false) - { - _net_nfc_server_handover_send_response(result, - NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, NULL, user_param); - } - - 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) - NFC_ERR("net_nfc_server_llcp_simple_client failed, [%d]",result); - - return result; -} diff --git a/daemon/net_nfc_server_process_handover.h b/daemon/net_nfc_server_process_handover.h deleted file mode 100755 index ff41f02..0000000 --- a/daemon/net_nfc_server_process_handover.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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__ diff --git a/daemon/net_nfc_server_process_npp.c b/daemon/net_nfc_server_process_npp.c deleted file mode 100644 index 3d7eaae..0000000 --- a/daemon/net_nfc_server_process_npp.c +++ /dev/null @@ -1,639 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -#include "net_nfc_debug_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 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 net_nfc_error_e npp_create_message(data_s *data, data_s *message) -{ - net_nfc_npp_msg_t *msg; - uint32_t length = NPP_HEADER_LEN; - - 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; - - NFC_DBG("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) -{ - uint32_t i; - uint32_t length; - NppData *npp_data; - uint32_t entity_count; - net_nfc_npp_msg_t *message; - net_nfc_npp_entity_t *entity; - data_s ndef_msg = { NULL, 0 }; - - RET_IF(NULL == user_data); - - npp_data = user_data; - - if (result != NET_NFC_OK) - { - NFC_ERR("error [%d]", result); - - if(npp_data->callback) - npp_data->callback(result, NULL, npp_data->user_data); - - g_free(npp_data); - return; - } - - if (NULL == data) - { - NFC_ERR("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 (NULL == data->buffer || 0 == data->length) - { - NFC_ERR("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) - { - NFC_ERR("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)) - { - NFC_ERR("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) - { - NFC_ERR("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) - { - NFC_ERR("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); - - NFC_DBG("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; - - RET_IF(NULL == npp_data); - - /* 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; - - RET_IF(NULL == user_data); - - npp_data = user_data; - - NFC_DBG("npp_listen_cb, incoming socket [%#x], result [%d]", socket, result); - - if (result != NET_NFC_OK) - { - NFC_ERR("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) - { - NFC_ERR("%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; - } - - NFC_DBG("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) -{ - NFC_INFO("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; - - RET_IF(NULL == user_data); - - npp_data = user_data; - - NFC_DBG("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) -{ - data_s data; - net_nfc_error_e result; - - RET_IF(NULL == npp_data); - - result = npp_create_message(&npp_data->data, &data); - if (result != NET_NFC_OK) - { - NFC_ERR("%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) - { - NFC_ERR("%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; - - RET_IF(NULL == user_data); - - npp_data = user_data; - - if (result != NET_NFC_OK) - { - NFC_ERR("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 */ - NFC_DBG("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; - - NFC_DBG("socket [%x], result [%d]", socket, result); - - RET_IF(NULL == user_data); - npp_data = user_data; - - 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) -{ - NFC_DBG("result [%d], data [%p], user_data [%p]", result, data, user_data); - - RET_IF(NULL == data); - RET_IF(NULL == data->buffer); - - 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; - - NFC_DBG("result [%d], data [%p], user_data [%p]", result, data, user_data); - - RET_IF(NULL == user_data); - - npp_client_data = 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) -{ - NppData *npp_data = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == san, FALSE); - RETV_IF(NULL == handle, 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) - { - NFC_ERR("net_nfc_server_llcp_simple_server failed"); - - if (npp_data->callback) - npp_data->callback(result, NULL, npp_data->user_data); - - g_free(npp_data); - - return FALSE; - } - - NFC_DBG("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) -{ - NppData *npp_data; - net_nfc_llcp_config_info_s config; - net_nfc_error_e result = NET_NFC_OK;; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - if(net_nfc_controller_llcp_get_remote_config(handle, &config, &result) == false) - { - NFC_ERR("net_nfc_controller_llcp_get_remote_config failed [%d]", result); - return result; - } - - if (config.miu < data->length + NPP_HEADER_LEN + NPP_ENTITY_HEADER_LEN) - { - NFC_ERR("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) - { - NFC_ERR("net_nfc_server_llcp_simple_client failed"); - - 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) - NFC_DBG("start npp client, san [%s], result [%d]", san, result); - else - NFC_DBG("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; - - NFC_DBG("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) - NFC_ERR("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) -{ - net_nfc_error_e result = NET_NFC_OK; - NppClientStartData *npp_client_data; - - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == data->buffer, 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) - { - NFC_ERR("net_nfc_server_client failed"); - g_free(npp_client_data); - } - - return result; -} diff --git a/daemon/net_nfc_server_process_npp.h b/daemon/net_nfc_server_process_npp.h deleted file mode 100644 index 98b8f89..0000000 --- a/daemon/net_nfc_server_process_npp.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -#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__ diff --git a/daemon/net_nfc_server_process_phdc.c b/daemon/net_nfc_server_process_phdc.c deleted file mode 100755 index 2574d4b..0000000 --- a/daemon/net_nfc_server_process_phdc.c +++ /dev/null @@ -1,912 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "net_nfc_debug_internal.h" -#include "net_nfc_server_tag.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_util.h" -#include "net_nfc_server_process_phdc.h" -#include "net_nfc_server_controller.h" -#include "net_nfc_server_phdc.h" - - - -typedef struct _net_nfc_server_phdc_pdu_t -{ - uint8_t data[128]; -} -__attribute__ ((packed)) net_nfc_server_phdc_pdu_t; - -//callback for internal send/receive -typedef void (*_net_nfc_server_phdc_operation_cb)( - net_nfc_error_e result, - data_s *data, - void *user_param); - -static void _net_nfc_server_phdc_agent_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); - -typedef struct _net_nfc_server_phdc_op_context_t -{ - net_nfc_target_handle_s *handle; - net_nfc_error_e result; - int socket; - uint32_t state; - uint32_t current; - uint16_t miu; - data_s data; - _net_nfc_server_phdc_operation_cb cb; - void *user_param; -}net_nfc_server_phdc_op_context_t; - - -typedef struct _net_nfc_server_phdc_job_t -{ - net_nfc_server_phdc_context_t *context; - net_nfc_target_handle_s *handle; - net_nfc_error_e result; - net_nfc_llcp_socket_t socket; - uint32_t state; - data_s data; - net_nfc_server_phdc_send_cb cb; - void *user_param; -}net_nfc_server_phdc_job_t; - -static void _net_nfc_server_phdc_agent_process( - net_nfc_server_phdc_job_t *job); - -static void _net_nfc_server_phdc_destory_context( - net_nfc_server_phdc_op_context_t *context); - -static void _net_nfc_server_phdc_clear_queue( - gpointer data, - gpointer user_data); - -static void _net_nfc_server_phdc_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); - -static void _net_nfc_server_phdc_recv_cb( - net_nfc_llcp_socket_t socket, - net_nfc_error_e result, - data_s *data, - void *extra, - void *user_param); - -static void _net_nfc_server_phdc_recv( - net_nfc_server_phdc_op_context_t *context); - -static net_nfc_server_phdc_op_context_t* _net_nfc_server_phdc_create_recv_context( - net_nfc_target_handle_s *handle, - net_nfc_llcp_socket_t socket, - void *cb, - void *user_param); - -static void _net_nfc_server_phdc_manager_op_cb( - net_nfc_error_e result, - data_s *data, - void *user_param); - - -static net_nfc_error_e net_nfc_server_phdc_recv( - net_nfc_target_handle_s *handle, - net_nfc_llcp_socket_t socket, - _net_nfc_server_phdc_operation_cb cb, - void *user_param); - -static void _net_nfc_server_phdc_manager_process( - net_nfc_server_phdc_context_t *context); - -static void _net_nfc_server_phdc_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); - - -static void _net_nfc_server_phdc_destory_context(net_nfc_server_phdc_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_phdc_clear_queue(gpointer data,gpointer user_data) -{ - net_nfc_server_phdc_job_t *job = (net_nfc_server_phdc_job_t *)data; - - if (job != NULL) - { - if (job->cb != NULL) - { - job->cb((net_nfc_phdc_handle_h)job->context,NET_NFC_OPERATION_FAIL, - NET_NFC_PHDC_OPERATION_FAILED, 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_phdc_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_phdc_context_t *context = (net_nfc_server_phdc_context_t *)user_param; - - NFC_DBG("_net_nfc_server_phdc_socket_error_cb socket [%x], result [%d]", - socket, result); - - RET_IF(NULL == context); - - if (context->data.buffer != NULL) - net_nfc_util_free_data(&context->data); - - g_queue_foreach(&context->queue, _net_nfc_server_phdc_clear_queue, NULL); - - _net_nfc_util_free_mem(context); -} - - -static void _net_nfc_server_phdc_recv_cb(net_nfc_llcp_socket_t socket, - net_nfc_error_e result, data_s *data, void *extra, void *user_param) -{ - net_nfc_server_phdc_op_context_t *context = - (net_nfc_server_phdc_op_context_t *)user_param; - - uint8_t *buffer = NULL; - uint16_t pdu_length = 0; - - NFC_DBG("_net_nfc_server_phdc_recv_cb, socket[%x], result[%d]", socket, result); - - RET_IF(NULL == context); - - context->result = result; - - if (result != NET_NFC_OK) - { - NFC_ERR("error [%d]", result); - context->state = NET_NFC_STATE_ERROR; - goto END; - } - - if (NULL == data || NULL == data->buffer || 0 == data->length) - { - NFC_ERR("invalid response"); - context->state = NET_NFC_STATE_ERROR; - goto END; - } - - //first 2 bytes is phdc header length - memcpy(&pdu_length,data->buffer,PHDC_HEADER_LEN); - - pdu_length = ntohs(pdu_length); - NFC_INFO("pdu_legth [%d]", pdu_length); - - if(pdu_length > 0) - { - /* buffer create */ - net_nfc_util_alloc_data(&context->data,pdu_length); - if (NULL == context->data.buffer) - { - NFC_ERR("net_nfc_util_alloc_data failed"); - context->result = NET_NFC_ALLOC_FAIL; - goto END; - } - buffer =data->buffer; - context->data.length = data->length - PHDC_HEADER_LEN; - - /* copy data */ - if(context->data.length > 0) - { - memcpy(context->data.buffer ,buffer, context->data.length); - NFC_DBG("receive progress... [%d", context->data.length); - } - } -END: - context->cb(context->result, &context->data, context->user_param); -} - - -static void _net_nfc_server_phdc_recv(net_nfc_server_phdc_op_context_t *context) -{ - RET_IF(NULL == context); - - bool ret; - net_nfc_error_e result; - - NFC_DBG("socket [%x] waiting data.....", context->socket); - - ret = net_nfc_controller_llcp_recv(context->handle, context->socket, context->miu, - &result, _net_nfc_server_phdc_recv_cb, context); - - if(false == ret) - { - NFC_ERR("net_nfc_controller_llcp_recv failed, [%d]", result); - - context->result = result; - context->cb(context->result, &context->data, context->user_param); - - _net_nfc_server_phdc_destory_context(context); - } - -} - - -static net_nfc_server_phdc_op_context_t* _net_nfc_server_phdc_create_recv_context( - net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, void *cb, - void *user_param) -{ - - bool ret; - net_nfc_error_e result; - net_nfc_server_phdc_op_context_t *context = NULL; - net_nfc_llcp_config_info_s config; - - ret = net_nfc_controller_llcp_get_remote_config(handle, &config, &result); - - if(false == ret) - { - NFC_ERR("net_nfc_controller_llcp_get_remote_config failed, [%d]", result); - return NULL; - } - - _net_nfc_util_alloc_mem(context, sizeof(*context)); - - RETV_IF(NULL == context, 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 net_nfc_error_e net_nfc_server_phdc_recv(net_nfc_target_handle_s *handle, - net_nfc_llcp_socket_t socket, _net_nfc_server_phdc_operation_cb cb, - void *user_param) -{ - net_nfc_error_e result; - net_nfc_server_phdc_op_context_t *context = NULL; - - /* create context */ - context = _net_nfc_server_phdc_create_recv_context(handle, socket, cb, user_param); - - if (context != NULL) - { - _net_nfc_server_phdc_recv(context); - result = NET_NFC_OK; - } - else - { - result = NET_NFC_ALLOC_FAIL; - - if (cb != NULL) - cb(result, NULL, user_param); - } - - return result; -} - - -static void _net_nfc_server_phdc_agent_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_phdc_context_t *context = - (net_nfc_server_phdc_context_t *)user_param; - - RET_IF(NULL == context); - - context->socket = socket; - - if (NET_NFC_OK == result) - NFC_DBG("socket [%x] connected. send message", socket); - else - NFC_ERR("connect socket failed, [%d]", result); - - net_nfc_server_phdc_recv(handle, socket, - _net_nfc_server_phdc_manager_op_cb, - context); - - if (context->cb != NULL) - context->cb((net_nfc_phdc_handle_h)context, result, - NET_NFC_PHDC_TARGET_CONNECTED, NULL); - -} - -net_nfc_error_e net_nfc_server_phdc_agent_connect(net_nfc_target_handle_s *handle, - const char *san, sap_t sap, net_nfc_server_phdc_cb cb, void *user_param) -{ - bool ret; - net_nfc_error_e result; - net_nfc_server_phdc_context_t *context = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - - ret = net_nfc_server_target_connected(handle); - - if(FALSE == ret) - return NET_NFC_NOT_CONNECTED; - - _net_nfc_util_alloc_mem(context, sizeof(*context)); - - if (NULL == context) - { - NFC_ERR("_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_phdc_agent_connected_cb, - _net_nfc_server_phdc_socket_error_cb, - context); - - if (result != NET_NFC_OK) - { - NFC_ERR("net_nfc_server_llcp_simple_client failed, [%d]", result); - goto ERROR; - } - - if (san != NULL) - NFC_DBG("start phdc agent san [%s]", san); - else - NFC_DBG("start phdc agent, 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; -} - - -static void _net_nfc_server_phdc_agent_do_job( - net_nfc_server_phdc_context_t *context) -{ - if (context->state == NET_NFC_LLCP_IDLE && g_queue_is_empty(&context->queue) == false) - { - net_nfc_server_phdc_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_phdc_agent_process(job); - } - } -} - -static net_nfc_server_phdc_op_context_t* _net_nfc_server_phdc_create_send_context( - net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, - void *cb, void *user_param) -{ - bool ret; - uint32_t data_len = 0; - uint16_t length; - uint8_t *buffer = NULL; - net_nfc_server_phdc_op_context_t *context = NULL; - net_nfc_llcp_config_info_s config; - net_nfc_error_e result; - - ret = net_nfc_controller_llcp_get_remote_config(handle, - &config, &result); - - if(FALSE == ret) - { - NFC_ERR("net_nfc_controller_llcp_get_remote_config failed, [%d]", result); - return NULL; - } - - _net_nfc_util_alloc_mem(context, sizeof(*context)); - RETV_IF(NULL == context, NULL); - - if (data != NULL) - data_len =data->length; - - if (data_len > 0) - { - net_nfc_util_alloc_data(&context->data,data_len+PHDC_HEADER_LEN); - if (NULL == context->data.buffer) - { - _net_nfc_util_free_mem(context); - return NULL; - } - - length = (uint16_t)data->length; - length +=PHDC_HEADER_LEN; - buffer = context->data.buffer; - - if(data->buffer != NULL) - { - uint16_t network_length = htons(length); - memcpy(buffer,&network_length,PHDC_HEADER_LEN); - buffer+=PHDC_HEADER_LEN; - memcpy(buffer,data->buffer,data->length); - context->data.length = length; - } - } - - context->handle = handle; - 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_phdc_send_cb(net_nfc_llcp_socket_t socket, - net_nfc_error_e result, data_s *data, void *extra, void *user_param) -{ - net_nfc_server_phdc_op_context_t *context = - (net_nfc_server_phdc_op_context_t *)user_param; - - NFC_DBG("_net_nfc_server_phdc_send_cb, socket[%x], result[%d]", socket, result); - - RET_IF(NULL == context); - - context->result = result; - - /* complete and invoke callback */ - context->cb(context->result, NULL, context->user_param); - - _net_nfc_server_phdc_destory_context(context); -} - - -static void _net_nfc_server_phdc_send(net_nfc_server_phdc_op_context_t *context) -{ - bool ret; - data_s req_msg; - net_nfc_error_e result; - - RET_IF(NULL == context); - - req_msg.length = context->data.length; - req_msg.buffer = context->data.buffer; - - NFC_DBG("try to send data, socket [%x]",context->socket); - - ret= net_nfc_controller_llcp_send(context->handle, context->socket, - &req_msg, &result, _net_nfc_server_phdc_send_cb, context); - - if(FALSE == ret) - { - NFC_ERR("net_nfc_controller_llcp_send failed, [%d]",result); - context->result = result; - - context->cb(context->result, NULL, context->user_param); - _net_nfc_server_phdc_destory_context(context); - } -} - -static void _net_nfc_server_phdc_agent_send_cb(net_nfc_error_e result,data_s *data, - void *user_param) -{ - net_nfc_server_phdc_job_t*job = (net_nfc_server_phdc_job_t *)user_param; - - RET_IF(NULL == job); - - job->result = result; - - if (NET_NFC_OK ==result) - { - job->state = NET_NFC_LLCP_STEP_RETURN; - net_nfc_util_free_data(&job->data); - } - else - { - NFC_ERR("net_nfc_server_phdc_send failed, [%d]", result); - job->state = NET_NFC_STATE_ERROR; - } - - _net_nfc_server_phdc_agent_process(job); -} - - -net_nfc_error_e net_nfc_server_phdc_send(net_nfc_target_handle_s *handle, - net_nfc_llcp_socket_t socket, data_s *data, _net_nfc_server_phdc_operation_cb cb, - void *user_param) -{ - net_nfc_error_e result; - net_nfc_server_phdc_op_context_t *context = NULL; - - /* create context */ - context = _net_nfc_server_phdc_create_send_context(handle, socket,data, - cb, user_param); - - if (context != NULL) - { - /* send data */ - _net_nfc_server_phdc_send(context); - result = NET_NFC_OK; - } - else - { - NFC_ERR("_net_nfc_server_phdc_create_send_context failed"); - result = NET_NFC_ALLOC_FAIL; - - if (cb != NULL) - cb(result, NULL, user_param); - } - - return result; -} - -static void _net_nfc_server_phdc_agent_process(net_nfc_server_phdc_job_t *job) -{ - bool finish = false; - - RET_IF(NULL == job); - - switch (job->state) - { - case NET_NFC_LLCP_STEP_01 : - NFC_DBG("NET_NFC_LLCP_STEP_01"); - - /* send request */ - net_nfc_server_phdc_send(job->handle, job->socket, &job->data, - _net_nfc_server_phdc_agent_send_cb, job); - break; - - case NET_NFC_LLCP_STEP_RETURN : - NFC_DBG("NET_NFC_LLCP_STEP_RETURN"); - - /* complete and invoke callback */ - if (job->cb != NULL) - { - job->cb((net_nfc_phdc_handle_h)job->context, NET_NFC_OK, - NET_NFC_PHDC_DATA_RECEIVED, job->user_param); - } - /* finish job */ - finish = true; - break; - - case NET_NFC_STATE_ERROR : - default : - NFC_ERR("NET_NFC_STATE_ERROR"); - - /* error, invoke callback */ - NFC_ERR("phdc_agent_send failed, [%d]", job->result); - if (job->cb != NULL) - { - job->cb((net_nfc_phdc_handle_h)job->context, job->result, - NET_NFC_PHDC_OPERATION_FAILED, job->user_param); - } - /* finish job */ - finish = TRUE; - break; - } - - if (TRUE == finish) - { - net_nfc_server_phdc_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_phdc_agent_do_job(context); - } -} - - -net_nfc_error_e net_nfc_server_phdc_agent_request(net_nfc_phdc_handle_h handle, - data_s *data, net_nfc_server_phdc_send_cb cb, void *user_param) -{ - bool ret; - net_nfc_error_e result = NET_NFC_OK; - net_nfc_server_phdc_job_t *job = NULL; - net_nfc_server_phdc_context_t *context = (net_nfc_server_phdc_context_t *)handle; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == data->buffer, NET_NFC_NULL_PARAMETER); - - ret =net_nfc_server_target_connected(context->handle); - - if(FALSE == ret) - return NET_NFC_NOT_CONNECTED; - - /* 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->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; - - NFC_INFO("enqueued jobs [%d]", g_queue_get_length(&context->queue)); - - /* if agent is idle, starts sending request */ - if (context->state == NET_NFC_LLCP_IDLE) - _net_nfc_server_phdc_agent_do_job(context); - else - NFC_INFO("agent is working. this job will be enqueued"); - - return result; -} - - -net_nfc_error_e net_nfc_server_phdc_agent_start(net_nfc_target_handle_s *handle, - const char *san, sap_t sap, net_nfc_server_phdc_cb cb, void *user_param) -{ - net_nfc_error_e result; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == san, NET_NFC_NULL_PARAMETER); - - /* start PHDC Agent, register your callback */ - result = net_nfc_server_phdc_agent_connect(handle, san, sap, - cb, user_param); - - if (result != NET_NFC_OK) - { - NFC_ERR("net_nfc_server_phdc_agent_connect failed, [%d]",result); - } - return result; -} - -static void _net_nfc_server_phdc_manager_op_cb( net_nfc_error_e result, data_s *data, - void *user_param) -{ - net_nfc_server_phdc_context_t *context = - (net_nfc_server_phdc_context_t *)user_param; - - NFC_DBG("_net_nfc_server_phdc_manager_op_cb result [%d]", result); - - RET_IF(NULL == context); - - context->result = result; - if (NET_NFC_OK == result && data != NULL && data->buffer != NULL) - { - NFC_DBG("received message, length [%d]", data->length); - - net_nfc_util_alloc_data(&context->data, data->length); - if (context->data.buffer != NULL) - { - memcpy(context->data.buffer,data->buffer, data->length); - context->state = NET_NFC_LLCP_STEP_02; - } - else - { - NFC_ERR("net_nfc_util_alloc_data failed"); - context->state = NET_NFC_STATE_ERROR; - context->result = NET_NFC_ALLOC_FAIL; - } - } - else - { - NFC_ERR("net_nfc_server_phdc_recv failed, [%d]", result); - context->state = NET_NFC_STATE_ERROR; - } - - _net_nfc_server_phdc_manager_process(context); - -} - - -static void _net_nfc_server_phdc_manager_process( - net_nfc_server_phdc_context_t *context) -{ - bool finish = false; - RET_IF(NULL == context); - - switch (context->state) - { - case NET_NFC_LLCP_STEP_01 : - NFC_INFO("NET_NFC_LLCP_STEP_01 "); - /*receive the Agent data*/ - net_nfc_server_phdc_recv( context->handle,context->socket, - _net_nfc_server_phdc_manager_op_cb, context); - break; - case NET_NFC_LLCP_STEP_02 : - NFC_INFO("NET_NFC_LLCP_STEP_02"); - if (context->cb != NULL) - { - /* complete operation and invoke the callback*/ - context->cb((net_nfc_phdc_handle_h)context,NET_NFC_OK, - NET_NFC_PHDC_DATA_RECEIVED, &context->data); - } - finish = true; - break; - case NET_NFC_STATE_ERROR : - NFC_INFO("NET_NFC_STATE_ERROR"); - default : - if (context->cb != NULL) - { - context->cb((net_nfc_phdc_handle_h)context,context->result, - NET_NFC_PHDC_OPERATION_FAILED,&context->data); - } - return; - break; - } - - if(true == finish) - { - context->state = NET_NFC_LLCP_IDLE; - - net_nfc_server_phdc_recv(context->handle, - context->socket, - _net_nfc_server_phdc_manager_op_cb, - context); - - } -} - - -static void _net_nfc_server_phdc_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_phdc_context_t *context = - (net_nfc_server_phdc_context_t *)user_param; - - net_nfc_server_phdc_context_t *accept_context = NULL; - - RET_IF(NULL == context); - - NFC_DBG("phdc incoming socket [%x], result [%d]", socket, result); - - if (result != NET_NFC_OK) - { - NFC_ERR("listen socket failed, [%d]", result); - goto ERROR; - } - - _net_nfc_util_alloc_mem(accept_context, sizeof(*accept_context)); - - if (NULL == accept_context) - { - NFC_ERR("_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_phdc_socket_error_cb, accept_context); - - if (result != NET_NFC_OK) - { - NFC_ERR("net_nfc_server_llcp_simple_accept failed, [%d]",result); - goto ERROR; - } - - NFC_DBG("socket [%x] accepted.. waiting for request message", socket); - - accept_context->cb((net_nfc_phdc_handle_h)accept_context, result, - NET_NFC_PHDC_TARGET_CONNECTED, data); - - _net_nfc_server_phdc_manager_process(accept_context); - - return; -ERROR : - if (accept_context != NULL) - { - _net_nfc_util_free_mem(accept_context); - } -} - -net_nfc_error_e net_nfc_server_phdc_manager_start(net_nfc_target_handle_s *handle, - const char *san, sap_t sap, net_nfc_server_phdc_cb cb, void *user_param) -{ - bool ret; - net_nfc_error_e result; - net_nfc_server_phdc_context_t *context = NULL; - - RETV_IF(NULL == handle, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == san, NET_NFC_NULL_PARAMETER); - - ret = net_nfc_server_target_connected(handle); - - if(FALSE == ret) - return NET_NFC_NOT_CONNECTED; - - _net_nfc_util_alloc_mem(context, sizeof(*context)); - if(NULL == context) - { - NFC_ERR("_create_phdc_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; - - if(!strcmp(san,PHDC_SAN)) - { - /*Handle the default PHDC SAN*/ - result = net_nfc_server_llcp_simple_server(handle, san,sap, - _net_nfc_server_phdc_incoming_cb,_net_nfc_server_phdc_socket_error_cb, - context); - } - else - { - /*Handle other SAN, Implement as and when needed.*/ - result = NET_NFC_NOT_SUPPORTED; - } - - if (result != NET_NFC_OK) - { - NFC_ERR("net_nfc_server_llcp_simple_server failed, [%d]",result); - goto ERROR; - } - - NFC_DBG("start phdc manager, san [%s], sap [%d]", san, sap); - return result; - -ERROR : - if (context != NULL) - _net_nfc_util_free_mem(context); - - return result; -} - -/////////////////////////////////////////////////////////////////// - diff --git a/daemon/net_nfc_server_process_phdc.h b/daemon/net_nfc_server_process_phdc.h deleted file mode 100755 index 7e34d9d..0000000 --- a/daemon/net_nfc_server_process_phdc.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_PHDC_H__ -#define __NET_NFC_SERVER_PROCESS_PHDC_H__ - -#include "net_nfc_gdbus.h" -#include "net_nfc_typedef_internal.h" - -#define PHDC_SAP 0x16 -#define PHDS_SAP 0x17 -#define PHDC_SAN "urn:nfc:sn:phdc" -#define PHDS_SAN "urn:nfc:sn:phds" -#define PHDC_HEADER_LEN 2 - -typedef enum -{ - NET_NFC_PHDC_OPERATION_FAILED = 0, - NET_NFC_PHDC_TARGET_CONNECTED , - NET_NFC_PHDC_DATA_RECEIVED -}net_nfc_server_phdc_indication_type; - - -//callback for manager connection accept / agent connect -typedef void (*net_nfc_server_phdc_cb)(net_nfc_phdc_handle_h handle, - net_nfc_error_e result, net_nfc_server_phdc_indication_type indication, data_s *data); - -//callback for data send -typedef gboolean (*net_nfc_server_phdc_send_cb)(net_nfc_phdc_handle_h handle, - net_nfc_error_e result, net_nfc_server_phdc_indication_type indication, gpointer *user_data); - -typedef struct _net_nfc_server_phdc_context_t net_nfc_server_phdc_context_t; - -struct _net_nfc_server_phdc_context_t -{ - net_nfc_target_handle_s *handle; - net_nfc_error_e result; - net_nfc_llcp_socket_t socket; - uint32_t state; - data_s data; - net_nfc_server_phdc_cb cb; - void *user_param; - GQueue queue; -}; - -net_nfc_error_e net_nfc_server_phdc_manager_start(net_nfc_target_handle_s *handle, - const char *san, sap_t sap, net_nfc_server_phdc_cb cb, void *user_param); - -net_nfc_error_e net_nfc_server_phdc_agent_start(net_nfc_target_handle_s *handle, - const char *san, sap_t sap, net_nfc_server_phdc_cb cb, void *user_param); - -net_nfc_error_e net_nfc_server_phdc_agent_request(net_nfc_phdc_handle_h handle, - data_s *data, net_nfc_server_phdc_send_cb cb, void *user_param); - - -#endif//__NET_NFC_SERVER_PROCESS_PHDC_H__ - diff --git a/daemon/net_nfc_server_process_snep.c b/daemon/net_nfc_server_process_snep.c deleted file mode 100644 index c86ba9f..0000000 --- a/daemon/net_nfc_server_process_snep.c +++ /dev/null @@ -1,2078 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "net_nfc_debug_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_tag.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_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 - { - NFC_ERR("g_list_append failed"); - } - } - else - { - NFC_ERR("_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) - { - NFC_DBG("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) - { - NFC_ERR("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) - { - NFC_DBG("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) - { - NFC_ERR("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; - - NFC_DBG("_net_nfc_server_recv_fragment_cb, socket[%x], result[%d]", socket, result); - - if (context == NULL) - return; - - context->result = result; - - if (result != NET_NFC_OK) - { - NFC_ERR("error [%d]", result); - context->state = NET_NFC_STATE_ERROR; - goto END; - } - - if (data == NULL || data->buffer == NULL || data->length == 0) - { - NFC_ERR("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) - { - NFC_ERR("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) - { - NFC_ERR("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) - { - NFC_ERR("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) - { - NFC_ERR("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; - } - } - - NFC_DBG("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; - - NFC_DBG("receive progress... [%d|%d]", context->offset, context->data.length); - - if (context->offset >= context->data.length) - context->state = NET_NFC_LLCP_STEP_RETURN; - - } - else - { - NFC_DBG("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; - - NFC_DBG("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) - { - NFC_ERR("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; - - NFC_DBG("_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 - { - NFC_ERR("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; - - NFC_DBG("_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) - { - NFC_ERR("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 : - NFC_DBG("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; - - NFC_DBG("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 : - { - NFC_DBG("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 : - { - NFC_DBG("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 : - NFC_ERR("NET_NFC_STATE_ERROR"); - - /* error, invoke callback */ - NFC_ERR("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; - - /* 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); - result = NET_NFC_OK; - } else { - result = NET_NFC_ALLOC_FAIL; - - if (cb != NULL) { - cb(result, -1, NULL, user_param); - } - } - - 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; - - NFC_DBG("_net_nfc_server_send_fragment_cb, socket[%x], result[%d]", socket, result); - - if (context == NULL) - return; - - context->result = result; - - if (result == NET_NFC_OK) - { - NFC_DBG("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 - { - NFC_ERR("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; - - NFC_DBG("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) - { - NFC_ERR("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; - - NFC_DBG("_net_nfc_server_snep_send_recv_cb, result [%d]", result); - - if (context == NULL)/* TODO */ - return; - - NFC_DBG("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 : - NFC_DBG("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 : - NFC_DBG("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 : - NFC_DBG("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 : - NFC_ERR("NET_NFC_STATE_ERROR"); - - /* error, invoke callback */ - NFC_ERR("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 : - NFC_ERR("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; - - /* 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); - result = NET_NFC_OK; - } - else - { - NFC_ERR("_net_nfc_server_snep_create_send_context failed"); - - result = NET_NFC_ALLOC_FAIL; - - if (cb != NULL) { - cb(result, type, NULL, user_param); - } - } - - 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; - - NFC_DBG("_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) - { - NFC_DBG("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 : - NFC_ERR("invalid request, [%d]", type); - context->state = NET_NFC_STATE_ERROR; - context->result = NET_NFC_NOT_ALLOWED_OPERATION; - break; - } - } - else - { - NFC_ERR("net_nfc_util_alloc_data failed"); - /* TODO */ - context->state = NET_NFC_STATE_ERROR; - context->result = NET_NFC_ALLOC_FAIL; - } - } - else - { - NFC_ERR("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; - - NFC_DBG("_net_nfc_server_snep_server_send_cb, result [%d]", result); - - if (context == NULL)/* TODO */ - return; - - context->result = result; - - if (result == NET_NFC_OK) - { - NFC_DBG("server process success. and restart...."); - - /* restart */ - net_nfc_util_free_data(&context->data); - context->state = NET_NFC_LLCP_STEP_01; - } - else - { - NFC_ERR("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 : - NFC_DBG("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 : - NFC_DBG("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 */ - NFC_ERR("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 : - NFC_DBG("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 : - NFC_DBG("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 : - NFC_DBG("NET_NFC_STATE_ERROR"); - - /* error, invoke callback */ - NFC_ERR("_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 : - NFC_ERR("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; - - NFC_DBG("_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; - - NFC_DBG("_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; - } - - NFC_DBG("snep incoming socket [%x], result [%d]", socket, result); - - if (result != NET_NFC_OK) - { - NFC_ERR("listen socket failed, [%d]", result); - - goto ERROR; - } - - /* start snep server */ - _net_nfc_util_alloc_mem(accept_context, sizeof(*accept_context)); - - if (accept_context == NULL) - { - NFC_ERR("_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) - { - NFC_ERR("net_nfc_server_llcp_simple_accept failed, [%d]", - result); - goto ERROR; - } - - NFC_DBG("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); - } -} - -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; - } - - if (net_nfc_server_target_connected(handle) == false) { - return NET_NFC_NOT_CONNECTED; - } - - _net_nfc_util_alloc_mem(context, sizeof(*context)); - if (context == NULL) - { - NFC_ERR("_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) - { - NFC_ERR("net_nfc_server_llcp_simple_server failed, [%d]", - result); - goto ERROR; - } - - NFC_DBG("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_server_snep_context_t *snep_handle, data_s *data) -{ - net_nfc_error_e result = NET_NFC_OK; - - if (snep_handle == NULL/* && check valid handle */) - { - NFC_ERR("invalid handle"); - return NET_NFC_INVALID_PARAM; - } - - if (net_nfc_server_target_connected(snep_handle->handle) == false) { - return NET_NFC_NOT_CONNECTED; - } - - NFC_DBG("send get response, socket [%x]", snep_handle->socket); - - /* check correct status */ - if (snep_handle->type == SNEP_REQ_GET) - { - if (snep_handle->data.buffer != NULL) - net_nfc_util_free_data(&snep_handle->data); - - if (data != NULL) - { - snep_handle->type = SNEP_RESP_SUCCESS; - - if (net_nfc_util_alloc_data(&snep_handle->data, data->length) == true) - { - memcpy(snep_handle->data.buffer, data->buffer, - data->length); - } - else - { - NFC_ERR("net_nfc_util_alloc_data failed"); - result = NET_NFC_ALLOC_FAIL; - } - } - else - { - /* not found */ - snep_handle->type = SNEP_RESP_NOT_FOUND; - } - - _net_nfc_server_snep_server_process(snep_handle); - } - else - { - NFC_ERR("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 - { - NFC_ERR("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 - { - NFC_ERR("net_nfc_util_alloc_data failed"); - job->state = NET_NFC_STATE_ERROR; - job->result = NET_NFC_ALLOC_FAIL; - } - } - } - else - { - /* TODO */ - NFC_ERR("invalid request, [0x%x]", type); - job->state = NET_NFC_STATE_ERROR; - job->result = NET_NFC_NOT_ALLOWED_OPERATION; - } - } - else - { - - NFC_ERR("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 : - NFC_DBG("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 : - NFC_DBG("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 : - NFC_DBG("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 : - NFC_ERR("NET_NFC_STATE_ERROR"); - - /* error, invoke callback */ - NFC_ERR("_snep_client_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 */ - NFC_DBG("socket [%x] connected. send message", socket); - } - else - { - NFC_ERR("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; - } - - if (net_nfc_server_target_connected(handle) == false) { - return NET_NFC_NOT_CONNECTED; - } - - _net_nfc_util_alloc_mem(context, sizeof(*context)); - if (context == NULL) - { - NFC_ERR("_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) - { - NFC_ERR("net_nfc_server_llcp_simple_client failed, [%d]", result); - - goto ERROR; - } - if (san != NULL) - NFC_DBG("start snep client, san [%s]", san); - else - NFC_DBG("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_server_snep_context_t *snep, - uint8_t type, - data_s *data, - net_nfc_server_snep_cb cb, - void *user_param) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_server_snep_job_t *job; - - if (snep == NULL || data == NULL || data->buffer == NULL) - { - return NET_NFC_NULL_PARAMETER; - } - - if (net_nfc_server_target_connected(snep->handle) == false) { - return NET_NFC_NOT_CONNECTED; - } - - /* 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 = snep; - job->handle = snep->handle; - job->socket = snep->socket; - - g_queue_push_tail(&snep->queue, job); - } - else - { - return NET_NFC_ALLOC_FAIL; - } - - NFC_INFO("enqueued jobs [%d]", g_queue_get_length(&snep->queue)); - - /* if client is idle, starts sending request */ - if (snep->state == NET_NFC_LLCP_IDLE) - { - _net_nfc_server_snep_client_do_job(snep); - } else { - NFC_INFO("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) -{ - NFC_DBG("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)}; - - NFC_DBG("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 : - NFC_ERR("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; - - NFC_DBG("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); - break; - - default : - NFC_ERR("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; - - NFC_DBG("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) - { - result = 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_server_snep_context_t *snep, data_s *data) -{ - net_nfc_error_e result = NET_NFC_OK; - - if (snep == NULL/* && check valid handle */) - { - NFC_ERR("invalid handle"); - return NET_NFC_INVALID_PARAM; - } - - /* check correct status */ - if (snep->type == SNEP_REQ_GET && - snep->state == NET_NFC_LLCP_STEP_03) - { - net_nfc_server_snep_server_send_get_response(snep, data); - } - else - { - NFC_ERR("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; - - NFC_DBG("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) { - NFC_ERR("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); - - NFC_DBG("GET : acceptable max_len [%d], message [%d]", - *max_len, request->length - sizeof(msg->length)); - - return NET_NFC_OK; -} diff --git a/daemon/net_nfc_server_process_snep.h b/daemon/net_nfc_server_process_snep.h deleted file mode 100644 index 873b7c2..0000000 --- a/daemon/net_nfc_server_process_snep.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 struct _net_nfc_server_snep_context_t net_nfc_server_snep_context_t; - -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); - -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_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_server_snep_context_t *snep_handle, data_s *data); - -net_nfc_error_e net_nfc_server_snep_client_request( - net_nfc_server_snep_context_t *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_server_snep_context_t *snep, 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 diff --git a/daemon/net_nfc_server_se.c b/daemon/net_nfc_server_se.c deleted file mode 100644 index ec798fd..0000000 --- a/daemon/net_nfc_server_se.c +++ /dev/null @@ -1,1343 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include - -#include "net_nfc_typedef_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_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" - -enum -{ - SE_UICC_UNAVAILABLE = -1, - SE_UICC_ON_PROGRESS = 0, - SE_UICC_READY = 1, -}; - -typedef struct _nfc_se_setting_t -{ - bool busy; - uint8_t type; - uint8_t return_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; - -static int gdbus_uicc_ready; - -/* server_side */ -typedef struct _ServerSeData ServerSeData; - -struct _ServerSeData -{ - data_s aid; - data_s param; - guint event; -}; - -typedef struct _SeSetCardEmul SeSetCardEmul; - -struct _SeSetCardEmul -{ - NetNfcGDbusSecureElement *object; - GDBusMethodInvocation *invocation; - gint mode; -}; - -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; -}; - -typedef struct _ChangeCardEmulMode ChangeCardEmulMode; - -struct _ChangeCardEmulMode -{ - NetNfcGDbusSecureElement *object; - GDBusMethodInvocation *invocation; - gint mode; -}; - -uint8_t net_nfc_server_se_get_se_type() -{ - return gdbus_se_setting.type; -} - -uint8_t net_nfc_server_se_get_return_se_mode() -{ - return gdbus_se_setting.return_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.return_type = gdbus_se_setting.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() -{ - bool ret; - - if (NULL == gdbus_ese_handle) - { - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - - ret = net_nfc_controller_secure_element_open(SECURE_ELEMENT_TYPE_ESE, - &handle, &result); - if (true == ret) - { - net_nfc_server_se_set_current_ese_handle(handle); - - NFC_DBG("handle [%p]", handle); - } - else - { - NFC_ERR("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; -} - -static void _se_uicc_enable_card_emulation() -{ - net_nfc_error_e result; - - /*turn off ESE*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, - SECURE_ELEMENT_OFF_MODE, &result); - - /*turn on UICC*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, - SECURE_ELEMENT_VIRTUAL_MODE, &result); - - if (NET_NFC_OK == result) - { - NFC_INFO("card emulation 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) - NFC_ERR("vconf_set_int failed"); - } - else - { - NFC_ERR("net_nfc_controller_set_secure_element_mode failed, [%d]", result); - } -} - -static void _se_uicc_prepare(void) -{ - char **cpList; - - cpList = tel_get_cp_name_list(); - if (cpList != NULL) - { - gdbus_uicc_handle = tel_init(cpList[0]); - if (NULL == gdbus_uicc_handle) - NFC_ERR("tel_init() failed"); - - } - else - { - NFC_ERR("tel_get_cp_name_list() failed"); - } -} - -static void _se_uicc_status_noti_cb(TapiHandle *handle, - const char *noti_id, void *data, void *user_data) -{ - TelSimCardStatus_t *status = data; - - NFC_DBG("_se_uicc_status_noti_cb"); - - switch (*status) - { - case TAPI_SIM_STATUS_SIM_INIT_COMPLETED : - gdbus_uicc_ready = SE_UICC_READY; - - _se_uicc_prepare(); - - if (gdbus_se_setting.busy == true && - net_nfc_server_se_get_se_type() == SECURE_ELEMENT_TYPE_UICC) - { - gdbus_se_setting.busy = false; - - _se_uicc_enable_card_emulation(); - } - break; - - case TAPI_SIM_STATUS_CARD_REMOVED : - NFC_DBG("TAPI_SIM_STATUS_CARD_REMOVED"); - gdbus_uicc_ready = SE_UICC_UNAVAILABLE; - - if (net_nfc_server_se_get_se_type() == SECURE_ELEMENT_TYPE_UICC) - { - net_nfc_error_e result; - - /*turn off UICC*/ - 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_INVALID); - net_nfc_server_se_set_se_mode(SECURE_ELEMENT_OFF_MODE); - } - break; - - default: - break; - } -} - -static void _se_uicc_init(void) -{ - _se_uicc_prepare(); - tel_register_noti_event(gdbus_uicc_handle, TAPI_NOTI_SIM_STATUS, - _se_uicc_status_noti_cb, NULL); -} - -static void _se_uicc_deinit() -{ - if (gdbus_uicc_handle != NULL) - { - 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() -{ - net_nfc_target_handle_s *result = NULL; - - if (gdbus_uicc_ready == SE_UICC_READY && gdbus_uicc_handle != NULL) - 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_ready == SE_UICC_READY && 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_disable_card_emulation() -{ - int ret; - net_nfc_error_e result; - - 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); - - /*turn off UICC*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, - SECURE_ELEMENT_OFF_MODE, &result); - - ret = vconf_set_int(VCONFKEY_NFC_SE_TYPE, VCONFKEY_NFC_SE_TYPE_NONE); - - if (ret != 0) - { - NFC_ERR("vconf_set_int is failed, error type : %d", ret); - return NET_NFC_UNKNOWN_ERROR; - } - - return result; - -} - -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 (false == gdbus_se_setting.busy) - { - if (SE_UICC_READY == gdbus_uicc_ready) - { - _se_uicc_enable_card_emulation(); - } - else if (SE_UICC_ON_PROGRESS == gdbus_uicc_ready) - { - NFC_INFO("waiting for uicc initializing complete..."); - - gdbus_se_setting.busy = true; - result = NET_NFC_OPERATION_FAIL; - } - else - { - result = NET_NFC_NOT_SUPPORTED; - } - } - else - { - NFC_DBG("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 (NET_NFC_OK == result) - { - NFC_INFO("card emulation 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) - NFC_ERR("vconf_set_int failed"); - } - else - { - NFC_ERR("net_nfc_controller_set_secure_element_mode failed, [%d]", result); - } - break; - - default: - result = net_nfc_server_se_disable_card_emulation(); - if (NET_NFC_OK == result) - { - NFC_INFO("card emulation turned off"); - - if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, VCONFKEY_NFC_SE_TYPE_NONE) != 0) - NFC_ERR("vconf_set_int failed"); - } - break; - } - - return result; -} - -static void se_close_secure_element_thread_func(gpointer user_data) -{ - net_nfc_error_e result; - SeDataHandle *detail = user_data; - - 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_server_controller_deinit(); - } -} - -static gboolean se_handle_close_secure_element( - NetNfcGDbusSecureElement *object, - GDBusMethodInvocation *invocation, - guint arg_handle, - GVariant *smack_privilege) -{ - bool ret; - gboolean result; - SeDataHandle *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(SeDataHandle, 1); - if (NULL == data) - { - NFC_ERR("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 = GUINT_TO_POINTER(arg_handle); - - result = net_nfc_server_controller_async_queue_push( - se_close_secure_element_thread_func, data); - if (FALSE == result) - { - 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) -{ - GVariant *data; - data_s *atr = NULL; - SeDataHandle *detail = user_data; - net_nfc_error_e result = NET_NFC_OK; - - 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 - { - NFC_ERR("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) -{ - bool ret; - gboolean result; - SeDataHandle *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager", "r"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(SeDataHandle, 1); - if (NULL == data) - { - NFC_ERR("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 = GUINT_TO_POINTER(arg_handle); - - result = net_nfc_server_controller_async_queue_push(se_get_atr_thread_func, data); - if (FALSE == result) - { - 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 = user_data; - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - - 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 = _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 - NFC_DBG("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) -{ - bool ret; - gboolean result; - SeDataSeType *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(SeDataSeType, 1); - if (NULL == data) - { - NFC_ERR("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 (FALSE == result) - { - 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) -{ - data_s *response = NULL; - GVariant *rspdata = NULL; - SeDataApdu *detail = user_data; - data_s apdu_data = { NULL, 0 }; - net_nfc_error_e result = NET_NFC_OK; - - 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) - { - 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) -{ - bool ret; - gboolean result; - SeDataApdu *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(SeDataApdu, 1); - if (NULL == data) - { - NFC_ERR("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 = GUINT_TO_POINTER(arg_handle); - data->data = g_variant_ref(apdudata); - - result = net_nfc_server_controller_async_queue_push(se_send_apdu_thread_func, data); - if (FALSE == result) - { - 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 = 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); - - if(NET_NFC_OK == result) - 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) -{ - bool ret; - gboolean result; - SeDataSeType *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager", "w"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(SeDataSeType, 1); - if (NULL == data) - { - NFC_ERR("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 (FALSE == result) - { - 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_data_thread_func(gpointer user_data) -{ - SeDataSeType *data = user_data; - net_nfc_error_e result = NET_NFC_OK; - - g_assert(data != NULL); - g_assert(data->object != NULL); - g_assert(data->invocation != NULL); - - net_nfc_gdbus_secure_element_complete_get(data->object, data->invocation, - net_nfc_server_se_get_se_type(), result); - - g_object_unref(data->invocation); - g_object_unref(data->object); - - g_free(data); -} - -static gboolean se_handle_get(NetNfcGDbusSecureElement *object, - GDBusMethodInvocation *invocation, GVariant *smack_privilege) -{ - bool ret; - gboolean result; - SeDataSeType *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager", "r"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(SeDataSeType, 1); - if (NULL == data) - { - NFC_ERR("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); - - result = net_nfc_server_controller_async_queue_push(se_get_data_thread_func, data); - if (FALSE == result) - { - 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_change_card_emulation_mode_thread_func(gpointer user_data) -{ - bool isChanged = false; - net_nfc_error_e result = NET_NFC_OK; - uint8_t current_mode, return_mode; - ChangeCardEmulMode *data = (ChangeCardEmulMode *)user_data; - - g_assert(data != NULL); - g_assert(data->object != NULL); - g_assert(data->invocation != NULL); - - current_mode = net_nfc_server_se_get_se_mode(); - - if(data->mode == SECURE_ELEMENT_ACTIVE_STATE - && current_mode == SECURE_ELEMENT_TYPE_INVALID) - { - return_mode = net_nfc_server_se_get_return_se_mode(); - - if(SECURE_ELEMENT_TYPE_INVALID == return_mode) - { - result = NET_NFC_OPERATION_FAIL; - } - else - { - result = net_nfc_server_se_change_se(return_mode); - isChanged = true; - } - } - else if(data->mode == SECURE_ELEMENT_INACTIVE_STATE - && current_mode != SECURE_ELEMENT_TYPE_INVALID) - { - result = net_nfc_server_se_disable_card_emulation(); - isChanged = true; - } - - net_nfc_gdbus_secure_element_complete_change_card_emulation_mode(data->object, - data->invocation, result); - - if(isChanged) - { - net_nfc_gdbus_secure_element_emit_card_emulation_mode_changed(data->object, - data->mode); - } - - g_object_unref(data->invocation); - g_object_unref(data->object); - - g_free(data); -} - - -static gboolean se_handle_change_card_emulation_mode( - NetNfcGDbusSecureElement *object, - GDBusMethodInvocation *invocation, - gint arg_mode, - GVariant *smack_privilege) -{ - bool ret; - gboolean result; - SeSetCardEmul *data; - - NFC_DBG(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager", "w"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_try_new0(ChangeCardEmulMode, 1); - if (NULL == data) - { - NFC_ERR("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->mode = arg_mode; - - result = net_nfc_server_controller_async_queue_push( - _se_change_card_emulation_mode_thread_func, data); - if (FALSE == result) - { - 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) -{ - gboolean result; - GError *error = NULL; - - 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-get", G_CALLBACK(se_handle_get), NULL); - - g_signal_connect(se_skeleton, "handle-set-card-emulation", - G_CALLBACK(se_handle_change_card_emulation_mode), 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 (FALSE == result) - { - NFC_ERR("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) -{ - uint32_t devType = 0; - GVariant *data = NULL; - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - - g_assert(user_data != NULL); - - if (NULL == se_skeleton) - { - NFC_ERR("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); - - NFC_DBG("trying to connect to ESE = [0x%p]", handle); - - if (!net_nfc_controller_connect(handle, &result)) - NFC_DBG("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) -{ - bool fg_dispatch; - pid_t focus_app_pid; - ServerSeData *detail = user_data; - - - g_assert(user_data != NULL); - - if (detail->event == NET_NFC_MESSAGE_SE_START_TRANSACTION) - { - GVariant *aid = NULL; - GVariant *param = NULL; - uint8_t se_type; - - NFC_DBG("launch se app"); - - aid = net_nfc_util_gdbus_data_to_variant(&(detail->aid)); - param = net_nfc_util_gdbus_data_to_variant(&(detail->param)); - se_type = net_nfc_server_se_get_se_type(); - focus_app_pid = net_nfc_app_util_get_focus_app_pid(); - fg_dispatch = net_nfc_app_util_check_launch_state(); - - /* TODO : check access control */ - net_nfc_gdbus_secure_element_emit_transaction_event ( - se_skeleton, - se_type, - aid, - param, - fg_dispatch, - focus_app_pid); - - net_nfc_app_util_launch_se_transaction_app( - se_type, - detail->aid.buffer, - detail->aid.length, - detail->param.buffer, - detail->param.length); - - NFC_DBG("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) -{ - gboolean ret; - GVariant *data; - GVariant *parameter; - net_nfc_request_target_detected_t *se_target = - (net_nfc_request_target_detected_t *)info; - - 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) - { - ret = net_nfc_server_controller_async_queue_push(se_detected_thread_func, - parameter); - if (FALSE == ret) - { - NFC_ERR("can not push to controller thread"); - - g_variant_unref(parameter); - } - } - else - { - NFC_ERR("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) -{ - gboolean ret; - ServerSeData *detail; - net_nfc_request_se_event_t *se_event = (net_nfc_request_se_event_t *)info; - - detail = g_try_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); - } - - ret = net_nfc_server_controller_async_queue_push( - se_transcation_thread_func, detail); - if (FALSE == ret) - { - NFC_ERR("can not push to controller thread"); - - net_nfc_util_free_data(&detail->param); - net_nfc_util_free_data(&detail->aid); - - g_free(detail); - } - } - else - { - NFC_ERR("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); -} diff --git a/daemon/net_nfc_server_se.h b/daemon/net_nfc_server_se.h deleted file mode 100644 index ddc30b6..0000000 --- a/daemon/net_nfc_server_se.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -#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); - -net_nfc_error_e net_nfc_server_se_disable_card_emulation(); - -/***************************************************************/ - -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__ diff --git a/daemon/net_nfc_server_snep.c b/daemon/net_nfc_server_snep.c deleted file mode 100644 index fb678c2..0000000 --- a/daemon/net_nfc_server_snep.c +++ /dev/null @@ -1,918 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "net_nfc_debug_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" - -/* 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) -{ - gboolean ret; - char *client_id; - void *user_data; - GVariant *arg_data; - GError *error = NULL; - GDBusConnection *connection; - - g_variant_get(parameter, "(usu)", (guint *)&connection, &client_id, - (guint *)&user_data); - - arg_data = net_nfc_util_gdbus_data_to_variant(data); - - ret = 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); - if (false == ret) - { - if (error != NULL && error->message != NULL) - NFC_ERR("g_dbus_connection_emit_signal failed : %s", error->message); - else - NFC_ERR("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) -{ - data_s *temp = data; - GVariant *parameter = (GVariant *)user_param; - - NFC_DBG("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 : - NFC_ERR("error [%d]", result); - break; - } - - if (result < NET_NFC_OK) - type = NET_NFC_LLCP_STOP; - - _emit_snep_event_signal(parameter, handle, result, type, data); - - if (NET_NFC_LLCP_STOP == type) - g_variant_unref(parameter); - - return result; -} - -static void snep_server_start_thread_func(gpointer user_data) -{ - guint arg_sap; - gchar *arg_san; - GVariant *parameter; - void *arg_user_data; - net_nfc_error_e result; - NetNfcGDbusSnep *object; - GDBusConnection *connection; - GDBusMethodInvocation *invocation; - net_nfc_target_handle_s *arg_handle; - - RET_IF(NULL == user_data); - - 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) - { - NFC_ERR("net_nfc_server_snep_server failed, [%d]", result); - g_object_unref(connection); - - g_variant_unref(parameter); - } - } - else - { - NFC_ERR("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) -{ - bool ret; - gboolean result; - GVariant *parameter; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, arg_privilege, - "nfc-manager::p2p", "rw"); - if (false == ret) - { - NFC_ERR("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) - { - result = net_nfc_server_controller_async_queue_push( - snep_server_start_thread_func, parameter); - if (FALSE == result) - { - NFC_ERR("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 - { - NFC_ERR("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; - - NFC_DBG("type [%d], result [%d], data [%p], user_param [%p]", - type, result, data, user_param); - - _emit_snep_event_signal(parameter, handle, result, type, data); - - if (NET_NFC_LLCP_STOP == type) - g_variant_unref(parameter); - - return result; -} - -static void snep_client_start_thread_func(gpointer user_data) -{ - guint arg_sap; - gchar *arg_san; - GVariant *parameter; - void *arg_user_data; - net_nfc_error_e result; - NetNfcGDbusSnep *object; - GDBusConnection *connection; - GDBusMethodInvocation *invocation; - net_nfc_target_handle_s *arg_handle; - - RET_IF(NULL == user_data); - - 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) - { - NFC_ERR("net_nfc_server_snep_client failed, [%d]", result); - g_object_unref(connection); - - g_variant_unref(parameter); - } - } - else - { - NFC_ERR("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) -{ - bool ret; - gboolean result; - GVariant *parameter; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, arg_privilege, - "nfc-manager::p2p", "rw"); - if (false == ret) - { - NFC_ERR("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) - { - result = net_nfc_server_controller_async_queue_push( - snep_client_start_thread_func, parameter); - if (FALSE == result) - { - NFC_ERR("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 - { - NFC_ERR("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; - - NFC_DBG("type [%d], result [%d], data [%p], user_param [%p]", - type, result, data, user_param); - - if (parameter != NULL) - { - GVariant *arg_ndef_msg; - NetNfcGDbusSnep *object; - GVariant *arg_data = NULL; - net_nfc_snep_type_t arg_type; - GDBusMethodInvocation *invocation; - net_nfc_snep_handle_h arg_snep_handle; - - 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) -{ - net_nfc_error_e result; - GVariant *arg_ndef_msg; - NetNfcGDbusSnep *object; - data_s data = { NULL, }; - net_nfc_snep_type_t arg_type; - GDBusMethodInvocation *invocation; - net_nfc_server_snep_context_t *arg_snep_handle; - - RET_IF(NULL == user_data); - - 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; - - NFC_ERR("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) -{ - bool ret; - gboolean result; - GVariant *parameter; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, arg_privilege, - "nfc-manager::p2p", "rw"); - if (false == ret) - { - NFC_ERR("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) - { - result = net_nfc_server_controller_async_queue_push( - snep_client_send_request_thread_func, parameter); - if (FALSE == result) - { - NFC_ERR("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 - { - NFC_ERR("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; - net_nfc_target_handle_s *handle; - GDBusMethodInvocation *invocation; - net_nfc_snep_handle_h snep_handle; - - RET_IF(NULL == user_data); - - 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) -{ - bool ret; - gboolean result; - GVariant *parameter; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, arg_privilege, - "nfc-manager::p2p", "rw"); - if (false == ret) - { - NFC_ERR("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) - { - result = net_nfc_server_controller_async_queue_push( - snep_stop_service_thread_func, parameter); - if (FALSE == result) - { - NFC_ERR("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 - { - NFC_ERR("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) -{ - net_nfc_error_e result = NET_NFC_OK; - GVariant *parameter = (GVariant *)user_param; - - NFC_DBG("event [%d], handle [%p], sap [%d], san [%s]", event, handle, sap, san); - - if (NET_NFC_LLCP_START == event) - { - char *client_id; - void *user_data; - GVariant *param = NULL; - GDBusConnection *connection; - - /* 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 (NET_NFC_OK == result) - { - _emit_snep_event_signal(parameter, handle, result, event, NULL); - } - else - { - NFC_ERR("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) -{ - guint arg_sap; - gchar *arg_san; - guint arg_user_data; - net_nfc_error_e result; - NetNfcGDbusSnep *object; - g_assert(user_data != NULL); - GVariant *parameter = NULL; - GDBusConnection *connection; - GDBusMethodInvocation *invocation; - - 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) - { - NFC_ERR("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) -{ - bool ret; - gboolean result; - GVariant *parameter; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, arg_privilege, - "nfc-manager::p2p", "rw"); - if (false == ret) - { - NFC_ERR("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) - { - result = net_nfc_server_controller_async_queue_push( - snep_register_server_thread_func, parameter); - if (FALSE == result) - { - NFC_ERR("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 - { - NFC_ERR("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) -{ - guint arg_sap; - gchar *arg_san; - net_nfc_error_e result; - NetNfcGDbusSnep *object; - GDBusMethodInvocation *invocation; - - 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) -{ - bool ret; - gboolean result; - GVariant *parameter; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, arg_privilege, - "nfc-manager::p2p", "rw"); - - if (false == ret) - { - NFC_ERR("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) - { - result = net_nfc_server_controller_async_queue_push( - snep_unregister_server_thread_func, parameter); - if (FALSE == result) - { - NFC_ERR("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 - { - NFC_ERR("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) -{ - gboolean result; - GError *error = NULL; - - 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 (FALSE == result) - { - 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; - } -} diff --git a/daemon/net_nfc_server_snep.h b/daemon/net_nfc_server_snep.h deleted file mode 100644 index c868fb7..0000000 --- a/daemon/net_nfc_server_snep.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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__ diff --git a/daemon/net_nfc_server_system_handler.c b/daemon/net_nfc_server_system_handler.c deleted file mode 100644 index 9cdf65f..0000000 --- a/daemon/net_nfc_server_system_handler.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_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, - gint state, - gint focus_state, - GVariant *smack_privilege, - gpointer user_data) -{ - bool ret; - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager", "w"); - if (false == ret) - { - NFC_ERR("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, NET_NFC_OK); - - return TRUE; -} - -static gboolean popup_handle_get(NetNfcGDbusPopup *popup_manager, - GDBusMethodInvocation *invocation, GVariant *smack_privilege, gpointer user_data) -{ - bool ret; - gboolean state; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager", "r"); - if (false == ret) - { - NFC_ERR("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, NET_NFC_OK, state); - - return TRUE; -} - -gboolean net_nfc_server_system_handler_init(GDBusConnection *connection) -{ - gboolean result; - GError *error = NULL; - - if (popup_skeleton) - g_object_unref(popup_skeleton); - - popup_skeleton = net_nfc_gdbus_popup_skeleton_new(); - if (NULL == popup_skeleton) - { - NFC_ERR("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 (FALSE == result) - { - NFC_ERR("Can not skeleton_export %s", error->message); - - g_error_free(error); - - net_nfc_server_system_handler_deinit(); - } - - return result; -} - -void net_nfc_server_system_handler_deinit(void) -{ - if (popup_skeleton) - { - g_object_unref(popup_skeleton); - popup_skeleton = NULL; - } -} diff --git a/daemon/net_nfc_server_system_handler.h b/daemon/net_nfc_server_system_handler.h deleted file mode 100644 index dc8ac3a..0000000 --- a/daemon/net_nfc_server_system_handler.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -gboolean net_nfc_server_system_handler_init(GDBusConnection *connection); - -void net_nfc_server_system_handler_deinit(void); - -#endif //__NET_NFC_SERVER_SYSTEM_HANDLER_H__ diff --git a/daemon/net_nfc_server_tag.c b/daemon/net_nfc_server_tag.c deleted file mode 100644 index d3a0335..0000000 --- a/daemon/net_nfc_server_tag.c +++ /dev/null @@ -1,652 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 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) -{ - - gboolean result = false; - data_s *response = NULL; - net_nfc_transceive_info_s info; - net_nfc_error_e error = NET_NFC_OK; - uint8_t cmd[] = { 0x90, 0x60, 0x00, 0x00, 0x00 }; - - 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) - { - NFC_ERR("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 - { - NFC_ERR("response is NULL"); - } - - return result; -} - -static gboolean tag_read_ndef_message(net_nfc_target_handle_s *handle, - int dev_type, data_s **read_ndef) -{ - data_s *temp = NULL; - net_nfc_error_e result = NET_NFC_OK; - - RETV_IF(NULL == handle, FALSE); - RETV_IF(NULL == read_ndef, FALSE); - - *read_ndef = NULL; - - if (NET_NFC_MIFARE_DESFIRE_PICC == dev_type) - { - if (tag_is_isp_dep_ndef_formatable(handle, dev_type) == FALSE) - { - NFC_ERR("DESFIRE : ISO-DEP ndef not formatable"); - return FALSE; - } - - NFC_DBG("DESFIRE : ISO-DEP ndef formatable"); - - if (net_nfc_controller_connect(handle, &result) == false) - { - NFC_ERR("net_nfc_controller_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 FALSE; - } - } - - if (net_nfc_controller_read_ndef(handle, &temp, &result) == false) - { - NFC_ERR("net_nfc_controller_read_ndef failed"); - return FALSE; - } - - NFC_DBG("net_nfc_controller_read_ndef success"); - - if (NET_NFC_MIFARE_DESFIRE_PICC == dev_type) - { - if (net_nfc_controller_connect(handle, &result) == false) - { - NFC_ERR("net_nfc_controller_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(); - } - - 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) -{ - gboolean ret; - net_nfc_target_handle_s *handle; - bool is_present_target = false; - net_nfc_error_e result = NET_NFC_OK; - WatchDogData *watch_dog = user_data; - - RET_IF(NULL == watch_dog); - RET_IF(NULL == watch_dog->handle); - - /* 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 (true == is_present_target) - { - ret = net_nfc_server_controller_async_queue_push(tag_watchdog_thread_func, - watch_dog); - if(FALSE == ret) - { - NFC_ERR("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) - { - NFC_ERR("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) -{ - - /* FIXME : net_nfc_current_target_info_s should be removed */ - bool ret; - data_s *raw_data = NULL; - gint number_of_keys = 0; - guint32 max_data_size = 0; - guint8 ndef_card_state = 0; - guint32 actual_data_size = 0; - gboolean is_ndef_supported = FALSE; - net_nfc_target_handle_s *handle = NULL; - data_s target_info_values = { NULL, 0 }; - CurrentTagInfoData *info_data = user_data; - net_nfc_current_target_info_s *target_info; - net_nfc_error_e result = NET_NFC_OPERATION_FAIL; - net_nfc_target_type_e dev_type = NET_NFC_UNKNOWN_TARGET; - - 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 ; - - ret = net_nfc_controller_check_ndef(target_info->handle, &ndef_card_state, - (int *)&max_data_size, (int *)&actual_data_size, &result); - if (true == ret) - is_ndef_supported = TRUE; - - if (is_ndef_supported) - { - ret = net_nfc_controller_read_ndef(target_info->handle, &raw_data, &result); - if (true == ret) - NFC_DBG("net_nfc_controller_read_ndef is success"); - } - } - - net_nfc_gdbus_tag_complete_get_current_tag_info(info_data->tag, - info_data->invocation, - result, - (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) -{ - bool ret; - GVariant *raw_data = NULL; - guint32 max_data_size = 0; - guint8 ndef_card_state = 0; - guint32 actual_data_size = 0; - WatchDogData *watch_dog = NULL; - bool isHandoverMessage = false; - net_nfc_error_e result = NET_NFC_OK; - gboolean is_ndef_supported = FALSE; - net_nfc_current_target_info_s *target; - GVariant *target_info_values = NULL; - - target = net_nfc_server_get_target_info(); - - g_assert(target != NULL); /* raise exception!!! what;s wrong?? */ - - RET_IF(NULL == tag_skeleton); - - if (net_nfc_controller_connect(target->handle, &result) == false) - { - NFC_ERR("connect failed & Retry Polling!!"); - - ret = net_nfc_controller_configure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, - NET_NFC_ALL_ENABLE, &result); - if (false == ret) - net_nfc_controller_exception_handler(); - - return; - } - - net_nfc_server_set_state(NET_NFC_TAG_CONNECTED); - - NFC_DBG("tag is connected"); - - target_info_values = net_nfc_util_gdbus_buffer_to_variant( - target->target_info_values.buffer, target->target_info_values.length); - - ret = net_nfc_controller_check_ndef(target->handle, &ndef_card_state, - (int *)&max_data_size, (int *)&actual_data_size, &result); - if (true == ret) - is_ndef_supported = TRUE; - - if (is_ndef_supported) - { - data_s *recv_data = NULL; - - NFC_DBG("support NDEF"); - - if (tag_read_ndef_message(target->handle, target->devType, &recv_data) == TRUE) - { - ndef_record_s *record; - ndef_message_s *selector; - ndef_record_s *recordasperpriority; - - result = net_nfc_server_handover_create_selector_from_rawdata(&selector, - recv_data); - - if (NET_NFC_OK == result) - { - result = net_nfc_server_handover_get_carrier_record_by_priority_order( - selector, &record); - isHandoverMessage = true; - if (NET_NFC_OK == result) - { - 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 - { - NFC_ERR("_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 - { - NFC_ERR("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) }; - - NFC_DBG("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 */ - NFC_DBG("turn on watch dog"); - - watch_dog = g_new0(WatchDogData, 1); - if(NULL == watch_dog) - { - NFC_ERR("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) - { - NFC_ERR("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 */ - bool ret; - gint result; - gboolean is_connected = FALSE; - net_nfc_current_target_info_s *target_info; - net_nfc_target_type_e dev_type = NET_NFC_UNKNOWN_TARGET; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::tag", "r"); - - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - result = NET_NFC_SECURITY_FAIL; - - goto END; - } - - target_info = net_nfc_server_get_target_info(); - if (target_info != NULL) - { - dev_type = target_info->devType; - is_connected = TRUE; - } - - result = NET_NFC_OK; - -END : - net_nfc_gdbus_tag_complete_is_tag_connected(tag, invocation, result, 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) -{ - bool ret; - gboolean result; - CurrentTagInfoData *info_data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::tag", "r"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - info_data = g_new0(CurrentTagInfoData, 1); - if (NULL == info_data) - { - NFC_ERR("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 (FALSE == result) - { - 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 */ - gint result; - gboolean ret; - net_nfc_target_handle_s *handle = NULL; - uint32_t devType = NET_NFC_UNKNOWN_TARGET; - net_nfc_current_target_info_s *target_info; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager::p2p", "r"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - result = NET_NFC_SECURITY_FAIL; - - goto END; - } - - target_info = net_nfc_server_get_target_info(); - if (target_info != NULL) - { - handle = target_info->handle; - devType = target_info->devType; - } - - result = NET_NFC_OK; - -END : - net_nfc_gdbus_tag_complete_get_current_target_handle(tag, invocation, result, - (handle != NULL), GPOINTER_TO_UINT(handle), devType); - - return TRUE; -} - - -gboolean net_nfc_server_tag_init(GDBusConnection *connection) -{ - gboolean result; - GError *error = NULL; - - 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 (FALSE == result) - { - NFC_ERR("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 (NULL == current_target_info) - 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) -{ - gboolean ret; - - ret = net_nfc_server_controller_async_queue_push( - tag_slave_target_detected_thread_func, NULL); - - if (FALSE == ret) - NFC_ERR("can not push to controller thread"); -} diff --git a/daemon/net_nfc_server_tag.h b/daemon/net_nfc_server_tag.h deleted file mode 100644 index 09d2d61..0000000 --- a/daemon/net_nfc_server_tag.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -#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__ diff --git a/daemon/net_nfc_server_transceive.c b/daemon/net_nfc_server_transceive.c deleted file mode 100644 index 7359f7f..0000000 --- a/daemon/net_nfc_server_transceive.c +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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; - - -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) -{ - bool ret; - data_s *data = NULL; - GVariant *resp_data = NULL; - net_nfc_error_e result = NET_NFC_OK; - TransceiveSendData *transceive_data = user_data; - net_nfc_target_handle_s *handle = - (net_nfc_target_handle_s *)transceive_data->transceive_handle; - - /* 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) - { - NFC_DBG("call transceive"); - - ret = net_nfc_controller_transceive(handle, &transceive_data->transceive_info, - &data, &result); - - if (true == ret) - { - if (data != NULL) - NFC_DBG("Transceive data received [%d]", data->length); - } - } - else - { - result = NET_NFC_TARGET_IS_MOVED_AWAY; - } - - NFC_DBG("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) -{ - bool ret; - gboolean result; - TransceiveSendData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_new0(TransceiveSendData, 1); - if (NULL == data) - { - NFC_ERR("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 (FALSE == result) - { - 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) -{ - bool ret; - data_s *data = NULL; - net_nfc_error_e result = NET_NFC_OK; - TransceiveSendData *transceive_data = user_data; - net_nfc_target_handle_s *handle = - (net_nfc_target_handle_s *)transceive_data->transceive_handle; - - /* 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) - { - NFC_DBG("call transceive"); - ret = net_nfc_controller_transceive(handle, &transceive_data->transceive_info, - &data, &result); - if (true == ret) - { - if (data != NULL) - { - NFC_DBG("Transceive data received [%d]", data->length); - - /* free resource because it doesn't need */ - g_free(data->buffer); - g_free(data); - } - } - } - else - { - NFC_ERR("target is not connected"); - - result = NET_NFC_TARGET_IS_MOVED_AWAY; - } - - NFC_DBG("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) -{ - bool ret; - gboolean result; - TransceiveSendData *data; - - NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); - - /* check privilege and update client context */ - ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege, - "nfc-manager", "rw"); - if (false == ret) - { - NFC_ERR("permission denied, and finished request"); - - return FALSE; - } - - data = g_new0(TransceiveSendData, 1); - if (NULL == data) - { - NFC_ERR("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 (FALSE == result) - { - 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) -{ - gboolean result; - GError *error = NULL; - - 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 (FALSE == result) - { - 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; - } -} diff --git a/daemon/net_nfc_server_transceive.h b/daemon/net_nfc_server_transceive.h deleted file mode 100644 index b467464..0000000 --- a/daemon/net_nfc_server_transceive.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -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 diff --git a/daemon/net_nfc_server_util.c b/daemon/net_nfc_server_util.c deleted file mode 100755 index 18c264b..0000000 --- a/daemon/net_nfc_server_util.c +++ /dev/null @@ -1,1055 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#ifdef HAVE_X11 -#include -#endif - -#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 inline int _mkdir_recursive(char *path, mode_t mode) -{ - char *found = path; - - while (found) - { - char tmp_ch; - - if ('\0' == found[1]) - break; - - found = strchr(found+1, '/'); - - if (found) - { - int ret; - DIR *exist; - - tmp_ch = *found; - *found = '\0'; - - exist = opendir(path); - if (NULL == exist) - { - if (ENOENT == errno) - { - ret = mkdir(path, mode); - if (-1 == ret) - { - char buf[1024]; - NFC_ERR("mkdir() Failed(%s)", strerror_r(errno, buf, sizeof(buf))); - return -1; - } - } - else - { - char buf[1024]; - NFC_ERR("opendir() Failed(%s)", strerror_r(errno, buf, sizeof(buf))); - return -1; - } - } - else - { - closedir(exist); - } - *found = tmp_ch; - } - else - { - mkdir(path, mode); - } - } - return 0; -} - -static bool _net_nfc_app_util_change_file_owner_permission(FILE *file) -{ - char *buffer = NULL; - size_t buffer_len = 0; - struct group grp = { 0, }; - struct passwd pwd = { 0, }; - struct group *gr_inhouse = NULL; - struct passwd *pw_inhouse = NULL; - - RETV_IF(NULL == file, 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 (NULL == buffer) - 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 (NULL == buffer) - 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) - NFC_ERR("failed to change owner"); - } - - return true; -} - -static net_nfc_error_e net_nfc_app_util_store_ndef_message(data_s *data) -{ - int ret; - FILE *fp = NULL; - char file_name[1024] = { 0, }; - net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; - - RETV_IF(NULL == data, 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); - - ret = _mkdir_recursive(file_name, 0755); - if (-1 == ret) - { - NFC_ERR("_mkdir_recursive() 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) - { - NFC_DBG("[%d] bytes is written", length); - - _net_nfc_app_util_change_file_owner_permission(fp); - - fflush(fp); - fsync(fileno(fp)); - - result = NET_NFC_OK; - } - else - { - NFC_ERR("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; - - RETV_IF(NULL == record, result); - RETV_IF(NULL == operation, result); - RETV_IF(0 == length, 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 */ - if(strncmp((char*)record->type_s.buffer, NET_NFC_APPLICATION_RECORD, - record->type_s.length)==0) - { - //use APPSVC_OPERATION_VIEW in case of Selective App launch - op_text = APPSVC_OPERATION_VIEW; - } - else - { - 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; - - RETV_IF(NULL == record, result); - RETV_IF(NULL == mime, result); - RETV_IF(0 == length, 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) - { - NFC_ERR("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'; - } - - result = true; - } - break; - - case NET_NFC_RECORD_MIME_TYPE : - { - int len = 0; - char *token = NULL; - char *buffer = NULL; - - if (record->type_s.buffer == NULL || record->type_s.length == 0) - { - NFC_ERR("Broken NDEF Message [NET_NFC_RECORD_MIME_TYPE]"); - break; - } - - /* get mime type */ - _net_nfc_util_alloc_mem(buffer, record->type_s.length + 1); - if (NULL == buffer) - { - NFC_ERR("_net_nfc_manager_util_alloc_mem return NULL"); - break; - } - memcpy(buffer, record->type_s.buffer, record->type_s.length); - - token = strchr(buffer, ';'); - if (token != NULL) - len = MIN(token - buffer, length - 1); - else - len = MIN(strlen(buffer), length - 1); - - strncpy(mime, buffer, len); - mime[len] = '\0'; - - _to_lower(0, 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; - - RETV_IF(NULL == record, result); - RETV_IF(NULL == data, result); - RETV_IF(0 == length, 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) - { - 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); - - NFC_DBG("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); - - 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; - - RETV_IF(NULL == record, result); - RETV_IF(NULL == data, result); - RETV_IF(0 == length, 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) - { - NFC_ERR("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)); - } - - result = true; - } - break; - - case NET_NFC_RECORD_MIME_TYPE : - case NET_NFC_RECORD_URI : /* Absolute URI */ - break; - case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */ - { - NFC_DBG("NDEF Message with external type"); - if(strncmp((char*)record->type_s.buffer, NET_NFC_APPLICATION_RECORD, - record->type_s.length)==0) - { - uint8_t *buffer_temp = record->payload_s.buffer; - uint32_t buffer_length = record->payload_s.length; - if(buffer_length > length) - { - result= false; - } - else - { - //Copy application id into data - memcpy(data,buffer_temp,MIN(buffer_length,length)); - result = true; - } - } - } - break; - 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) -{ - int ret = 0; - char mime[2048] = { 0, }; - char text[2048] = { 0, }; - ndef_message_s *msg = NULL; - char operation[2048] = { 0, }; - net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; -#ifdef USE_FULL_URI - char uri[2048] = { 0, }; -#endif - - RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == data->buffer, NET_NFC_NULL_PARAMETER); - RETV_IF(NULL == data->length, NET_NFC_NULL_PARAMETER); - - /* create file */ - if ((result = net_nfc_app_util_store_ndef_message(data)) != NET_NFC_OK) - { - NFC_ERR("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() == NET_NFC_NO_LAUNCH_APP_SELECT) - { - NFC_DBG("skip launch popup!!!"); - result = NET_NFC_OK; - return result; - } - - if (net_nfc_util_create_ndef_message(&msg) != NET_NFC_OK) - { - NFC_ERR("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) - { - NFC_ERR("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) - { - NFC_ERR("_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) - { - NFC_ERR("_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) - { - NFC_ERR("_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) - { - NFC_ERR("_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 - - NFC_DBG("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) -{ - DIR* dir = NULL; - char path[1024] = { 0 }; - struct dirent* ent = NULL; - - RET_IF((dir = opendir(src_path)) == NULL); - - 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: - NFC_ERR("aul launch error : AUL_R_EINVAL"); - break; - case AUL_R_ECOMM: - NFC_ERR("aul launch error : AUL_R_ECOM"); - break; - case AUL_R_ERROR: - NFC_ERR("aul launch error : AUL_R_ERROR"); - break; - default: - NFC_ERR("aul launch error : unknown ERROR"); - break; - } - } - else - { - NFC_DBG("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; - bool specific_app_launch = false; - bd = bundle_create(); - if (NULL == bd) - return result; - - if (operation != NULL && strlen(operation) > 0) - { - NFC_DBG("operation : %s", operation); - appsvc_set_operation(bd, operation); - if(strncmp(operation, APPSVC_OPERATION_VIEW,strlen(APPSVC_OPERATION_VIEW))==0) - { - appsvc_set_appid(bd, data); - specific_app_launch = true; - goto LAUNCH; - } - } - - if (uri != NULL && strlen(uri) > 0) - { - NFC_DBG("uri : %s", uri); - appsvc_set_uri(bd, uri); - } - - if (mime != NULL && strlen(mime) > 0) - { - NFC_DBG("mime : %s", mime); - appsvc_set_mime(bd, mime); - } - - if (data != NULL && strlen(data) > 0) - { - NFC_DBG("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); - -LAUNCH: - result = appsvc_run_service(bd, 0, NULL, NULL); - - /*if the app could not be found*/ - if(specific_app_launch && result == APPSVC_RET_ENOMATCH) - { - /*TODO: tizen store launch*/ - } - - 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; - - RET_IF(0 == len); - RET_IF(0 == max_len); - RET_IF(NULL == buffer); - RET_IF(NULL == out_buf); - - 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 temp; - int current = 0; - - RET_IF(NULL == input); - RET_IF(NULL == length); - RET_IF(0 == *length); - RET_IF(NULL == output); - NFC_DBG("_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( - net_nfc_secure_element_type_e se_type, - 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)); - - switch(se_type) - { - case SECURE_ELEMENT_TYPE_UICC: - snprintf(aid_string, sizeof(aid_string), "nfc://secure/SIM1/aid/%s", temp_string); - break; - - case SECURE_ELEMENT_TYPE_ESE: - snprintf(aid_string, sizeof(aid_string), "nfc://secure/eSE/aid/%s", temp_string); - break; - default: - snprintf(aid_string, sizeof(aid_string), "nfc://secure/aid/%s", temp_string); - break; - } - - NFC_DBG("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)); - NFC_DBG("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; - - RETV_IF(NULL == buffer, ret); - RETV_IF(0 == buf_len, ret); - RETV_IF(NULL == result, ret); - RETV_IF(0 == max_result, 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; - - RETV_IF(NULL == buffer, ret); - RETV_IF(0 == buf_len, ret); - RETV_IF(NULL == result, ret); - RETV_IF(NULL == res_len, ret); - RETV_IF(0 == *res_len, 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 - { - NFC_ERR("alloc failed"); - } - - return ret; -} - -pid_t net_nfc_app_util_get_focus_app_pid() -{ -#ifdef HAVE_X11 - pid_t pid; - Ecore_X_Window focus; - - ecore_x_init(":0"); - - focus = ecore_x_window_focus_get(); - if (ecore_x_netwm_pid_get(focus, &pid)) - return pid; - -#endif - return -1; -} - -bool net_nfc_app_util_check_launch_state() -{ - bool result = false; - pid_t focus_app_pid; - net_nfc_launch_popup_state_e popup_state; - - 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(NET_NFC_NO_LAUNCH_APP_SELECT == popup_state) - result = true; - - return result; -} - -static void _play_sound_callback(int id, void *data) -{ - NFC_DBG("_play_sound_callback"); - - if (WAV_PLAYER_ERROR_NONE != wav_player_stop(id)) - NFC_ERR("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) - { - NFC_ERR("vconf_get_bool failed for Sound"); - return; - } - - if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &bVibrationOn) != 0) - { - NFC_ERR("vconf_get_bool failed for Vibration"); - return; - } - - if ((sound_type > NET_NFC_TASK_ERROR) || (sound_type < NET_NFC_TASK_START)) - { - NFC_ERR("Invalid Sound Type"); - return; - } - - if (bVibrationOn) - { - int svi_handle = -1; - - NFC_DBG("Play Vibration"); - - if (SVI_SUCCESS == svi_init(&svi_handle)) - { - if (SVI_SUCCESS == svi_play_vib(svi_handle, SVI_VIB_TOUCH_SIP)) - NFC_DBG("svi_play_vib success"); - - svi_fini(svi_handle); - } - } - - if (bSoundOn) - { - char *sound_path = NULL; - - NFC_DBG("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)) - { - NFC_DBG("wav_player_start success"); - } - - _net_nfc_util_free_mem(sound_path); - } - else - { - NFC_ERR("Invalid Sound Path"); - } - } -} diff --git a/daemon/net_nfc_server_util.h b/daemon/net_nfc_server_util.h deleted file mode 100644 index bd0016f..0000000 --- a/daemon/net_nfc_server_util.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -/* For multi-user support */ -#include - -#include "net_nfc_typedef_internal.h" - -#ifndef MESSAGE_STORAGE -#define MESSAGE_STORAGE tzplatform_mkpath(TZ_SYS_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(net_nfc_secure_element_type_e se_type, - 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(); -pid_t net_nfc_app_util_get_focus_app_pid(); - -#endif //__NET_NFC_SERVER_UTIL_H__ diff --git a/daemon/net_nfc_server_vconf.c b/daemon/net_nfc_server_vconf.c deleted file mode 100644 index bed8ba9..0000000 --- a/daemon/net_nfc_server_vconf.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "net_nfc_typedef.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) - NFC_ERR("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 result; - gint state = 0; - gint pm_state = 0; - - result = vconf_get_bool(VCONFKEY_NFC_STATE, &state); - if (result != 0) - NFC_ERR("can not get %s", "VCONFKEY_NFC_STATE"); - - if (false == state) - { - NFC_DBG("NFC off"); - return; - } - - result = vconf_get_int(VCONFKEY_PM_STATE, &pm_state); - if (result != 0) - NFC_ERR("can not get %s", "VCONFKEY_PM_STATE"); - - NFC_DBG("pm_state : %d", pm_state); - - if (VCONFKEY_PM_STATE_NORMAL == pm_state || VCONFKEY_PM_STATE_LCDOFF == pm_state) - net_nfc_server_restart_polling_loop(); -} - -static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key, - void *user_data) -{ - gint result = 0; - gint nfc_state = 0; - gint flight_mode = 0; - - - result = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode); - if (result != 0) - NFC_ERR("Can not get VCONFKEY_TELEPHONY_FLIGHT_MODE"); - - NFC_DBG("flight mode %d", flight_mode); - - result = vconf_get_bool(VCONFKEY_NFC_STATE, &nfc_state); - if (result != 0) - NFC_ERR("Can not get VCONFKEY_NET_STATE"); - - NFC_DBG("nfc_state %d", nfc_state); - NFC_DBG("powerd_off_by_flightmode %d", powered_off_by_flightmode); - - if (flight_mode) /* turn on flight mode */ - { - /* nfc is already disabled ignore it */ - if (VCONFKEY_NFC_STATE_OFF == nfc_state) - return; - - NFC_INFO("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 (VCONFKEY_NFC_STATE_ON == nfc_state) - return; - - if (FALSE == powered_off_by_flightmode) - return; - - NFC_INFO("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); -} diff --git a/daemon/net_nfc_server_vconf.h b/daemon/net_nfc_server_vconf.h deleted file mode 100644 index b7e25ee..0000000 --- a/daemon/net_nfc_server_vconf.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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__ diff --git a/daemon/nfc-manager.xml b/daemon/nfc-manager.xml deleted file mode 100644 index 731865a..0000000 --- a/daemon/nfc-manager.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - name - NFC manager - - - - diff --git a/daemon/org.tizen.NetNfcService.service b/daemon/org.tizen.NetNfcService.service deleted file mode 100644 index ae98f33..0000000 --- a/daemon/org.tizen.NetNfcService.service +++ /dev/null @@ -1,4 +0,0 @@ -[D-BUS Service] -Name=org.tizen.NetNfcService -Exec=/usr/bin/nfc-manager-daemon -User=root diff --git a/daemon/sounds/Operation_sdk.wav b/daemon/sounds/Operation_sdk.wav deleted file mode 100644 index 5383bdf..0000000 Binary files a/daemon/sounds/Operation_sdk.wav and /dev/null differ diff --git a/doxygen/createdoc.sh b/doxygen/createdoc.sh deleted file mode 100755 index 42b1939..0000000 --- a/doxygen/createdoc.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -# Create doxygen from debian package server -# By Jungbae Lee (yi_jungbae@samsung.com) - -#cd `dirname $0` -CWD=`pwd` - -# Use doxygen 1.7.0 -#export PATH=${PATH} -#export LD_LIBRARY_PATH=${LD_LIBRARY_PATH} - - -### Configuration -SBOX=/scratchbox/users/$USER/home/$USER -DOXYGEN_OUTPUT_DIR=$CWD/doxygen_output -DOXYGEN=doxygen -DOXY_CONF=doxygen.conf -IMAGE_DIR=images #need to change -#IMAGE_DIR=[fill your image path] - - - -####doxygen configuration :: output Directory -mkdir $DOXYGEN_OUTPUT_DIR - -echo "Doxygen running..." -if [ ! -e $CWD/doxygen_output ]; then - mkdir $CWD/doxygen_output -fi -# Run doxygen -$DOXYGEN $DOXY_CONF 2>&1 - -#image copy -if [ -d $CWD/$IMAGE_DIR ];then -cp $CWD/$IMAGE_DIR $DOXYGEN_OUTPUT_DIR/html/ -rf -fi - -echo "Finished!" -exit; - diff --git a/doxygen/doxygen.conf b/doxygen/doxygen.conf deleted file mode 100644 index c0b3673..0000000 --- a/doxygen/doxygen.conf +++ /dev/null @@ -1,851 +0,0 @@ -# Doxyfile 1.5.2 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project -# -# All text after a hash (#) is considered a comment and will be ignored -# The format is: -# TAG = value [value, ...] -# For lists items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (" ") - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -DOXYFILE_ENCODING = UTF-8 -PROJECT_NAME = SLP-Developer Library -PROJECT_NUMBER = -OUTPUT_DIRECTORY = ./doxygen_output -CREATE_SUBDIRS = NO -OUTPUT_LANGUAGE = English -BRIEF_MEMBER_DESC = YES -REPEAT_BRIEF = YES -ABBREVIATE_BRIEF = NO -ALWAYS_DETAILED_SEC = YES -INLINE_INHERITED_MEMB = NO -FULL_PATH_NAMES = NO -STRIP_FROM_PATH = -STRIP_FROM_INC_PATH = -SHORT_NAMES = YES -JAVADOC_AUTOBRIEF = NO -MULTILINE_CPP_IS_BRIEF = NO -DETAILS_AT_TOP = YES -INHERIT_DOCS = YES -SEPARATE_MEMBER_PAGES = YES -TAB_SIZE = 8 -ALIASES = -OPTIMIZE_OUTPUT_FOR_C = NO -OPTIMIZE_OUTPUT_JAVA = NO -BUILTIN_STL_SUPPORT = NO -CPP_CLI_SUPPORT = NO -DISTRIBUTE_GROUP_DOC = NO -SUBGROUPING = YES - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -EXTRACT_ALL = YES -EXTRACT_PRIVATE = YES -EXTRACT_STATIC = YES -EXTRACT_LOCAL_CLASSES = NO -EXTRACT_LOCAL_METHODS = YES -HIDE_UNDOC_MEMBERS = YES -HIDE_UNDOC_CLASSES = YES -HIDE_FRIEND_COMPOUNDS = YES -HIDE_IN_BODY_DOCS = NO -INTERNAL_DOCS = NO -CASE_SENSE_NAMES = YES -HIDE_SCOPE_NAMES = NO -SHOW_INCLUDE_FILES = YES -INLINE_INFO = YES -SORT_MEMBER_DOCS = YES -SORT_BRIEF_DOCS = YES -SORT_BY_SCOPE_NAME = YES -SORT_GROUP_NAMES = YES -GENERATE_TODOLIST = NO -USE_INLINE_TREES = NO -SHOW_NAMESPACES = NO -HTML DYNAMIC SECTIONS = YES -GENERATE_TESTLIST = NO -GENERATE_BUGLIST = NO -GENERATE_DEPRECATEDLIST= NO -ENABLED_SECTIONS = -MAX_INITIALIZER_LINES = 30 -SHOW_USED_FILES = YES -SHOW_DIRECTORIES = NO -FILE_VERSION_FILTER = - -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated -# by doxygen. Possible values are YES and NO. If left blank NO is used. - -QUIET = NO - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated by doxygen. Possible values are YES and NO. If left blank -# NO is used. - -WARNINGS = YES - -# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings -# for undocumented members. If EXTRACT_ALL is set to YES then this flag will -# automatically be disabled. - -WARN_IF_UNDOCUMENTED = YES - -# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some -# parameters in a documented function, or documenting parameters that -# don't exist or using markup commands wrongly. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be abled to get warnings for -# functions that are documented, but have no documentation for their parameters -# or return value. If set to NO (the default) doxygen will only warn about -# wrong or incomplete parameter documentation, but not about the absence of -# documentation. - -WARN_NO_PARAMDOC = NO - -# The WARN_FORMAT tag determines the format of the warning messages that -# doxygen can produce. The string should contain the $file, $line, and $text -# tags, which will be replaced by the file and line number from which the -# warning originated and the warning text. Optionally the format may contain -# $version, which will be replaced by the version of the file (if it could -# be obtained via FILE_VERSION_FILTER) - -WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning -# and error messages should be written. If left blank the output is written -# to stderr. - -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag can be used to specify the files and/or directories that contain -# documented source files. You may enter file names like "myfile.cpp" or -# directories like "/usr/src/myproject". Separate the files or directories -# with spaces. - -INPUT = ../common/include/ ../client/include/ - - -# This tag can be used to specify the character encoding of the source files that -# doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default -# input encoding. Doxygen uses libiconv (or the iconv built into libc) for the transcoding. -# See http://www.gnu.org/software/libiconv for the list of possible encodings. - -INPUT_ENCODING = UTF-8 -FILE_PATTERNS = *.h \ - *.doxy -RECURSIVE = YES -EXCLUDE = -EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = */test/* \ - */debian/* \ - */lost+found/* \ - */i386/* \ - */arm/* \ - */simulator/* \ - *test* \ - */voda3rd/* -EXCLUDE_SYMBOLS = -EXAMPLE_PATH = -EXAMPLE_PATTERNS = -EXAMPLE_RECURSIVE = NO -IMAGE_PATH = ../image -INPUT_FILTER = -FILTER_PATTERNS = -FILTER_SOURCE_FILES = NO - -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will -# be generated. Documented entities will be cross-referenced with these sources. -# Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. - -SOURCE_BROWSER = NO - -# Setting the INLINE_SOURCES tag to YES will include the body -# of functions and classes directly in the documentation. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct -# doxygen to hide any special comment blocks from generated source code -# fragments. Normal C and C++ comments will always remain visible. - -STRIP_CODE_COMMENTS = YES - -# If the REFERENCED_BY_RELATION tag is set to YES (the default) -# then for each documented function all documented -# functions referencing it will be listed. - -REFERENCED_BY_RELATION = YES - -# If the REFERENCES_RELATION tag is set to YES (the default) -# then for each documented function all documented entities -# called/used by that function will be listed. - -REFERENCES_RELATION = YES - -# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) -# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from -# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will -# link to the source code. Otherwise they will link to the documentstion. - -REFERENCES_LINK_SOURCE = YES - -# If the USE_HTAGS tag is set to YES then the references to source code -# will point to the HTML generated by the htags(1) tool instead of doxygen -# built-in source browser. The htags tool is part of GNU's global source -# tagging system (see http://www.gnu.org/software/global/global.html). You -# will need version 4.8.6 or higher. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen -# will generate a verbatim copy of the header file for each class for -# which an include is specified. Set to NO to disable this. - -VERBATIM_HEADERS = YES - -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index -# of all compounds will be generated. Enable this if the project -# contains a lot of classes, structs, unions or interfaces. - -ALPHABETICAL_INDEX = YES -COLS_IN_ALPHA_INDEX = 10 -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES (the default) Doxygen will -# generate HTML output. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `html' will be used as the default path. - -HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for -# each generated HTML page (for example: .htm,.php,.asp). If it is left blank -# doxygen will generate files with .html extension. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a personal HTML header for -# each generated HTML page. If it is left blank doxygen will generate a -# standard header. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a personal HTML footer for -# each generated HTML page. If it is left blank doxygen will generate a -# standard footer. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading -# style sheet that is used by each HTML page. It can be used to -# fine-tune the look of the HTML output. If the tag is left blank doxygen -# will generate a default style sheet. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own -# stylesheet in the HTML output directory as well, or it will be erased! - -HTML_STYLESHEET =./slp_doxy.css - -# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, -# files or namespaces will be aligned in HTML using tables. If set to -# NO a bullet list will be used. - -HTML_ALIGN_MEMBERS = YES - -# If the GENERATE_HTMLHELP tag is set to YES, additional index files -# will be generated that can be used as input for tools like the -# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) -# of the generated HTML documentation. - -GENERATE_HTMLHELP = YES - -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can -# be used to specify the file name of the resulting .chm file. You -# can add a path in front of the file if the result should not be -# written to the html output directory. - -CHM_FILE = - -# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can -# be used to specify the location (absolute path including file name) of -# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run -# the HTML help compiler on the generated index.hhp. - -HHC_LOCATION = - -# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag -# controls if a separate .chi index file is generated (YES) or that -# it should be included in the master .chm file (NO). - -GENERATE_CHI = NO - -# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag -# controls whether a binary table of contents is generated (YES) or a -# normal table of contents (NO) in the .chm file. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members -# to the contents of the HTML help documentation and to the tree view. - -TOC_EXPAND = NO - -# The DISABLE_INDEX tag can be used to turn on/off the condensed index at -# top of each HTML page. The value NO (the default) enables the index and -# the value YES disables it. - -DISABLE_INDEX = NO - -# This tag can be used to set the number of enum values (range [1..20]) -# that doxygen will group on one line in the generated HTML documentation. - -ENUM_VALUES_PER_LINE = 4 - -# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be -# generated containing a tree-like index structure (just like the one that -# is generated for HTML Help). For this to work a browser that supports -# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, -# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are -# probably better off using the HTML help feature. - -GENERATE_TREEVIEW = YES - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be -# used to set the initial width (in pixels) of the frame in which the tree -# is shown. - -TREEVIEW_WIDTH = 190 - -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- - -# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will -# generate Latex output. - -GENERATE_LATEX = NO - -# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `latex' will be used as the default path. - -LATEX_OUTPUT = latex - -# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be -# invoked. If left blank `latex' will be used as the default command name. - -LATEX_CMD_NAME = latex - -# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to -# generate index for LaTeX. If left blank `makeindex' will be used as the -# default command name. - -MAKEINDEX_CMD_NAME = makeindex - -# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact -# LaTeX documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_LATEX = NO - -# The PAPER_TYPE tag can be used to set the paper type that is used -# by the printer. Possible values are: a4, a4wide, letter, legal and -# executive. If left blank a4wide will be used. - -PAPER_TYPE = a4wide - -# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX -# packages that should be included in the LaTeX output. - -EXTRA_PACKAGES = - -# The LATEX_HEADER tag can be used to specify a personal LaTeX header for -# the generated latex document. The header should contain everything until -# the first chapter. If it is left blank doxygen will generate a -# standard header. Notice: only use this tag if you know what you are doing! - -LATEX_HEADER = - -# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated -# is prepared for conversion to pdf (using ps2pdf). The pdf file will -# contain links (just like the HTML output) instead of page references -# This makes the output suitable for online browsing using a pdf viewer. - -PDF_HYPERLINKS = NO - -# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of -# plain latex in the generated Makefile. Set this option to YES to get a -# higher quality PDF documentation. - -USE_PDFLATEX = NO - -# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. -# command to the generated LaTeX files. This will instruct LaTeX to keep -# running if errors occur, instead of asking the user for help. -# This option is also used when generating formulas in HTML. - -LATEX_BATCHMODE = NO - -# If LATEX_HIDE_INDICES is set to YES then doxygen will not -# include the index chapters (such as File Index, Compound Index, etc.) -# in the output. - -LATEX_HIDE_INDICES = NO - -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- - -# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output -# The RTF output is optimized for Word 97 and may not look very pretty with -# other RTF readers or editors. - -GENERATE_RTF = NO - -# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `rtf' will be used as the default path. - -RTF_OUTPUT = rtf - -# If the COMPACT_RTF tag is set to YES Doxygen generates more compact -# RTF documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_RTF = NO - -# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated -# will contain hyperlink fields. The RTF file will -# contain links (just like the HTML output) instead of page references. -# This makes the output suitable for online browsing using WORD or other -# programs which support those fields. -# Note: wordpad (write) and others do not support links. - -RTF_HYPERLINKS = NO - -# Load stylesheet definitions from file. Syntax is similar to doxygen's -# config file, i.e. a series of assignments. You only have to provide -# replacements, missing definitions are set to their default value. - -RTF_STYLESHEET_FILE = - -# Set optional variables used in the generation of an rtf document. -# Syntax is similar to doxygen's config file. - -RTF_EXTENSIONS_FILE = - -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- - -# If the GENERATE_MAN tag is set to YES (the default) Doxygen will -# generate man pages - -GENERATE_MAN = NO - -# The MAN_OUTPUT tag is used to specify where the man pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `man' will be used as the default path. - -MAN_OUTPUT = man - -# The MAN_EXTENSION tag determines the extension that is added to -# the generated man pages (default is the subroutine's section .3) - -MAN_EXTENSION = .3 - -# If the MAN_LINKS tag is set to YES and Doxygen generates man output, -# then it will generate one additional man file for each entity -# documented in the real man page(s). These additional files -# only source the real man page, but without them the man command -# would be unable to find the correct page. The default is NO. - -MAN_LINKS = NO - -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- - -# If the GENERATE_XML tag is set to YES Doxygen will -# generate an XML file that captures the structure of -# the code including all documentation. - -GENERATE_XML = NO - -# The XML_OUTPUT tag is used to specify where the XML pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `xml' will be used as the default path. - -XML_OUTPUT = xml - -# The XML_SCHEMA tag can be used to specify an XML schema, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_SCHEMA = - -# The XML_DTD tag can be used to specify an XML DTD, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_DTD = - -# If the XML_PROGRAMLISTING tag is set to YES Doxygen will -# dump the program listings (including syntax highlighting -# and cross-referencing information) to the XML output. Note that -# enabling this will significantly increase the size of the XML output. - -XML_PROGRAMLISTING = YES - -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- - -# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will -# generate an AutoGen Definitions (see autogen.sf.net) file -# that captures the structure of the code including all -# documentation. Note that this feature is still experimental -# and incomplete at the moment. - -GENERATE_AUTOGEN_DEF = NO - -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- - -# If the GENERATE_PERLMOD tag is set to YES Doxygen will -# generate a Perl module file that captures the structure of -# the code including all documentation. Note that this -# feature is still experimental and incomplete at the -# moment. - -GENERATE_PERLMOD = NO - -# If the PERLMOD_LATEX tag is set to YES Doxygen will generate -# the necessary Makefile rules, Perl scripts and LaTeX code to be able -# to generate PDF and DVI output from the Perl module output. - -PERLMOD_LATEX = YES - -# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be -# nicely formatted so it can be parsed by a human reader. This is useful -# if you want to understand what is going on. On the other hand, if this -# tag is set to NO the size of the Perl module output will be much smaller -# and Perl will parse it just the same. - -PERLMOD_PRETTY = YES - -# The names of the make variables in the generated doxyrules.make file -# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. -# This is useful so different doxyrules.make files included by the same -# Makefile don't overwrite each other's variables. - -PERLMOD_MAKEVAR_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- - -# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will -# evaluate all C-preprocessor directives found in the sources and include -# files. - -ENABLE_PREPROCESSING = YES - -# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro -# names in the source code. If set to NO (the default) only conditional -# compilation will be performed. Macro expansion can be done in a controlled -# way by setting EXPAND_ONLY_PREDEF to YES. - -MACRO_EXPANSION = NO - -# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES -# then the macro expansion is limited to the macros specified with the -# PREDEFINED and EXPAND_AS_DEFINED tags. - -EXPAND_ONLY_PREDEF = NO - -# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files -# in the INCLUDE_PATH (see below) will be search if a #include is found. - -SEARCH_INCLUDES = YES - -# The INCLUDE_PATH tag can be used to specify one or more directories that -# contain include files that are not input files but should be processed by -# the preprocessor. - -INCLUDE_PATH = - -# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard -# patterns (like *.h and *.hpp) to filter out the header-files in the -# directories. If left blank, the patterns specified with FILE_PATTERNS will -# be used. - -INCLUDE_FILE_PATTERNS = - -# The PREDEFINED tag can be used to specify one or more macro names that -# are defined before the preprocessor is started (similar to the -D option of -# gcc). The argument of the tag is a list of macros of the form: name -# or name=definition (no spaces). If the definition and the = are -# omitted =1 is assumed. To prevent a macro definition from being -# undefined via #undef or recursively expanded use the := operator -# instead of the = operator. - -PREDEFINED = - -# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then -# this tag can be used to specify a list of macro names that should be expanded. -# The macro definition that is found in the sources will be used. -# Use the PREDEFINED tag if you want to use a different macro definition. - -EXPAND_AS_DEFINED = - -# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then -# doxygen's preprocessor will remove all function-like macros that are alone -# on a line, have an all uppercase name, and do not end with a semicolon. Such -# function macros are typically used for boiler-plate code, and will confuse -# the parser if not removed. - -SKIP_FUNCTION_MACROS = YES - -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- - -# The TAGFILES option can be used to specify one or more tagfiles. -# Optionally an initial location of the external documentation -# can be added for each tagfile. The format of a tag file without -# this location is as follows: -# TAGFILES = file1 file2 ... -# Adding location for the tag files is done as follows: -# TAGFILES = file1=loc1 "file2 = loc2" ... -# where "loc1" and "loc2" can be relative or absolute paths or -# URLs. If a location is present for each tag, the installdox tool -# does not have to be run to correct the links. -# Note that each tag file must have a unique name -# (where the name does NOT include the path) -# If a tag file is not located in the directory in which doxygen -# is run, you must also specify the path to the tagfile here. - -TAGFILES = - -# When a file name is specified after GENERATE_TAGFILE, doxygen will create -# a tag file that is based on the input files it reads. - -GENERATE_TAGFILE = - -# If the ALLEXTERNALS tag is set to YES all external classes will be listed -# in the class index. If set to NO only the inherited external classes -# will be listed. - -ALLEXTERNALS = NO - -# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed -# in the modules index. If set to NO, only the current project's groups will -# be listed. - -EXTERNAL_GROUPS = YES - -# The PERL_PATH should be the absolute path and name of the perl script -# interpreter (i.e. the result of `which perl'). - -PERL_PATH = /usr/bin/perl - -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- - -# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will -# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base -# or super classes. Setting the tag to NO turns the diagrams off. Note that -# this option is superseded by the HAVE_DOT option below. This is only a -# fallback. It is recommended to install and use dot, since it yields more -# powerful graphs. - -CLASS_DIAGRAMS = NO - -# You can define message sequence charts within doxygen comments using the \msc -# command. Doxygen will then run the mscgen tool (see http://www.mcternan.me.uk/mscgen/) to -# produce the chart and insert it in the documentation. The MSCGEN_PATH tag allows you to -# specify the directory where the mscgen tool resides. If left empty the tool is assumed to -# be found in the default search path. - -MSCGEN_PATH = - -# If set to YES, the inheritance and collaboration graphs will hide -# inheritance and usage relations if the target is undocumented -# or is not a class. - -HIDE_UNDOC_RELATIONS = YES - -# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is -# available from the path. This tool is part of Graphviz, a graph visualization -# toolkit from AT&T and Lucent Bell Labs. The other options in this section -# have no effect if this option is set to NO (the default) - -HAVE_DOT = NO - -# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect inheritance relations. Setting this tag to YES will force the -# the CLASS_DIAGRAMS tag to NO. - -CLASS_GRAPH = NO - -# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect implementation dependencies (inheritance, containment, and -# class references variables) of the class with other documented classes. - -COLLABORATION_GRAPH = NO - -# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for groups, showing the direct groups dependencies - -GROUP_GRAPHS = NO - -# If the UML_LOOK tag is set to YES doxygen will generate inheritance and -# collaboration diagrams in a style similar to the OMG's Unified Modeling -# Language. - -UML_LOOK = NO - -# If set to YES, the inheritance and collaboration graphs will show the -# relations between templates and their instances. - -TEMPLATE_RELATIONS = NO - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT -# tags are set to YES then doxygen will generate a graph for each documented -# file showing the direct and indirect include dependencies of the file with -# other documented files. - -INCLUDE_GRAPH = NO - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and -# HAVE_DOT tags are set to YES then doxygen will generate a graph for each -# documented header file showing the documented files that directly or -# indirectly include this file. - -INCLUDED_BY_GRAPH = NO - -# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will -# generate a call dependency graph for every global function or class method. -# Note that enabling this option will significantly increase the time of a run. -# So in most cases it will be better to enable call graphs for selected -# functions only using the \callgraph command. - -CALL_GRAPH = NO - -# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will -# generate a caller dependency graph for every global function or class method. -# Note that enabling this option will significantly increase the time of a run. -# So in most cases it will be better to enable caller graphs for selected -# functions only using the \callergraph command. - -CALLER_GRAPH = NO - -# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen -# will graphical hierarchy of all classes instead of a textual one. - -GRAPHICAL_HIERARCHY = NO - -# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES -# then doxygen will show the dependencies a directory has on other directories -# in a graphical way. The dependency relations are determined by the #include -# relations between the files in the directories. - -DIRECTORY_GRAPH = NO - -# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. Possible values are png, jpg, or gif -# If left blank png will be used. - -DOT_IMAGE_FORMAT = jpg - -# The tag DOT_PATH can be used to specify the path where the dot tool can be -# found. If left blank, it is assumed the dot tool can be found in the path. - -DOT_PATH = - -# The DOTFILE_DIRS tag can be used to specify one or more directories that -# contain dot files that are included in the documentation (see the -# \dotfile command). - -DOTFILE_DIRS = - -# The MAX_DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of -# nodes that will be shown in the graph. If the number of nodes in a graph -# becomes larger than this value, doxygen will truncate the graph, which is -# visualized by representing a node as a red box. Note that doxygen will always -# show the root nodes and its direct children regardless of this setting. - -DOT_GRAPH_MAX_NODES = 50 - -# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, which results in a white background. -# Warning: Depending on the platform used, enabling this option may lead to -# badly anti-aliased labels on the edges of a graph (i.e. they become hard to -# read). - -DOT_TRANSPARENT = NO - -# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output -# files in one run (i.e. multiple -o and -T options on the command line). This -# makes dot run faster, but since only newer versions of dot (>1.8.10) -# support this, this feature is disabled by default. - -DOT_MULTI_TARGETS = NO - -# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will -# generate a legend page explaining the meaning of the various boxes and -# arrows in the dot generated graphs. - -GENERATE_LEGEND = NO - -# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will -# remove the intermediate dot files that are used to generate -# the various graphs. - -DOT_CLEANUP = NO - -#--------------------------------------------------------------------------- -# Configuration::additions related to the search engine -#--------------------------------------------------------------------------- - -# The SEARCHENGINE tag specifies whether or not a search engine should be -# used. If set to NO the values of all tags below this one will be ignored. - -SEARCHENGINE = YES diff --git a/doxygen/slp_doxy.css b/doxygen/slp_doxy.css deleted file mode 100644 index 12c03ac..0000000 --- a/doxygen/slp_doxy.css +++ /dev/null @@ -1,699 +0,0 @@ -/* The standard CSS for doxygen */ - -body, table, div, p, dl { - font-family: Lucida Grande, Verdana, Geneva, Arial, sans-serif; - font-size: 12px; -} - -/* @group Heading Levels */ - -h1 { - font-size: 18pt; - color: #3366ED; -} - -h1.pg { - font-size: 18pt; - color: #336666; - margin-right:-0.6pt; - margin-left:0cm; - padding-top:0cm; - padding-right:0cm; - padding-bottom:1pt; - padding-left:0cm; - border-bottom-width:1.5pt; - border-bottom-color:#336666; - border-top-style:none; - border-right-style:none; - border-bottom-style:solid; - border-left-style:none; -} - -h2 { - font-size: 14pt; - color: #336666; -} -h2.pg { - font-size: 14pt; - color: #336666; - margin-right:-0.1pt; - margin-left:0cm; - padding-top:0cm; - padding-right:0cm; - padding-bottom:1pt; - padding-left:0cm; - border-bottom-width:1.2pt; - border-bottom-color:#336666; - border-top-style:none; - border-right-style:none; - border-bottom-style:solid; - border-left-style:none; -} - - -h3 { - font-size: 12pt; - color: #336666; -} -h3.pg { - font-size: 12pt; - color: #336666; -} - - - -dt { - font-weight: bold; -} - -div.multicol { - -moz-column-gap: 1em; - -webkit-column-gap: 1em; - -moz-column-count: 3; - -webkit-column-count: 3; -} - -p.startli, p.startdd, p.starttd { - margin-top: 2px; -} - -p.endli { - margin-bottom: 0px; -} - -p.enddd { - margin-bottom: 4px; -} - -p.endtd { - margin-bottom: 2px; -} - -/* @end */ - -caption { - font-weight: bold; -} - -span.legend { - font-size: 70%; - text-align: center; -} - -h3.version { - font-size: 90%; - text-align: center; -} - -div.qindex, div.navtab{ - background-color: #EBEFF6; - border: 1px solid #A3B4D7; - text-align: center; - margin: 2px; - padding: 2px; -} - -div.qindex, div.navpath { - width: 100%; - line-height: 140%; -} - -div.navtab { - margin-right: 15px; -} - -/* @group Link Styling */ - -a { - color: #3D578C; - font-weight: normal; - text-decoration: none; -} - -.contents a:visited { - color: #4665A2; -} - -a:hover { - text-decoration: underline; -} - -a.qindex { - font-weight: bold; -} - -a.qindexHL { - font-weight: bold; - background-color: #9CAFD4; - color: #ffffff; - border: 1px double #869DCA; -} - -.contents a.qindexHL:visited { - color: #ffffff; -} - -a.el { - font-weight: bold; -} - -a.elRef { -} - -a.code { - color: #4665A2; -} - -a.codeRef { - color: #4665A2; -} - -/* @end */ - -dl.el { - margin-left: -1cm; -} - -.fragment { - font-family: monospace, fixed; - font-size: 105%; -} - -pre.fragment { - border: 1px solid #C4CFE5; - background-color: #FBFCFD; - padding: 4px 6px; - margin: 4px 8px 4px 2px; - overflow: auto; - word-wrap: break-word; - font-size: 9pt; - line-height: 125%; -} - -div.ah { - background-color: black; - font-weight: bold; - color: #ffffff; - margin-bottom: 3px; - margin-top: 3px - padding: .2em; - border: solid thin #333; - border-radius: .5em; - -webkit-border-radius: .5em; - -moz-border-radius: .5em; - -webkit-box-shadow: 2px 2px 3px #999; - -moz-box-shadow: rgba(0, 0, 0, 0.15) 2px 2px 2px; - background-image: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#000),color-stop(0.3, #444)); - background-image: -moz-linear-gradient(center top, #eee 0%, #444 40%, #000); -} - -div.groupHeader { - margin-left: 16px; - margin-top: 12px; - margin-bottom: 6px; - font-weight: bold; -} - -div.groupText { - margin-left: 16px; - font-style: italic; -} - -body { - background: white; - color: black; - margin: 0; -} - -div.contents { - margin-top: 10px; - margin-left: 10px; - margin-right: 10px; -} - -td.indexkey { - background-color: #EBEFF6; - font-weight: bold; - border: 1px solid #C4CFE5; - margin: 2px 0px 2px 0; - padding: 2px 10px; -} - -td.indexvalue { - background-color: #EBEFF6; - border: 1px solid #C4CFE5; - padding: 2px 10px; - margin: 2px 0px; -} - -tr.memlist { - background-color: #EEF1F7; -} - -p.formulaDsp { - text-align: center; -} - -img.formulaDsp { - -} - -img.formulaInl { - vertical-align: middle; -} - -div.center { - text-align: center; - margin-top: 0px; - margin-bottom: 0px; - padding: 0px; -} - -div.center img { - border: 0px; -} - -address.footer { - text-align: right; - padding-right: 12px; -} - -img.footer { - border: 0px; - vertical-align: middle; -} - -/* @group Code Colorization */ - -span.keyword { - color: #008000 -} - -span.keywordtype { - color: #604020 -} - -span.keywordflow { - color: #e08000 -} - -span.comment { - color: #800000 -} - -span.preprocessor { - color: #806020 -} - -span.stringliteral { - color: #002080 -} - -span.charliteral { - color: #008080 -} - -span.vhdldigit { - color: #ff00ff -} - -span.vhdlchar { - color: #000000 -} - -span.vhdlkeyword { - color: #700070 -} - -span.vhdllogic { - color: #ff0000 -} - -/* @end */ - -/* -.search { - color: #003399; - font-weight: bold; -} - -form.search { - margin-bottom: 0px; - margin-top: 0px; -} - -input.search { - font-size: 75%; - color: #000080; - font-weight: normal; - background-color: #e8eef2; -} -*/ - -td.tiny { - font-size: 75%; -} - -.dirtab { - padding: 4px; - border-collapse: collapse; - border: 1px solid #A3B4D7; -} - -th.dirtab { - background: #EBEFF6; - font-weight: bold; -} - -hr { - height: 0px; - border: none; - border-top: 1px solid #4A6AAA; -} - -hr.footer { - height: 1px; -} - -/* @group Member Descriptions */ - -table.memberdecls { - border-spacing: 0px; - padding: 0px; -} - -.mdescLeft, .mdescRight, -.memItemLeft, .memItemRight, -.memTemplItemLeft, .memTemplItemRight, .memTemplParams { - background-color: #F9FAFC; - border: none; - margin: 4px; - padding: 1px 0 0 8px; -} - -.mdescLeft, .mdescRight { - padding: 0px 8px 4px 8px; - color: #555; -} - -.memItemLeft, .memItemRight, .memTemplParams { - border-top: 1px solid #C4CFE5; -} - -.memItemLeft, .memTemplItemLeft { - white-space: nowrap; -} - -.memTemplParams { - color: #4665A2; - white-space: nowrap; -} - -/* @end */ - -/* @group Member Details */ - -/* Styles for detailed member documentation */ - -.memtemplate { - font-size: 80%; - color: #4665A2; - font-weight: normal; - margin-left: 3px; -} - -.memnav { - background-color: #EBEFF6; - border: 1px solid #A3B4D7; - text-align: center; - margin: 2px; - margin-right: 15px; - padding: 2px; -} - -.memitem { - padding: 0; - margin-bottom: 10px; -} - -.memname { - white-space: nowrap; - font-weight: bold; - margin-left: 6px; -} - -.memproto { - border-top: 1px solid #A8B8D9; - border-left: 1px solid #A8B8D9; - border-right: 1px solid #A8B8D9; - padding: 6px 0px 6px 0px; - color: #253555; - font-weight: bold; - text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); - /* firefox specific markup */ - -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; - -moz-border-radius-topright: 8px; - -moz-border-radius-topleft: 8px; - /* webkit specific markup */ - -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); - -webkit-border-top-right-radius: 8px; - -webkit-border-top-left-radius: 8px; - background-image:url('nav_f.png'); - background-repeat:repeat-x; - background-color: #E2E8F2; - -} - -.memdoc { - border-bottom: 1px solid #A8B8D9; - border-left: 1px solid #A8B8D9; - border-right: 1px solid #A8B8D9; - padding: 2px 5px; - background-color: #FBFCFD; - border-top-width: 0; - /* firefox specific markup */ - -moz-border-radius-bottomleft: 8px; - -moz-border-radius-bottomright: 8px; - -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; - background-image: -moz-linear-gradient(center top, #FFFFFF 0%, #FFFFFF 60%, #F8 95%, #F0); - /* webkit specific markup */ - -webkit-border-bottom-left-radius: 8px; - -webkit-border-bottom-right-radius: 8px; - -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); - background-image: -webkit-gradient(linear,center top,center bottom,from(#FFFFFF), color-stop(0.6,#FFFFFF), color-stop(0.60,#FF), color-stop(0.95,#F8), to(#F0)); -} - -.paramkey { - text-align: right; -} - -.paramtype { - white-space: nowrap; -} - -.paramname { - color: #602020; - white-space: nowrap; -} -.paramname em { - font-style: normal; -} - -/* @end */ - -/* @group Directory (tree) */ - -/* for the tree view */ - -.ftvtree { - font-family: sans-serif; - margin: 0px; -} - -/* these are for tree view when used as main index */ - -.directory { - font-size: 9pt; - font-weight: bold; - margin: 5px; -} - -.directory h3 { - margin: 0px; - margin-top: 1em; - font-size: 11pt; -} - -/* -The following two styles can be used to replace the root node title -with an image of your choice. Simply uncomment the next two styles, -specify the name of your image and be sure to set 'height' to the -proper pixel height of your image. -*/ - -/* -.directory h3.swap { - height: 61px; - background-repeat: no-repeat; - background-image: url("yourimage.gif"); -} -.directory h3.swap span { - display: none; -} -*/ - -.directory > h3 { - margin-top: 0; -} - -.directory p { - margin: 0px; - white-space: nowrap; -} - -.directory div { - display: none; - margin: 0px; -} - -.directory img { - vertical-align: -30%; -} - -/* these are for tree view when not used as main index */ - -.directory-alt { - font-size: 100%; - font-weight: bold; -} - -.directory-alt h3 { - margin: 0px; - margin-top: 1em; - font-size: 11pt; -} - -.directory-alt > h3 { - margin-top: 0; -} - -.directory-alt p { - margin: 0px; - white-space: nowrap; -} - -.directory-alt div { - display: none; - margin: 0px; -} - -.directory-alt img { - vertical-align: -30%; -} - -/* @end */ - -div.dynheader { - margin-top: 8px; -} - -address { - font-style: normal; - color: #2A3D61; -} - -table.doxtable { - border-collapse:collapse; -} - -table.doxtable td, table.doxtable th { - border: 1px solid #2D4068; - padding: 3px 7px 2px; -} - -table.doxtable th { - background-color: #374F7F; - color: #FFFFFF; - font-size: 110%; - padding-bottom: 4px; - padding-top: 5px; - text-align:left; -} - -.tabsearch { - top: 0px; - left: 10px; - height: 36px; - background-image: url('tab_b.png'); - z-index: 101; - overflow: hidden; - font-size: 13px; -} - -.navpath ul -{ - font-size: 11px; - background-image:url('tab_b.png'); - background-repeat:repeat-x; - height:30px; - line-height:30px; - color:#8AA0CC; - border:solid 1px #C2CDE4; - overflow:hidden; - margin:0px; - padding:0px; -} - -.navpath li -{ - list-style-type:none; - float:left; - padding-left:10px; - padding-right: 15px; - background-image:url('bc_s.png'); - background-repeat:no-repeat; - background-position:right; - color:#364D7C; -} - -.navpath a -{ - height:32px; - display:block; - text-decoration: none; - outline: none; -} - -.navpath a:hover -{ - color:#6884BD; -} - -div.summary -{ - float: right; - font-size: 8pt; - padding-right: 5px; - width: 50%; - text-align: right; -} - -div.summary a -{ - white-space: nowrap; -} - -div.header -{ - background-image:url('nav_h.png'); - background-repeat:repeat-x; - background-color: #F9FAFC; - margin: 0px; - border-bottom: 1px solid #C4CFE5; -} - -div.headertitle -{ - padding: 5px 5px 5px 10px; -} - diff --git a/nfc-client-lib-devel.manifest b/nfc-client-lib-devel.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/nfc-client-lib-devel.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/nfc-client-lib.manifest b/nfc-client-lib.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/nfc-client-lib.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/nfc-client-test.manifest b/nfc-client-test.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/nfc-client-test.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/nfc-common-lib-devel.manifest b/nfc-common-lib-devel.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/nfc-common-lib-devel.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/nfc-common-lib.manifest b/nfc-common-lib.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/nfc-common-lib.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/nfc-manager.manifest b/nfc-manager.manifest index ca37499..24771db 100644 --- a/nfc-manager.manifest +++ b/nfc-manager.manifest @@ -1,6 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/packaging/nfc-manager.changes b/packaging/nfc-manager.changes deleted file mode 100644 index 16427a5..0000000 --- a/packaging/nfc-manager.changes +++ /dev/null @@ -1,8 +0,0 @@ -* Fri Jun 28 2013 Patrick McCarty 500ab47 -- packaging: remove explicit requires on sys-assert - -* Fri Jun 28 2013 Alexandru Cornea 011dde4 -- resetting manifest requested domain to floor - -* Tue May 28 2013 Baptiste DURAND accepted/tizen/20130520.101035@bc7a137 -- Fix compatibility for x64 arch diff --git a/packaging/nfc-manager.manifest b/packaging/nfc-manager.manifest deleted file mode 100644 index 017d22d..0000000 --- a/packaging/nfc-manager.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/nfc-manager.service b/packaging/nfc-manager.service old mode 100644 new mode 100755 index 85be079..72908a5 --- a/packaging/nfc-manager.service +++ b/packaging/nfc-manager.service @@ -1,12 +1,15 @@ [Unit] Description=NFC manager After=system-server.service -Requires=system-server.service [Service] +User=system +Group=system Type=simple ExecStart=/usr/bin/nfc-manager-daemon --daemon KillSignal=SIGKILL +MemoryLimit=30M +SmackProcessLabel=nfc-manager [Install] WantedBy=multi-user.target diff --git a/packaging/nfc-manager.spec b/packaging/nfc-manager.spec index 9100f9f..e1e373f 100755 --- a/packaging/nfc-manager.spec +++ b/packaging/nfc-manager.spec @@ -1,128 +1,139 @@ -%bcond_with wayland -%bcond_with x - Name: nfc-manager Summary: NFC framework manager -Version: 0.1.6 +Version: 0.1.102 Release: 0 Group: Network & Connectivity/NFC -License: Flora +License: Apache-2.0 Source0: %{name}-%{version}.tar.gz -Source1: %{name}.service -Source1001: %{name}.manifest -BuildRequires: cmake -BuildRequires: pkgconfig(aul) -BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(gobject-2.0) -BuildRequires: pkgconfig(security-server) -BuildRequires: pkgconfig(vconf) -BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(tapi) -BuildRequires: pkgconfig(bluetooth-api) -BuildRequires: pkgconfig(capi-network-wifi) -BuildRequires: pkgconfig(mm-sound) -BuildRequires: pkgconfig(appsvc) -BuildRequires: pkgconfig(svi) -BuildRequires: pkgconfig(capi-media-wav-player) -BuildRequires: pkgconfig(libssl) -BuildRequires: pkgconfig(libcurl) -BuildRequires: pkgconfig(pkgmgr) -BuildRequires: pkgconfig(pkgmgr-info) -%if %{with x} -BuildRequires: pkgconfig(ecore-x) -%endif -%if %{with wayland} -BuildRequires: pkgconfig(ecore-wayland) -%endif -BuildRequires: pkgconfig(pmapi) -BuildRequires: pkgconfig(libtzplatform-config) -BuildRequires: python -BuildRequires: python-xml -BuildRequires: gettext-tools -%ifarch %arm aarch64 -BuildRequires: pkgconfig(wifi-direct) -%global ARM_DEF "-DARM_TARGET=Y" -%endif - -Requires(post): /sbin/ldconfig -Requires(post): /usr/bin/vconftool +Source1: nfc-manager.service +Requires: sys-assert +BuildRequires: cmake +BuildRequires: pkgconfig(aul) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gobject-2.0) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(tapi) +BuildRequires: pkgconfig(bluetooth-api) +BuildRequires: pkgconfig(capi-network-bluetooth) +BuildRequires: pkgconfig(mm-sound) +BuildRequires: pkgconfig(appsvc) +BuildRequires: pkgconfig(feedback) +BuildRequires: pkgconfig(capi-media-wav-player) +BuildRequires: pkgconfig(openssl) +BuildRequires: pkgconfig(deviced) +BuildRequires: pkgconfig(mm-keysound) +BuildRequires: pkgconfig(syspopup-caller) +BuildRequires: pkgconfig(notification) +BuildRequires: pkgconfig(capi-network-wifi) +BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(libxml-2.0) +BuildRequires: pkgconfig(libcurl) +BuildRequires: pkgconfig(libprivilege-control) +BuildRequires: python +BuildRequires: python-xml + +Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig -Requires: nfc-client-lib = %{version} %description -Tizen NFC framework manager. +A NFC Service Framework for support Tizen NFC. %prep %setup -q -cp %{SOURCE1001} . -%package -n nfc-common-devel +%package -n nfc-common-lib +Summary: NFC common library +Group: Development/Libraries + + +%description -n nfc-common-lib +A library for Tizen NFC Framework and Tizen NFC client library. + + +%package -n nfc-common-lib-devel Summary: NFC common library (devel) Group: Network & Connectivity/Development +Requires: nfc-common-lib = %{version}-%{release} -%description -n nfc-common-devel -NFC manager common header for internal development. +%description -n nfc-common-lib-devel +This package contains the development files for NFC Common library. %package -n nfc-client-lib Summary: NFC client library -Group: Network & Connectivity/NFC +Group: Development/Libraries +Requires: nfc-common-lib = %{version}-%{release} %description -n nfc-client-lib -NFC manager Client library for NFC client applications. +A library for Tizen NFC Client. %package -n nfc-client-lib-devel Summary: NFC client library (devel) Group: Network & Connectivity/Development -Requires: nfc-client-lib = %{version} +Requires: nfc-client-lib = %{version}-%{release} %description -n nfc-client-lib-devel -NFC manager Client library for developing NFC client applications. - - - -#%%package -n nfc-client-test -#Summary: NFC client test -#Group: Network & Connectivity/NFC -#Requires: %%{name} = %%{version} - - -#%%description -n nfc-client-test -#NFC client test (devel) - +This package contains the development files for NFC Client library. %build -MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} %{?ARM_DEF} \ -%if %{with wayland} - -DWAYLAND_SUPPORT=On \ -%else - -DWAYLAND_SUPPORT=Off \ -%endif -%if %{with x} - -DX11_SUPPORT=On -%else - -DX11_SUPPORT=Off +export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" +export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" +export CFLAGS="$CFLAGS -DTIZEN_TELEPHONY_ENABLED" + +export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed" +LDFLAGS="$LDFLAGS" cmake . \ + -DTIZEN_ENGINEER_MODE=1 \ + -DCMAKE_INSTALL_PREFIX=%{_prefix} \ + -DTIZEN_TELEPHONY_ENABLED=1 \ +%ifarch aarch64 + -DTIZEN_ARCH_64=1 \ %endif - %install %make_install mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants cp -af %{SOURCE1} %{buildroot}%{_libdir}/systemd/system/ + +mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants ln -s ../%{name}.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/%{name}.service +install -D -m 0644 LICENSE.Flora %{buildroot}/%{_datadir}/license/nfc-common-lib +install -D -m 0644 LICENSE.Flora %{buildroot}/%{_datadir}/license/%{name} +install -D -m 0644 LICENSE.Flora %{buildroot}/%{_datadir}/license/nfc-client-lib +#install -D -m 0644 LICENSE.Flora %{buildroot}/%{_datadir}/license/nfc-client-test + + %post /sbin/ldconfig +mkdir -p -m 700 /opt/usr/data/nfc-manager-daemon +/usr/bin/chsmack -a nfc-manager /opt/usr/data/nfc-manager-daemon +chown system:system /opt/usr/data/nfc-manager-daemon + +mkdir -p -m 744 /opt/usr/share/nfc_debug +/usr/bin/chsmack -a nfc-manager /opt/usr/share/nfc_debug +chown system:system /opt/usr/share/nfc_debug + +mkdir -p -m 744 /opt/usr/share/nfc-manager-daemon +/usr/bin/chsmack -a nfc-manager /opt/usr/share/nfc-manager-daemon +chown system:system /opt/usr/share/nfc-manager-daemon + +mkdir -p -m 744 /opt/usr/share/nfc-manager-daemon/message +/usr/bin/chsmack -a nfc-manager /opt/usr/share/nfc-manager-daemon/message +chown system:system /opt/usr/share/nfc-manager-daemon/message + systemctl daemon-reload if [ $1 == 1 ]; then systemctl restart %{name}.service @@ -131,59 +142,64 @@ fi %post -n nfc-client-lib /sbin/ldconfig -USER_GROUP_ID=$(getent group %{TZ_SYS_USER_GROUP} | cut -d: -f3) -vconftool set -t bool db/nfc/feature 0 -g $USER_GROUP_ID -f -vconftool set -t bool db/nfc/predefined_item_state 0 -g $USER_GROUP_ID -f -vconftool set -t string db/nfc/predefined_item "None" -g $USER_GROUP_ID -f -vconftool set -t bool db/nfc/enable 0 -g $USER_GROUP_ID -f -vconftool set -t int db/nfc/se_type 0 -g $USER_GROUP_ID -f +vconftool set -t string db/nfc/payment_handlers "" -u 200 -g 5000 -f -s tizen::vconf::nfc::admin +vconftool set -t string db/nfc/other_handlers "" -u 200 -g 5000 -f -s tizen::vconf::nfc::admin + +/usr/sbin/setcap cap_mac_override+ep /usr/bin/nfc-manager-daemon + +%postun -n nfc-client-lib -p /sbin/ldconfig %postun /sbin/ldconfig + if [ $1 == 0 ]; then systemctl stop %{name}.service fi systemctl daemon-reload -%postun -n nfc-client-lib -p /sbin/ldconfig +%post -n nfc-common-lib -p /sbin/ldconfig + + +%postun -n nfc-common-lib -p /sbin/ldconfig %files %manifest %{name}.manifest %defattr(-,root,root,-) %{_bindir}/nfc-manager-daemon -#%%{_bindir}/ndef-tool %{_libdir}/systemd/system/%{name}.service %{_libdir}/systemd/system/multi-user.target.wants/%{name}.service %{_datadir}/dbus-1/system-services/org.tizen.NetNfcService.service -%{_datadir}/packages/%{name}.xml -%{_datadir}/nfc-manager-daemon/sounds/* -%license LICENSE.Flora +%{_datadir}/license/%{name} %files -n nfc-client-lib -%manifest %{name}.manifest +%manifest nfc-client-lib.manifest %defattr(-,root,root,-) +%{_libdir}/libnfc.so %{_libdir}/libnfc.so.* -%license LICENSE.Flora +%{_datadir}/license/nfc-client-lib %files -n nfc-client-lib-devel +%manifest nfc-client-lib-devel.manifest %defattr(-,root,root,-) -%{_libdir}/libnfc.so %{_libdir}/pkgconfig/nfc.pc %{_includedir}/nfc/*.h -%files -n nfc-common-devel +%files -n nfc-common-lib +%manifest nfc-common-lib.manifest %defattr(-,root,root,-) -%{_libdir}/pkgconfig/nfc-common.pc -%{_includedir}/nfc-common/*.h +%{_libdir}/libnfc-common-lib.so +%{_libdir}/libnfc-common-lib.so.* +%{_datadir}/license/nfc-common-lib +%{_datadir}/nfc-manager-daemon/sounds/Operation_sdk.wav -#%%files -n nfc-client-test -#%%manifest nfc-client-test.manifest -#%%defattr(-,root,root,-) -#%%{_bindir}/nfc_client -#%%license LICENSE.Flora +%files -n nfc-common-lib-devel +%manifest nfc-common-lib-devel.manifest +%defattr(-,root,root,-) +%{_libdir}/pkgconfig/nfc-common-lib.pc +%{_includedir}/nfc-common-lib/*.h diff --git a/src/clientlib/CMakeLists.txt b/src/clientlib/CMakeLists.txt old mode 100644 new mode 100755 index 0488ff3..d5b5693 --- a/src/clientlib/CMakeLists.txt +++ b/src/clientlib/CMakeLists.txt @@ -1,5 +1,4 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -#PROJECT(nfc C) PROJECT(nfc-client-lib C) #SET(NFC_CLIENT_LIB "nfc-client-lib") @@ -7,9 +6,10 @@ SET(NFC_CLIENT_LIB "nfc") SET(VERSION_MAJOR 1) SET(VERSION ${VERSION_MAJOR}.0.0) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../commonlib/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../manager/include) +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) @@ -18,7 +18,7 @@ IF("${CMAKE_BUILD_TYPE}" STREQUAL "") ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") INCLUDE(FindPkgConfig) -pkg_check_modules(clientlib_pkges REQUIRED security-server dbus-glib-1 dlog ecore vconf) +pkg_check_modules(clientlib_pkges REQUIRED dlog vconf) FOREACH(flag ${clientlib_pkges_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -32,7 +32,7 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraph 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} -Werror-implicit-function-declaration -Wl,-z,nodelete") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") @@ -46,54 +46,58 @@ IF("${ARCH}" MATCHES "^arm.*") ENDIF() ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") -#ADD_DEFINITIONS("-DSLP_DEBUG") - -ADD_DEFINITIONS("-DNFC_FIRMWARE_UPDATE") -ADD_DEFINITIONS("-DNFC_DEBUG_USE_DLOG -D_GNU_SOURCE") -ADD_DEFINITIONS("-DUSE_UNIX_DOMAIN") -ADD_DEFINITIONS("-DUSE_IPC_EPOLL -DUSE_EPOLL_TIMEOUT") -ADD_DEFINITIONS("-DLLCP_MODE") -ADD_DEFINITIONS("-DNFC_APP_SUPPORTED") -ADD_DEFINITIONS("-DSAVE_TARGET_INFO_IN_CC") -#ADD_DEFINITIONS("-DSECURITY_SERVER") -#ADD_DEFINITIONS("-DG_MAIN_LOOP") -#ADD_DEFINITIONS("-DUSE_ECORE_MAIN_LOOP") -ADD_DEFINITIONS("-DUSE_GLIB_MAIN_LOOP") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") ADD_LIBRARY(${NFC_CLIENT_LIB} SHARED ${CLIENT_SRCS}) SET_TARGET_PROPERTIES(${NFC_CLIENT_LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${NFC_CLIENT_LIB} PROPERTIES VERSION ${VERSION}) -TARGET_LINK_LIBRARIES(${NFC_CLIENT_LIB} ${clientlib_pkges_LDFLAGS} "-L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/commonlib/" "-lnfc-common-lib") +TARGET_LINK_LIBRARIES(${NFC_CLIENT_LIB} ${clientlib_pkges_LDFLAGS} nfc-common-lib) + +LINK_DIRECTORIES(${CMAKE_BUILD_DIR}/src/commonlib) + SET(CLIENT_HEADER - ../commonlib/include/net_nfc_typedef.h + ${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_tag.h - include/net_nfc_tag_jewel.h - include/net_nfc_tag_mifare.h - include/net_nfc_tag_felica.h - include/net_nfc_llcp.h - include/net_nfc_ndef_record.h include/net_nfc_ndef_message.h - include/net_nfc_ndef_message_handover.h + include/net_nfc_ndef_record.h include/net_nfc_sign_record.h - include/net_nfc_data.h - include/net_nfc_exchanger.h - include/net_nfc_internal_se.h - include/net_nfc_test.h - ../manager/include/nfc-service-glue.h - ../manager/include/net_nfc_manager_dbus.h + 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_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 + include/net_nfc_client_hce.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_INSTALL_DIR}/pkgconfig) -INSTALL(TARGETS ${NFC_CLIENT_LIB} DESTINATION ${LIB_INSTALL_DIR}) +IF (TIZEN_ARCH_64) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${NFC_CLIENT_LIB}.pc DESTINATION /usr/lib64/pkgconfig) +ELSE (TIZEN_ARCH_64) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${NFC_CLIENT_LIB}.pc DESTINATION /usr/lib/pkgconfig) +ENDIF(TIZEN_ARCH_64) + +IF (TIZEN_ARCH_64) + INSTALL(TARGETS ${NFC_CLIENT_LIB} DESTINATION lib64) +ELSE (TIZEN_ARCH_64) + INSTALL(TARGETS ${NFC_CLIENT_LIB} DESTINATION lib) +ENDIF(TIZEN_ARCH_64) FOREACH(hfile ${CLIENT_HEADER}) - INSTALL(FILES ${hfile} DESTINATION include/nfc) + INSTALL(FILES ${hfile} DESTINATION include/nfc) ENDFOREACH(hfile) - diff --git a/src/clientlib/include/net_nfc.h b/src/clientlib/include/net_nfc.h new file mode 100755 index 0000000..1e97731 --- /dev/null +++ b/src/clientlib/include/net_nfc.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_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" +#include "net_nfc_client_hce.h" + + +#endif //__NET_NFC_H__ diff --git a/src/clientlib/include/net_nfc_client.h b/src/clientlib/include/net_nfc_client.h new file mode 100755 index 0000000..107cdd9 --- /dev/null +++ b/src/clientlib/include/net_nfc_client.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#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__ diff --git a/src/clientlib/include/net_nfc_client_context.h b/src/clientlib/include/net_nfc_client_context.h new file mode 100755 index 0000000..36b9864 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_context.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ diff --git a/src/clientlib/include/net_nfc_client_handover.h b/src/clientlib/include/net_nfc_client_handover.h new file mode 100755 index 0000000..52aaf98 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_handover.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 enum +{ + NET_NFC_HANDOVER_START, + NET_NFC_HANDOVER_FINISH, +} +net_nfc_handover_event_e; + +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); + +typedef void (*net_nfc_connection_handover_event_cb)( + net_nfc_handover_event_e event, + net_nfc_error_e result, + net_nfc_conn_handover_carrier_type_e carrier, + data_h ac_data, + data_h ndef_message, + void *user_data); + +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); + + +void net_nfc_client_handover_set_handover_event_cb( + net_nfc_connection_handover_event_cb callback, + void *user_data); + +void net_nfc_client_handover_unset_handover_event_cb(void); + + +/* 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__ diff --git a/src/clientlib/include/net_nfc_client_hce.h b/src/clientlib/include/net_nfc_client_hce.h new file mode 100755 index 0000000..da96271 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_hce.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_HCE_H__ +#define __NET_NFC_CLIENT_HCE_H__ + +#include "net_nfc_typedef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*************Hce Callbacks*********/ + +typedef void (*net_nfc_client_hce_event_cb)( + net_nfc_target_handle_h handle, + net_nfc_hce_event_t event, + data_h apdu, + void *user_data); + +/************* Hce API's*************/ + +net_nfc_error_e net_nfc_client_hce_set_event_received_cb( + net_nfc_client_hce_event_cb callback, void *user_data); +net_nfc_error_e net_nfc_client_hce_unset_event_received_cb(void); + +net_nfc_error_e net_nfc_client_hce_response_apdu_sync( + net_nfc_target_handle_h handle, data_h resp_apdu_data); + + +/* internal */ +net_nfc_error_e net_nfc_client_hce_init(void); +void net_nfc_client_hce_deinit(void); + +#ifdef __cplusplus +} +#endif + +#endif //__NET_NFC_CLIENT_HCE_H__ diff --git a/src/clientlib/include/net_nfc_client_llcp.h b/src/clientlib/include/net_nfc_client_llcp.h new file mode 100755 index 0000000..a8204e7 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_llcp.h @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_accept_completed)(net_nfc_error_e result, + void *user_data); + +typedef void (*net_nfc_client_llcp_reject_completed)(net_nfc_error_e result, + 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, + void *user_data); + +typedef void (*net_nfc_client_llcp_send_to_completed)(net_nfc_error_e result, + 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, + void *user_data); + +typedef void (*net_nfc_client_llcp_disconnect_completed)( + net_nfc_error_e result, + 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_accept(net_nfc_llcp_socket_t socket, + net_nfc_client_llcp_accept_completed callback, + void *user_data); + +net_nfc_error_e net_nfc_client_llcp_accept_sync(net_nfc_llcp_socket_t socket); + +net_nfc_error_e net_nfc_client_llcp_reject(net_nfc_llcp_socket_t socket, + net_nfc_client_llcp_reject_completed callback, + void *user_data); + +net_nfc_error_e net_nfc_client_llcp_reject_sync(net_nfc_llcp_socket_t 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_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_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_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); + +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__ diff --git a/src/clientlib/include/net_nfc_client_manager.h b/src/clientlib/include/net_nfc_client_manager.h new file mode 100755 index 0000000..094d437 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_manager.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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); + +bool net_nfc_client_manager_is_activated(void); + +/* TODO : move to internal header */ +net_nfc_error_e net_nfc_client_manager_init(void); + +void net_nfc_client_manager_deinit(void); + +#ifdef __cplusplus +} +#endif + +#endif //__NET_NFC_CLIENT_MANAGER_H__ diff --git a/src/clientlib/include/net_nfc_client_ndef.h b/src/clientlib/include/net_nfc_client_ndef.h new file mode 100755 index 0000000..cdaf312 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_ndef.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ diff --git a/src/clientlib/include/net_nfc_client_p2p.h b/src/clientlib/include/net_nfc_client_p2p.h new file mode 100755 index 0000000..58b97aa --- /dev/null +++ b/src/clientlib/include/net_nfc_client_p2p.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_target_handle_h handle, + data_h data, + net_nfc_client_p2p_send_completed callback, + void *user_data); + +net_nfc_error_e net_nfc_client_p2p_send_sync(net_nfc_target_handle_h handle, + data_h data); + + +/* 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__ diff --git a/src/clientlib/include/net_nfc_client_se.h b/src/clientlib/include/net_nfc_client_se.h new file mode 100755 index 0000000..c5cfad9 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_se.h @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "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_get_se_cb)( + net_nfc_error_e result, + net_nfc_se_type_e se_type, + void *user_data); + +typedef void (*net_nfc_se_set_card_emulation_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)( + net_nfc_se_type_e se_type, + 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); + +typedef bool (*net_nfc_client_se_registered_aid_cb)(net_nfc_se_type_e se_type, + const char *aid, bool readonly, void *user_data); + +typedef bool (*net_nfc_client_se_registered_handler_cb)(const char *package, + 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_sync( + net_nfc_se_type_e *se_type); + +net_nfc_error_e net_nfc_set_card_emulation_mode_sync( + net_nfc_card_emulation_mode_t mode); + +net_nfc_error_e net_nfc_get_card_emulation_mode_sync( + net_nfc_card_emulation_mode_t *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_se_type_e se_type, + net_nfc_client_se_transaction_event callback, + void *user_data); + +void net_nfc_client_se_unset_transaction_event_cb(net_nfc_se_type_e type); + +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); + +net_nfc_error_e net_nfc_client_se_set_transaction_fg_dispatch(int mode); + + +/* new card emulation */ +net_nfc_error_e net_nfc_client_se_is_activated_aid_handler_sync( + net_nfc_se_type_e se_type, const char *aid, bool *activated); + +net_nfc_error_e net_nfc_client_se_is_activated_category_handler_sync( + net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, bool *activated); + +net_nfc_error_e net_nfc_client_se_get_registered_aids_count_sync( + net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + size_t *count); + +net_nfc_error_e net_nfc_client_se_foreach_registered_aids_sync( + net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + net_nfc_client_se_registered_aid_cb callback, + void *user_data); + +net_nfc_error_e net_nfc_client_se_register_aids_sync(net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, const char *aid, ...); +net_nfc_error_e net_nfc_client_se_unregister_aid_sync(net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, const char *aid); +net_nfc_error_e net_nfc_client_se_unregister_aids_sync(net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category); + + +net_nfc_error_e net_nfc_client_se_set_default_route_sync( + net_nfc_se_type_e switch_on, net_nfc_se_type_e switch_off, + net_nfc_se_type_e battery_off); + +/* internal */ +net_nfc_error_e net_nfc_client_se_add_route_aid_sync( + const char *package, net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, const char *aid, + bool unlock_required, int power); + +net_nfc_error_e net_nfc_client_se_remove_route_aid_sync( + const char *package, const char *aid); + +net_nfc_error_e net_nfc_client_se_remove_package_aids_sync( + const char *package); + +net_nfc_error_e net_nfc_client_se_foreach_registered_handlers_sync( + net_nfc_card_emulation_category_t category, + net_nfc_client_se_registered_handler_cb callback, + void *user_data); + +//net_nfc_error_e net_nfc_client_hce_get_route_table_sync(data_h arg_aid); + + +/* 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__ diff --git a/src/clientlib/include/net_nfc_client_snep.h b/src/clientlib/include/net_nfc_client_snep.h new file mode 100755 index 0000000..25c925e --- /dev/null +++ b/src/clientlib/include/net_nfc_client_snep.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ diff --git a/src/clientlib/include/net_nfc_client_system_handler.h b/src/clientlib/include/net_nfc_client_system_handler.h new file mode 100755 index 0000000..b384fa6 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_system_handler.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ diff --git a/src/clientlib/include/net_nfc_client_tag.h b/src/clientlib/include/net_nfc_client_tag.h new file mode 100755 index 0000000..3f67bf1 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_tag.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#if 0 +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); +#endif +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); + +#if 0 +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_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_target_handle( + net_nfc_client_tag_get_current_target_handle_completed callback, + void *user_data); +#endif +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_sync( + net_nfc_target_info_h *info); + +net_nfc_error_e net_nfc_client_barcode_get_barcode_sync( + unsigned char **barcode, int* barcode_len); + +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); + + +/* internal function */ +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__ diff --git a/src/clientlib/include/net_nfc_client_tag_felica.h b/src/clientlib/include/net_nfc_client_tag_felica.h new file mode 100755 index 0000000..29231bf --- /dev/null +++ b/src/clientlib/include/net_nfc_client_tag_felica.h @@ -0,0 +1,266 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ diff --git a/src/clientlib/include/net_nfc_client_tag_internal.h b/src/clientlib/include/net_nfc_client_tag_internal.h new file mode 100755 index 0000000..11220d9 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_tag_internal.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#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__ diff --git a/src/clientlib/include/net_nfc_client_tag_jewel.h b/src/clientlib/include/net_nfc_client_tag_jewel.h new file mode 100755 index 0000000..04774cb --- /dev/null +++ b/src/clientlib/include/net_nfc_client_tag_jewel.h @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ diff --git a/src/clientlib/include/net_nfc_client_test.h b/src/clientlib/include/net_nfc_client_test.h new file mode 100755 index 0000000..2fa8bc4 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_test.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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); + +typedef void (*net_nfc_client_test_ese_test_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); + +net_nfc_error_e net_nfc_client_test_ese_test( + net_nfc_client_test_sim_test_completed callback, + void *user_data); + +net_nfc_error_e net_nfc_client_test_ese_test_sync(void); + + + +net_nfc_error_e net_nfc_client_test_set_se_tech_type_sync(net_nfc_se_type_e type, int tech); + +/* 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__ diff --git a/src/clientlib/include/net_nfc_client_transceive.h b/src/clientlib/include/net_nfc_client_transceive.h new file mode 100755 index 0000000..95bfb75 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_transceive.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ diff --git a/src/clientlib/include/net_nfc_client_util_internal.h b/src/clientlib/include/net_nfc_client_util_internal.h new file mode 100755 index 0000000..54bc92f --- /dev/null +++ b/src/clientlib/include/net_nfc_client_util_internal.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +typedef struct _NetNfcCallback +{ + void *callback; + void *user_data; +} +NetNfcCallback; + +#ifdef __cplusplus +} +#endif + +#endif //__NET_NFC_CLIENT_UTIL_INTERNAL_H__ diff --git a/src/clientlib/include/net_nfc_data.h b/src/clientlib/include/net_nfc_data.h new file mode 100755 index 0000000..07c2a73 --- /dev/null +++ b/src/clientlib/include/net_nfc_data.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + +@addtogroup NET_NFC_MANAGER_INFO +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + + @li @c #net_nfc_initialize Initialize the nfc device. + +*/ + +/** + create data handler only. + + @param[out] data data handler + + @return return the result of this operation + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal 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) illegal 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, size_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) illegal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_get_data(const data_h data, uint8_t **bytes, size_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) illegal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_set_data(data_h data, const uint8_t *bytes, size_t length); + +/** + get length of data handler's bytes. + + @param[in] data data handler + + @return return the length of bytes + + @exception 0 is returned if data is NULL +*/ + +size_t net_nfc_get_data_length(const data_h data); + +/** + get pointer of the handler's bytes (do not free this. it should be freed when the application call "net_nfc_free_data" function) + + @param[in] data data handler + + @return 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) illegal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_free_data(data_h data); + + +/** +@} +*/ +#ifdef __cplusplus +} +#endif + +#endif //__NET_NFC_DATA_H__ diff --git a/src/clientlib/include/net_nfc_internal_se.h b/src/clientlib/include/net_nfc_internal_se.h deleted file mode 100755 index 20b5df0..0000000 --- a/src/clientlib/include/net_nfc_internal_se.h +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NET_NFC_INTERNAL_SE_H__ -#define __NET_NFC_INTERNAL_SE_H__ - -#include "net_nfc_typedef.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** - -@addtogroup NET_NFC_MANAGER_SECURE_ELEMENT -@{ - This document is for the APIs reference document - - NFC Manager defines are defined in - - @li @c #net_nfc_set_secure_element_type set secure element type - @li @c #net_nfc_get_secure_element_type get current selected secure element - @li @c #net_nfc_open_internal_secure_element open selected secure element - @li @c #net_nfc_open_internal_secure_element_sync open selected secure element (synchronous) - @li @c #net_nfc_close_internal_secure_element close selected secure element - @li @c #net_nfc_close_internal_secure_element_sync close selected secure element (synchronous) - @li @c #net_nfc_send_apdu send apdu to opened secure element - @li @c #net_nfc_send_apdu_sync send apdu to opened secure element (synchronous) - @li @c #net_nfc_get_atr request atr of secure element - @li @c #net_nfc_get_atr_sync request atr of secure element (synchronous) -*/ - -/** - set secure element type. secure element will be a UICC or ESE. - only one secure element is selected in a time. - external reader can communicate with secure element by emitting RF - - \par Sync (or) Async: Sync - This is a Asynchronous API - - @param[in] se_type secure element type - @param[in] trans_param user data that will be delivered to callback - - @return return the result of the calling the function - - @exception NET_NFC_INVALID_PARAM not supported se_type -*/ -net_nfc_error_e net_nfc_set_secure_element_type(net_nfc_se_type_e se_type, void *trans_param); - -/** - get current select se type. - - \par Sync (or) Async: Async - This is a Asynchronous API - - @param[in] trans_param user data that will be delivered to callback - - @return return the result of the calling the function -*/ -net_nfc_error_e net_nfc_get_secure_element_type(void *trans_param); - -/** - open and initialize the type of secure element. - if the type of secure element is selected, then change mode as MODE OFF - to prevent to be detected by external reader - - \par Sync (or) Async: Async - This is a Asynchronous API - - @param[in] se_type secure element type - @param[in] trans_param user data that will be delivered to callback - - @return return the result of the calling the function - - @exception NET_NFC_INVALID_PARAM not supported se_type -*/ -net_nfc_error_e net_nfc_open_internal_secure_element(net_nfc_se_type_e se_type, void *trans_param); - -/** - open and initialize the type of secure element. - if the type of secure element is selected, then change mode as MODE OFF - to prevent to be detected by external reader - - \par Sync (or) Async: Sync - This is a Asynchronous API - - @param[in] se_type secure element type - @param[out] handle the handle of opened secure element - - @return return the result of the calling the function - - @exception NET_NFC_INVALID_PARAM not supported se_type -*/ -net_nfc_error_e net_nfc_open_internal_secure_element_sync(net_nfc_se_type_e se_type, net_nfc_target_handle_h *handle); - -/** - close opened secure element and change back to previous setting - - \par Sync (or) Async: Async - This is a Asynchronous API - - @param[in] handle the handle of opened secure element - @param[in] trans_param user data that will be delivered to callback - - @return return the result of the calling the function - - @exception NET_NFC_INVALID_PARAM invalid secure element handle -*/ -net_nfc_error_e net_nfc_close_internal_secure_element(net_nfc_target_handle_h handle, void *trans_param); - -/** - close opened secure element and change back to previous setting - - \par Sync (or) Async: Sync - This is a Asynchronous API - - @param[in] handle the handle of opened secure element - - @return return the result of the calling the function - - @exception NET_NFC_INVALID_PARAM invalid secure element handle -*/ -net_nfc_error_e net_nfc_close_internal_secure_element_sync(net_nfc_target_handle_h handle); - -/** - send apdu to opened secure element - - \par Sync (or) Async: Async - This is a Asynchronous API - - @param[in] handle the handle of opened secure element - @param[in] apdu apdu command to send - @param[in] trans_param user data that will be delivered to callback - - @return return the result of the calling the function - - @exception NET_NFC_INVALID_PARAM invalid secure element handle - @exception NET_NFC_NULL_PARAM data is null or empty -*/ -net_nfc_error_e net_nfc_send_apdu(net_nfc_target_handle_h handle, data_h apdu, void *trans_param); - -/** - send apdu to opened secure element - - \par Sync (or) Async: Async - This is a Asynchronous API - - @param[in] handle the handle of opened secure element - @param[in] apdu apdu command to send - @param[out] response result of apdu - - @return return the result of the calling the function - - @exception NET_NFC_INVALID_PARAM invalid secure element handle or parameter - @exception NET_NFC_NULL_PARAM data is null or empty -*/ -net_nfc_error_e net_nfc_send_apdu_sync(net_nfc_target_handle_h handle, data_h apdu, data_h *response); - -/** - request atr of secure element - - \par Sync (or) Async: Async - This is a Asynchronous API - - @param[in] handle the handle of opened secure element - @param[in] trans_param user data that will be delivered to callback - - @return return the result of the calling the function - - @exception NET_NFC_INVALID_PARAM invalid - -*/ -net_nfc_error_e net_nfc_get_atr(net_nfc_target_handle_h handle, void *trans_param); - -/** - request atr of secure element - - \par Sync (or) Async: Sync - This is a Asynchronous API - - @param[in] handle the handle of opened secure element - @param[out] atr Answer to reset of secure element - - @return return the result of the calling the function - - @exception NET_NFC_INVALID_PARAM invalid - -*/ -net_nfc_error_e net_nfc_get_atr_sync(net_nfc_target_handle_h handle, data_h *atr); - -/** - set card emulation mode of secure element - - \par Sync (or) Async: Sync - This is a Synchronous API - - @param[in] se_mode the mode of card emulation - - @return return the result of the calling the function - - @exception NET_NFC_INVALID_PARAM invalid - -*/ -net_nfc_error_e net_nfc_set_card_emulation_mode_sync(net_nfc_card_emulation_mode_t se_mode); - - -/** - set type of secure element - - \par Sync (or) Async: Sync - This is a Synchronous API - - @param[in] se_type the type of secure element - - @return return the result of the calling the function - - @exception NET_NFC_INVALID_PARAM invalid - -*/ -net_nfc_error_e net_nfc_set_secure_element_type_sync(net_nfc_se_type_e se_type); - -#ifdef __cplusplus -} -#endif - - -#endif - diff --git a/src/clientlib/include/net_nfc_ndef_message.h b/src/clientlib/include/net_nfc_ndef_message.h index 66eb8c5..a6b608a 100755 --- a/src/clientlib/include/net_nfc_ndef_message.h +++ b/src/clientlib/include/net_nfc_ndef_message.h @@ -1,19 +1,18 @@ /* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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. + */ #ifndef __NET_NFC_NDEF_MESSAGE_H__ #define __NET_NFC_NDEF_MESSAGE_H__ @@ -21,7 +20,7 @@ #include "net_nfc_typedef.h" #ifdef __cplusplus - extern "C" { +extern "C" { #endif @@ -73,7 +72,7 @@ */ -net_nfc_error_e net_nfc_create_ndef_message (ndef_message_h* ndef_message); +net_nfc_error_e net_nfc_create_ndef_message(ndef_message_h *ndef_message); /** this APIs is the getter of record counts @@ -110,7 +109,7 @@ net_nfc_error_e net_nfc_create_ndef_message (ndef_message_h* ndef_message); } @endcode */ -net_nfc_error_e net_nfc_get_ndef_message_record_count (ndef_message_h ndef_message, int * count); +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. @@ -165,7 +164,7 @@ net_nfc_error_e net_nfc_get_ndef_message_record_count (ndef_message_h ndef_messa */ -net_nfc_error_e net_nfc_create_rawdata_from_ndef_message (ndef_message_h ndef_message, data_h* rawdata); +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. @@ -219,7 +218,7 @@ net_nfc_error_e net_nfc_create_rawdata_from_ndef_message (ndef_message_h ndef_me */ -net_nfc_error_e net_nfc_create_ndef_message_from_rawdata (ndef_message_h* ndef_message, data_h rawdata); +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 @@ -240,7 +239,7 @@ net_nfc_error_e net_nfc_create_ndef_message_from_rawdata (ndef_message_h* ndef_m */ -net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, uint32_t *length) ; +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 @@ -309,7 +308,7 @@ net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_messag */ -net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int index); +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. @@ -328,7 +327,7 @@ net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int @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); +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. @@ -347,7 +346,7 @@ net_nfc_error_e net_nfc_get_record_by_index (ndef_message_h ndef_message, int in @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); +net_nfc_error_e net_nfc_append_record_by_index(ndef_message_h ndef_message, int index, ndef_record_h record); /** @@ -390,7 +389,7 @@ net_nfc_error_e net_nfc_append_record_by_index (ndef_message_h ndef_message,int @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); +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); /** @@ -431,7 +430,7 @@ net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message); */ -net_nfc_error_e net_nfc_retrieve_current_ndef_message (ndef_message_h* ndef_message); +net_nfc_error_e net_nfc_retrieve_current_ndef_message(ndef_message_h *ndef_message); /** @@ -442,6 +441,4 @@ net_nfc_error_e net_nfc_retrieve_current_ndef_message (ndef_message_h* ndef_mess } #endif - -#endif - +#endif //__NET_NFC_NDEF_MESSAGE_H__ diff --git a/src/clientlib/include/net_nfc_ndef_message_handover.h b/src/clientlib/include/net_nfc_ndef_message_handover.h new file mode 100755 index 0000000..55d1705 --- /dev/null +++ b/src/clientlib/include/net_nfc_ndef_message_handover.h @@ -0,0 +1,331 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 carrier configure handler instance. + + @param[out] config instance handler + @param[in] type Carrier types. It would be BT or WPS or etc. + + @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_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 attribute 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) illegal 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 with CREDENTIAL key. + The the attribute is exist then it will be removed and also freed automatically. + + @param[in] config instance handler + @param[in] attribute attribute key for value. + + @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_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 attribute 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) illegal 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) illegal 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) illegal 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] attribute group attribute + @param[out] group group handle + + @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_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 damaged +*/ +net_nfc_error_e net_nfc_get_carrier_config_group(net_nfc_carrier_config_h config, uint16_t attribute, 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) illegal 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 + @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) illegal 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) illegal 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) illegal 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) illegal 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) illegal 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 carrier configure handle + + @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 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 record must contained the configuration. + config should be freed after using + + @param[out] config the configure handle + @param[in] record record handler + + @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 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); + +net_nfc_error_e net_nfc_create_carrier_config_from_carrier( + net_nfc_carrier_config_h *config, net_nfc_ch_carrier_h carrier); + +net_nfc_error_e net_nfc_create_handover_carrier(net_nfc_ch_carrier_h *carrier, + net_nfc_conn_handover_carrier_state_e cps); + +net_nfc_error_e net_nfc_duplicate_handover_carrier(net_nfc_ch_carrier_h *dest, + net_nfc_ch_carrier_h src); + +net_nfc_error_e net_nfc_free_handover_carrier(net_nfc_ch_carrier_h carrier); + +net_nfc_error_e net_nfc_set_handover_carrier_cps( + net_nfc_ch_carrier_h carrier, + net_nfc_conn_handover_carrier_state_e cps); + +net_nfc_error_e net_nfc_get_handover_carrier_cps( + net_nfc_ch_carrier_h carrier, + net_nfc_conn_handover_carrier_state_e *cps); + +net_nfc_error_e net_nfc_set_handover_carrier_type( + net_nfc_ch_carrier_h carrier, + net_nfc_conn_handover_carrier_type_e type); + +net_nfc_error_e net_nfc_get_handover_carrier_type( + net_nfc_ch_carrier_h carrier, + net_nfc_conn_handover_carrier_type_e *type); + +net_nfc_error_e net_nfc_append_handover_carrier_record( + net_nfc_ch_carrier_h carrier, ndef_record_h record); + +net_nfc_error_e net_nfc_get_handover_carrier_record( + net_nfc_ch_carrier_h carrier, ndef_record_h *record); + +net_nfc_error_e net_nfc_remove_handover_carrier_record( + net_nfc_ch_carrier_h carrier); + +net_nfc_error_e net_nfc_append_handover_auxiliary_record( + net_nfc_ch_carrier_h carrier, ndef_record_h record); + +net_nfc_error_e net_nfc_get_handover_auxiliary_record_count( + net_nfc_ch_carrier_h carrier, uint32_t *count); + +net_nfc_error_e net_nfc_get_handover_auxiliary_record( + net_nfc_ch_carrier_h carrier, int index, ndef_record_h *record); + +net_nfc_error_e net_nfc_remove_handover_auxiliary_record( + net_nfc_ch_carrier_h carrier, ndef_record_h record); + + +net_nfc_error_e net_nfc_create_handover_message(net_nfc_ch_message_h *message); + +net_nfc_error_e net_nfc_free_handover_message(net_nfc_ch_message_h message); + +net_nfc_error_e net_nfc_get_handover_random_number(net_nfc_ch_message_h message, + uint16_t *random_number); + +net_nfc_error_e net_nfc_append_handover_carrier(net_nfc_ch_message_h message, + net_nfc_ch_carrier_h carrier); + +net_nfc_error_e net_nfc_get_handover_carrier_count(net_nfc_ch_message_h message, + uint32_t *count); + +net_nfc_error_e net_nfc_get_handover_carrier(net_nfc_ch_message_h message, + int index, net_nfc_ch_carrier_h *carrier); + +net_nfc_error_e net_nfc_get_handover_carrier_by_type( + net_nfc_ch_message_h message, + net_nfc_conn_handover_carrier_type_e type, + net_nfc_ch_carrier_h *carrier); + +net_nfc_error_e net_nfc_export_handover_to_ndef_message( + net_nfc_ch_message_h message, ndef_message_h *result); + +net_nfc_error_e net_nfc_import_handover_from_ndef_message( + ndef_message_h msg, net_nfc_ch_message_h *result); + +/** + create 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) illegal 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__ diff --git a/src/clientlib/include/net_nfc_ndef_record.h b/src/clientlib/include/net_nfc_ndef_record.h new file mode 100755 index 0000000..36957c3 --- /dev/null +++ b/src/clientlib/include/net_nfc_ndef_record.h @@ -0,0 +1,369 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NET_NFC_NDEF_RECORD_H__ +#define __NET_NFC_NDEF_RECORD_H__ + +#include "net_nfc_typedef.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + +@addtogroup NET_NFC_MANAGER_RECORD +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + +*/ + + +/** + This define gives you Message Begin from the flag byte + + @param[in] flag flag that comes from "net_nfc_get_record_flags" function + @return the mb flag + + @exception NONE +*/ +uint8_t net_nfc_get_record_mb(uint8_t flag); +/** + This define gives you Message end from the flag byte + + @param[in] flag flag that comes from "net_nfc_get_record_flags" function + @return the me flag + + @exception NONE +*/ +uint8_t net_nfc_get_record_me(uint8_t flag); +/** + This define gives you Chun Flag that indicate that either the first record chunk or a middle record chunk of a chunked payload + + @param[in] flag flag that comes from "net_nfc_get_record_flags" function + @return the chunk flag + + @exception NONE +*/ +uint8_t net_nfc_get_record_cf(uint8_t flag); +/** + This define gives you ID length present flag + + @param[in] flag flag that comes from "net_nfc_get_record_flags" function + @return the il (id length flag) flag + + @exception NONE + +*/ +uint8_t net_nfc_get_record_il(uint8_t flag); +/** + This define gives you short record flag. This flag indicates that the payload length filed is a single octet + + @param[in] flag flag that comes from "net_nfc_get_record_flags" function + @return the short record flag + + @exception NONE +*/ +uint8_t net_nfc_get_record_sr(uint8_t flag); + + + +/** + creat a record with given parameter value. this function automatically set the NDEF record flags + + @param[out] record Record handler + @param[in] tnf record type (TNF value) empty, well known, mime type, URI, external, or unchanged + @param[in] typeName specify type name ex) Sp, U, or Hr ... + @param[in] id record id + @param[in] payload payload of this record + + @return return the result of the calling the function + + @exception NET_NFC_OUT_OF_BOUND tnf value is out of range + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + char uri[] = " yahoo.com"; + ndef_record_s uriRecord; + + data_h payload; + + net_nfc_create_data (&payload, uri, strlen (uri)); + uri[0] = 0x01; + + if((result = net_nfc_create_record( &uriRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE, "U" , NULL, payload, )) != NET_NFC_OK) + { + printf("U record is failed [%d]\n", result); + } + @endcode +*/ +net_nfc_error_e net_nfc_create_record(ndef_record_h *record, net_nfc_record_tnf_e tnf, data_h typeName, data_h id, data_h payload); + + +/** + this function helps to create text type payload + please, refer the NDEF forum specification "Text Record Type Definition" + it creates byte array payload can be used in text type record + + this function does not encode the text. The paramter "text" will be asuumed as that it is already encoded with encode type. + this function just helps to create text records. + + @param[out] record Record handler + @param[in] text encoded text (this should be text not binary) + @param[in] language_code_str language_code_str ex) en-US + @param[in] encode text concoding type such as "utf8" + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + + @code + net_nfc_error_e result = NET_NFC_OK; + ndef_message_h msg = NULL; + ndef_record_h record = NULL; + + char* message = "Hello, NFC World"; + + net_nfc_create_ndef_message (&msg); + net_nfc_create_text_type_record (&record , message, "en-US", NET_NFC_ENCODE_UTF_8); + net_nfc_append_record_to_ndef_message (msg ,record); + + @endcode + +*/ +net_nfc_error_e net_nfc_create_text_type_record(ndef_record_h *record, const char *text, const char *language_code_str, net_nfc_encode_type_e encode); + +/** + this function helps to create URI type payload + please refer the NFC forum specification "URI Record type Definition" + it creates byte array payload. + + @param[out] record Record handler + @param[in] uri string uri that will be stored in the payload + @param[in] protocol_schema protocol schema that is specified in NFC Forum + + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + net_nfc_error_e result = NET_NFC_OK; + ndef_message_h msg = NULL; + ndef_record_h record = NULL; + + net_nfc_create_ndef_message (&msg); + net_nfc_create_uri_type_record (&record ,"http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI); + net_nfc_append_record_to_ndef_message (msg ,record); + @endcode +*/ + +net_nfc_error_e net_nfc_create_uri_type_record(ndef_record_h *record, const char *uri, net_nfc_schema_type_e protocol_schema); + +/** + this function is getter of record payload. + this function gives you the pointer of pyaload that is contained by record. + Do not free the payload. it will be freed when the record is freed + + @param[in] record Record handler + @param[out] payload data_h type payload pointer (it gives you the pointer of payload; not copied) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ +net_nfc_error_e net_nfc_get_record_payload(ndef_record_h record, data_h *payload); + +/** + this function is getter of record type. + this function gives you the pointer of record type that is contained by record. + Do not free the type. it will be freed when the record is freed + + @param[in] record Record handler + @param[out] type dat_h type pointer (it gives you the pointer of type; not copied) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ +net_nfc_error_e net_nfc_get_record_type(ndef_record_h record, data_h *type); + +/** + this function is getter of record ID. + this function gives you the pointer of ID that is contained by record. + it may return NULL pointer if the ID is not exist + Do not free the type. it will be freed when the record is freed. + + @param[in] record Record handler + @param[out] id dat_h type ID pointer (it gives you the pointer of payload not copied) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_get_record_id(ndef_record_h record, data_h *id); + +/** + this function is getter of record TNF value. + + @param[in] record Record handler + @param[out] tnf TNF value + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + + +*/ +net_nfc_error_e net_nfc_get_record_tnf(ndef_record_h record, net_nfc_record_tnf_e *tnf); + +/** + this function is getter of record flags. + you can get the each flag value by using defines "RECORD_GET_XX" + + @param[in] record Record handler + @param[out] flag flag value (it gives you the pointer of payload not copied) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + + @code + + ndef_record_h record; + uint8_t flag; + + net_nfc_get_record_by_index (msg, 0, &record); + if (record != NULL){ + net_nfc_get_record_flags (record, &flag); + printf ("MB:%d, ME:%d, CF:%d, IL:%d, SR:%d\n", + net_nfc_get_record_mb(flag), + net_nfc_get_record_me(flag), + net_nfc_get_record_cf(flag), + net_nfc_get_record_il(flag), + net_nfc_get_record_sr(flag)); + } + + @endcode + +*/ +net_nfc_error_e net_nfc_get_record_flags(ndef_record_h record, uint8_t *flag); + + +/** + you can set record ID with this function + + @param[in] record Record handler + @param[in] id Record ID + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ +net_nfc_error_e net_nfc_set_record_id(ndef_record_h record, data_h id); + +/** + this function free the record handler. do not use this function after appending the ndef message + + @param[in] record Record handler + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ +net_nfc_error_e net_nfc_free_record(ndef_record_h record); + + +/** + this function get text from text record. it allocate buffer char and store the text string. you should free this string. + + @param[in] record Record handler + @param[out] buffer text string + + @return return the result of the calling the function + + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char **buffer); + +/** + this function get language code from text record. (ex: US-en) + + @param[in] record Record handler + @param[out] lang_code_str lang code string value followed by IANA + + @return return the result of the calling the function + + @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_get_languange_code_string_from_text_record(ndef_record_h record, char **lang_code_str); + + +/** + this function get encoding type from text record (ex: UTF-8) + + @param[in] record Record handler + @param[out] encoding encoding type + + @return return the result of the calling the function + + @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_get_encoding_type_from_text_record(ndef_record_h record, net_nfc_encode_type_e *encoding); + + +/** + this function get URI from uri record. you should free the uri string. + + @param[in] record Record handler + @param[out] uri uri text string + + @return return the result of the calling the function + + @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not uri record + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char **uri); + +#ifdef __cplusplus +} +#endif + + +#endif //__NET_NFC_NDEF_RECORD_H__ diff --git a/src/clientlib/include/net_nfc_sign_record.h b/src/clientlib/include/net_nfc_sign_record.h new file mode 100755 index 0000000..b1ab6c2 --- /dev/null +++ b/src/clientlib/include/net_nfc_sign_record.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __NET_NFC_SIGN_RECORD_H__ +#define __NET_NFC_SIGN_RECORD_H__ + +#include "net_nfc_typedef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + +/** + +@addtogroup NET_NFC_MANAGER_RECORD +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + +*/ + +/** + this function make the signature of some continuous records + please refer the NFC forum specification "Signature Record type Definition" + + @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added. + @param[in] begin_index the index of beginning record that will be signed. + @param[in] end_index the last index of record that will be signed. + @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type) + @param[in] passowrd the password of cert_file + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + ndef_message_h msg = NULL; + + // create a ndef message and add some records + // ... + + net_nfc_sign_records(msg, 0, 1, "/tmp/cert.p12", "abcdef"); + @endcode +*/ +net_nfc_error_e net_nfc_sign_records(ndef_message_h msg, int begin_index, int end_index, char *cert_file, char *password); + +/** + this function make the signature of whole records in NDEF message + + @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added. + @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type) + @param[in] passowrd the password of cert_file + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + ndef_message_h msg = NULL; + + // create a ndef message and add some records + // ... + + net_nfc_sign_ndef_message(msg, "/tmp/cert.p12", "abcdef"); + @endcode +*/ +net_nfc_error_e net_nfc_sign_ndef_message(ndef_message_h msg, char *cert_file, char *password); + +/** + This function does verify signature of records + record MUST be continuous. + + @param[in] begin_record the handle of beginning record that will be verified + @param[in] sign_record the handle of signature record + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + net_nfc_error_e error = NET_NFC_OK; + ndef_message_h msg = NULL; + ndef_record_h begin_record = NULL; + ndef_record_h sign_record = NULL; + + // import NDEF message including the signature record. + // ... + + net_nfc_get_record_by_index(msg, 0, &begin_record); + net_nfc_get_record_by_index(msg, 2, &sign_record); + + error = net_nfc_verify_signature_records(begin_record, sign_record); + + return (error == NET_NFC_OK); + @endcode +*/ +net_nfc_error_e net_nfc_verify_signature_records(ndef_record_h begin_record, ndef_record_h sign_record); + +/** + This function does verify signature in NDEF message + If message has 2 or more signature record, it should do verify every signatures and return result. + (Despite of failing only one signature record, this function will return error.) + + @param[in] msg NDEF message that will be verified. + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + net_nfc_error_e error = NET_NFC_OK; + ndef_message_h msg = NULL; + + // import NDEF message including the signature record. + // ... + + error = net_nfc_verify_signature_ndef_message(msg); + + return (error == NET_NFC_OK); + @endcode +*/ +net_nfc_error_e net_nfc_verify_signature_ndef_message(ndef_message_h msg); + +#ifdef __cplusplus +} +#endif + + +#endif //__NET_NFC_SIGN_RECORD_H__ diff --git a/src/clientlib/include/net_nfc_tag_mifare.h b/src/clientlib/include/net_nfc_tag_mifare.h new file mode 100755 index 0000000..6bca641 --- /dev/null +++ b/src/clientlib/include/net_nfc_tag_mifare.h @@ -0,0 +1,423 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ diff --git a/src/clientlib/include/net_nfc_target_info.h b/src/clientlib/include/net_nfc_target_info.h new file mode 100755 index 0000000..914a040 --- /dev/null +++ b/src/clientlib/include/net_nfc_target_info.h @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NET_NFC_TARGET_INFO_H__ +#define __NET_NFC_TARGET_INFO_H__ + +#include "net_nfc_typedef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + +@addtogroup NET_NFC_MANAGER_INFO +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + + These APIs help to get information 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 target 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) illegal 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 target 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) illegal 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) illegal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_get_tag_ndef_support(net_nfc_target_info_h target_info, bool *is_support); + +/** + Get current ndef tag state + + \par Sync (or) Async: Sync + This is a Synchronous API + + @param[in] target_info target info handler + @param[out] state ndef tag state + + @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_get_tag_ndef_state(net_nfc_target_info_h target_info, net_nfc_ndef_card_state_e *state); + +/** + The max size getter from target 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) illegal 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) illegal 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) illegal 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); + +/** + Get ndef message of current tag + + @remark This data can be expired because it is snapshot when tag was attached. If you want to get updated data, call @net_nfc_client_ndef_read function. + @remark @msg must be release by caller with @net_nfc_free_ndef_message + + \par Sync (or) Async: Sync + This is a Synchronous API + + @param[in] target_info target info handler + @param[out] msg ndef message + + @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_get_tag_ndef_message(net_nfc_target_info_h target_info, ndef_message_h *msg); + +/** + 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__ diff --git a/src/clientlib/net_nfc_client.c b/src/clientlib/net_nfc_client.c new file mode 100755 index 0000000..9bed54c --- /dev/null +++ b/src/clientlib/net_nfc_client.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "net_nfc_typedef.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" +#include "net_nfc_client_hce.h" + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +void __attribute__ ((constructor)) lib_init() +{ + g_type_init(); +} + +void __attribute__ ((destructor)) lib_fini() +{ +} + +GVariant *net_nfc_client_gdbus_get_privilege() +{ + return net_nfc_util_gdbus_buffer_to_variant(NULL, 0); +} + +void net_nfc_client_gdbus_init(void) +{ +#if 0 /* change gdbus init time */ + 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; + if (net_nfc_client_hce_init() != NET_NFC_OK) + return; +#endif +} + +void net_nfc_client_gdbus_deinit(void) +{ + net_nfc_client_hce_deinit(); + 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(); +} diff --git a/src/clientlib/net_nfc_client_context.c b/src/clientlib/net_nfc_client_context.c new file mode 100755 index 0000000..f151390 --- /dev/null +++ b/src/clientlib/net_nfc_client_context.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; +} diff --git a/src/clientlib/net_nfc_client_data.c b/src/clientlib/net_nfc_client_data.c new file mode 100755 index 0000000..0e97fd4 --- /dev/null +++ b/src/clientlib/net_nfc_client_data.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_data.h" +#include "net_nfc_typedef_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, size_t length) +{ + data_s *tmp_data = NULL; + + if (data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *data = NULL; + + tmp_data = net_nfc_util_create_data(length); + if (tmp_data == NULL) + return NET_NFC_ALLOC_FAIL; + + if (length > 0 && 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, size_t *length) +{ + data_s *tmp_data = (data_s *)data; + + if (bytes == NULL || length == NULL) + return NET_NFC_NULL_PARAMETER; + + *bytes = NULL; + *length = 0; + + if (data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *bytes = tmp_data->buffer; + *length = tmp_data->length; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_data(data_h data, + const uint8_t *bytes, size_t length) +{ + data_s *tmp_data = (data_s *)data; + + if (data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (tmp_data->buffer == bytes && tmp_data->length == length) + { + return NET_NFC_OK; + } + + net_nfc_util_clear_data(tmp_data); + + if (length > 0) + { + net_nfc_util_init_data(tmp_data, length); + + if (bytes != NULL) + { + memcpy(tmp_data->buffer, bytes, length); + } + } + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API size_t net_nfc_get_data_length(const data_h data) +{ + data_s *tmp_data = (data_s *)data; + + if (data == NULL) + { + return 0; + } + + return tmp_data->length; +} + +NET_NFC_EXPORT_API uint8_t *net_nfc_get_data_buffer(const data_h data) +{ + data_s *tmp_data = (data_s *)data; + + if (data == NULL) + { + return NULL; + } + + return tmp_data->buffer; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_data(data_h data) +{ + data_s *tmp_data = (data_s *)data; + + if (data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (tmp_data->buffer != NULL) + { + _net_nfc_util_free_mem(tmp_data->buffer); + } + _net_nfc_util_free_mem(tmp_data); + + return NET_NFC_OK; +} diff --git a/src/clientlib/net_nfc_client_dispatcher.c b/src/clientlib/net_nfc_client_dispatcher.c deleted file mode 100755 index ce2f9b0..0000000 --- a/src/clientlib/net_nfc_client_dispatcher.c +++ /dev/null @@ -1,1225 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#ifdef USE_ECORE_MAIN_LOOP -#include "Ecore.h" -#endif - -#include "net_nfc_typedef_private.h" -#include "net_nfc_typedef.h" -#include "net_nfc_data.h" -#include "net_nfc_exchanger_private.h" -#include "net_nfc_tag.h" -#include "net_nfc_debug_private.h" -#include "net_nfc_util_defines.h" -#include "net_nfc_util_private.h" -#include "net_nfc_util_ndef_message.h" -#include "net_nfc_client_dispatcher_private.h" -#include "net_nfc_client_nfc_private.h" - - -extern unsigned int socket_handle; - -net_nfc_llcp_internal_socket_s *_find_internal_socket_info(net_nfc_llcp_socket_t socket); -net_nfc_llcp_internal_socket_s *_find_internal_socket_info_by_oal_socket(net_nfc_llcp_socket_t socket); -void _append_internal_socket(net_nfc_llcp_internal_socket_s *data); -void _remove_internal_socket(net_nfc_llcp_internal_socket_s *data); -void _net_nfc_llcp_close_all_socket(); -void _net_nfc_set_llcp_remote_configure(net_nfc_llcp_config_info_s *remote_data); - -typedef struct _client_dispatcher_param_t -{ - net_nfc_response_cb client_cb; - net_nfc_response_msg_t *msg; -} client_dispatcher_param_t; - -/* static function */ - -static net_nfc_error_e net_nfc_get_tag_info_list(data_s *values, int number_of_keys, net_nfc_tag_info_s **list); -static bool net_nfc_client_dispatch_response(client_dispatcher_param_t *param); - -///////////////////// - -void _net_nfc_set_llcp_current_target_id(net_nfc_target_handle_s *handle); - -#ifdef SAVE_TARGET_INFO_IN_CC -static void __net_nfc_clear_tag_info_cache (client_context_t *context) -{ - if (context->target_info != NULL) - { - net_nfc_target_info_s *info = context->target_info; - net_nfc_tag_info_s *list = info->tag_info_list; - - if (list != NULL) - { - - int i = 0; - net_nfc_tag_info_s *temp = list; - - while (i < info->number_of_keys) - { - if (list->key != NULL) - free(list->key); - - if (list->value != NULL) - net_nfc_free_data(list->value); - - list++; - i++; - } - - /* destroy list */ - free(temp); - } - - if (info->keylist != NULL) - { - _net_nfc_util_free_mem(info->keylist); - } - - _net_nfc_util_free_mem(context->target_info); - context->target_info = NULL; - } -} -#endif - -#ifdef USE_GLIB_MAIN_LOOP -void net_nfc_client_call_dispatcher_in_g_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t *msg) -{ - client_dispatcher_param_t *param = NULL; - - DEBUG_CLIENT_MSG("put message to g main loop"); - - _net_nfc_util_alloc_mem(param, sizeof(client_dispatcher_param_t)); - if (param != NULL) - { - param->client_cb = client_cb; - param->msg = msg; - - if (g_idle_add_full(G_PRIORITY_HIGH_IDLE, (GSourceFunc)net_nfc_client_dispatch_response, param, NULL)) - { - g_main_context_wakeup(g_main_context_default()); - } - } -} -#elif USE_ECORE_MAIN_LOOP -void net_nfc_client_call_dispatcher_in_ecore_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t *msg) -{ - client_dispatcher_param_t *param = NULL; - - DEBUG_CLIENT_MSG("put message to ecore main loop"); - - _net_nfc_util_alloc_mem(param, sizeof(client_dispatcher_param_t)); - if (param != NULL) - { - param->client_cb = client_cb; - param->msg = msg; - - if (ecore_idler_add((Ecore_Task_Cb)net_nfc_client_dispatch_response, param) != NULL) - { - g_main_context_wakeup(g_main_context_default()); - } - } -} -#else -void net_nfc_client_call_dispatcher_in_current_context(net_nfc_response_cb client_cb, net_nfc_response_msg_t *msg) -{ - client_dispatcher_param_t *param = NULL; - - DEBUG_CLIENT_MSG("invoke callback in current thread"); - - _net_nfc_util_alloc_mem(param, sizeof(client_dispatcher_param_t)); - if (param != NULL) - { - param->client_cb = client_cb; - param->msg = msg; - - net_nfc_client_dispatch_response(param); - } -} -#endif - -static bool net_nfc_client_dispatch_response(client_dispatcher_param_t *param) -{ - if (param == NULL) - return false; - - net_nfc_response_cb client_cb = param->client_cb; - net_nfc_response_msg_t *msg = param->msg; - - _net_nfc_util_free_mem(param); - - DEBUG_CLIENT_MSG("we have got message from nfc-daemon type = [%d]", msg->response_type); - - client_context_t *client_context = net_nfc_get_client_context(); - - switch (msg->response_type) - { - case NET_NFC_MESSAGE_GET_SE : - { - if (client_cb != NULL) - { - client_cb(msg->response_type, ((net_nfc_response_get_se_t *)msg->detail_message)->result, &(((net_nfc_response_get_se_t *)msg->detail_message)->se_type), client_context->register_user_param, ((net_nfc_response_get_se_t *)msg->detail_message)->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_SET_SE : - { - if (client_cb != NULL) - { - client_cb(msg->response_type, ((net_nfc_response_set_se_t *)msg->detail_message)->result, &(((net_nfc_response_get_se_t *)msg->detail_message)->se_type), client_context->register_user_param, ((net_nfc_response_set_se_t *)msg->detail_message)->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_SE_TYPE_CHANGED : - { - if (client_cb != NULL) - { - client_cb(msg->response_type, NET_NFC_OK, NULL, NULL, NULL); - } - } - break; - - case NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED : - { - if (client_cb != NULL) - { - client_cb(msg->response_type, NET_NFC_OK, NULL, NULL, NULL); - } - } - break; - - case NET_NFC_MESSAGE_OPEN_INTERNAL_SE : - { - DEBUG_CLIENT_MSG("handle = [0x%p]", ((net_nfc_response_open_internal_se_t *)(msg->detail_message))->handle); - - if (client_cb != NULL) - { - client_cb(msg->response_type, ((net_nfc_response_open_internal_se_t *)(msg->detail_message))->result, (void *)((net_nfc_response_open_internal_se_t *)(msg->detail_message))->handle, client_context->register_user_param, ((net_nfc_response_open_internal_se_t *)(msg->detail_message))->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE : - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_close_internal_se_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_close_internal_se_t *)msg->detail_message)->trans_param); - } - break; - - case NET_NFC_MESSAGE_SEND_APDU_SE : - { - data_s *apdu = &(((net_nfc_response_send_apdu_t *)msg->detail_message)->data); - - if (apdu->length > 0) - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, apdu, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param); - } - else - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_GET_ATR_SE : - { - data_s *atr = &(((net_nfc_response_get_atr_t *)msg->detail_message)->data); - - if (atr->length > 0) - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_get_atr_t *)msg->detail_message)->result, atr, client_context->register_user_param, (void *)((net_nfc_response_get_atr_t *)(msg->detail_message))->user_param); - } - else - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_get_atr_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_atr_t *)(msg->detail_message))->user_param); - } - } - break; - - case NET_NFC_MESSAGE_NOTIFY : - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_notify_t *)msg->detail_message)->result, NULL, client_context->register_user_param, NULL); - } - break; - - case NET_NFC_MESSAGE_TRANSCEIVE : - { - data_s *data = &(((net_nfc_response_transceive_t *)msg->detail_message)->data); - - if (data->length > 0) - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_transceive_t *)msg->detail_message)->result, (void *)data, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param); - } - else - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_transceive_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF : - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_make_read_only_ndef_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_make_read_only_ndef_t *)(msg->detail_message))->trans_param); - } - break; - - case NET_NFC_MESSAGE_IS_TAG_CONNECTED : - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_is_tag_connected_t *)msg->detail_message)->result, (void *)&(((net_nfc_response_is_tag_connected_t *)msg->detail_message)->devType), client_context->register_user_param, ((net_nfc_response_is_tag_connected_t *)(msg->detail_message))->trans_param); - } - break; - - case NET_NFC_MESSAGE_READ_NDEF : - { - data_s *data = &(((net_nfc_response_read_ndef_t *)msg->detail_message)->data); - ndef_message_s *ndef = NULL; - - if (net_nfc_util_create_ndef_message(&ndef) != NET_NFC_OK) - { - DEBUG_ERR_MSG("memory alloc fail.."); - break; - } - - if (data->length > 0 && net_nfc_util_convert_rawdata_to_ndef_message(data, ndef) == NET_NFC_OK) - { - if(client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_read_ndef_t *)msg->detail_message)->result, ndef, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param); - } - else - { - if(client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_read_ndef_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param); - } - net_nfc_util_free_ndef_message(ndef); - } - break; - - case NET_NFC_GET_SERVER_STATE : - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state); - } - break; - - case NET_NFC_MESSAGE_SIM_TEST : - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state); - } - break; - - case NET_NFC_MESSAGE_PRBS_TEST : - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state); - } - break; - - case NET_NFC_MESSAGE_SET_EEDATA : - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state); - } - break; - - case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION : - { - data_s *version = &(((net_nfc_response_firmware_version_t *)msg->detail_message)->data); - - if (version->length > 0) - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, version, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param); - } - else - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_WRITE_NDEF : - { - if (client_cb != NULL) - client_cb(msg->response_type, ((net_nfc_response_write_ndef_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param); - } - break; - - case NET_NFC_MESSAGE_TAG_DISCOVERED : - { - net_nfc_response_tag_discovered_t *detected = (net_nfc_response_tag_discovered_t *)msg->detail_message; - - if (net_nfc_util_check_tag_filter(detected->devType) == false) - { - DEBUG_CLIENT_MSG("The detected target is filtered out"); - } - -#ifdef SAVE_TARGET_INFO_IN_CC - __net_nfc_clear_tag_info_cache(client_context); - - net_nfc_tag_info_s *list = NULL; - net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list); - - net_nfc_target_info_s *info = NULL; - _net_nfc_util_alloc_mem(info, sizeof(net_nfc_target_info_s)); - if (info == NULL) - { - DEBUG_CLIENT_MSG("mem alloc is failed"); - _net_nfc_util_free_mem(list); - break; - } - - info->ndefCardState = detected->ndefCardState; - info->actualDataSize = detected->actualDataSize; - info->maxDataSize = detected->maxDataSize; - info->devType = detected->devType; - info->handle = detected->handle; - info->is_ndef_supported = detected->is_ndef_supported; - info->number_of_keys = detected->number_of_keys; - info->tag_info_list = list; - info->raw_data = detected->raw_data; - - client_context->target_info = info; - - if (client_cb != NULL) - client_cb(msg->response_type, NET_NFC_OK, info, client_context->register_user_param, NULL); -#else - net_nfc_tag_info_s *list = NULL; - net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list); - - net_nfc_target_info_s info; - memset(&info, 0x00, sizeof(net_nfc_target_info_s)); - - info.ndefCardState = detected->ndefCardState; - info.actualDataSize = detected->actualDataSize; - info.maxDataSize = detected->maxDataSize; - info.devType = detected->devType; - info.handle = detected->handle; - info.is_ndef_supported = detected->is_ndef_supported; - info.number_of_keys = detected->number_of_keys; - info.tag_info_list = list; - info.raw_data = detected.raw_data; - - if (client_cb != NULL) - client_cb(msg->response_type, NET_NFC_OK, &info, client_context->register_user_param, NULL); - - net_nfc_util_release_tag_info(&info); -#endif - } - break; - - case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO : - { - net_nfc_response_get_current_tag_info_t *detected = (net_nfc_response_get_current_tag_info_t *)msg->detail_message; - - if (detected->result != NET_NFC_NOT_CONNECTED) - { - if (net_nfc_util_check_tag_filter(detected->devType) == false) - { - DEBUG_CLIENT_MSG("The detected target is filtered out"); - } - -#ifdef SAVE_TARGET_INFO_IN_CC - __net_nfc_clear_tag_info_cache(client_context); - - net_nfc_tag_info_s *list = NULL; - net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list); - - net_nfc_target_info_s *info = NULL; - _net_nfc_util_alloc_mem(info, sizeof(net_nfc_target_info_s)); - if (info == NULL) - { - DEBUG_CLIENT_MSG("mem alloc is failed"); - _net_nfc_util_free_mem(list); - break; - } - - info->ndefCardState = detected->ndefCardState; - info->actualDataSize = detected->actualDataSize; - info->maxDataSize = detected->maxDataSize; - info->devType = detected->devType; - info->handle = detected->handle; - info->is_ndef_supported = detected->is_ndef_supported; - info->number_of_keys = detected->number_of_keys; - info->tag_info_list = list; - info->raw_data = detected->raw_data; - - client_context->target_info = info; - - if (client_cb != NULL) - client_cb(msg->response_type, NET_NFC_OK, info, client_context->register_user_param, detected->trans_param); -#else - net_nfc_tag_info_s *list = NULL; - net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list); - - net_nfc_target_info_s info; - memset(&info, 0x00, sizeof(net_nfc_target_info_s)); - - info.ndefCardState = detected->ndefCardState; - info.actualDataSize = detected->actualDataSize; - info.maxDataSize = detected->maxDataSize; - info.devType = detected->devType; - info.handle = detected->handle; - info.is_ndef_supported = detected->is_ndef_supported; - info.number_of_keys = detected->number_of_keys; - info.tag_info_list = list; - info.raw_data = detected.raw_data; - - if (client_cb != NULL) - client_cb(msg->response_type, NET_NFC_OK, &info, client_context->register_user_param, detected->trans_param); - - net_nfc_util_release_tag_info(&info); -#endif - } - else - { - if (client_cb != NULL) - client_cb(msg->response_type, detected->result, NULL, client_context->register_user_param, detected->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE : - { - net_nfc_response_get_current_target_handle_t *detected = (net_nfc_response_get_current_target_handle_t *)msg->detail_message; - - if (detected->result == NET_NFC_OK) - { - if (client_cb != NULL) - client_cb(msg->response_type, detected->result, (void *)detected->handle, client_context->register_user_param, detected->trans_param); - } - else - { - if (client_cb != NULL) - client_cb(msg->response_type, detected->result, NULL, client_context->register_user_param, detected->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_TAG_DETACHED : - { - net_nfc_response_target_detached_t *detached = (net_nfc_response_target_detached_t *)msg->detail_message; - - if (net_nfc_util_check_tag_filter(detached->devType) == false) - { - DEBUG_CLIENT_MSG("The detected target is filtered out"); - } - - if (client_cb != NULL) - client_cb(msg->response_type, NET_NFC_OK, (net_nfc_target_handle_h)detached->handle, client_context->register_user_param, NULL); - -#ifdef SAVE_TARGET_INFO_IN_CC - __net_nfc_clear_tag_info_cache(client_context); -#endif - } - break; - - case NET_NFC_MESSAGE_FORMAT_NDEF : - { - net_nfc_response_format_ndef_t *detail_msg = (net_nfc_response_format_ndef_t *)msg->detail_message; - - if (client_cb != NULL) - client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, detail_msg->trans_param); - } - break; - - case NET_NFC_MESSAGE_SE_START_TRANSACTION : - case NET_NFC_MESSAGE_SE_END_TRANSACTION : - case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION : - case NET_NFC_MESSAGE_SE_CONNECTIVITY : - case NET_NFC_MESSAGE_SE_FIELD_ON : - case NET_NFC_MESSAGE_SE_FIELD_OFF : - { - net_nfc_response_se_event_t *se_event = (net_nfc_response_se_event_t *)msg->detail_message; - net_nfc_se_event_info_s info = { { 0, }, }; - - info.aid = se_event->aid; - info.param = se_event->param; - info.se_type = se_event->se_type; - info.fg_dispatch = se_event->fg_dispatch; - info.focus_app_pid = se_event->focus_app_pid; - - if (client_cb != NULL) - client_cb(msg->response_type, NET_NFC_OK, (void *)&info, client_context->register_user_param, NULL); - } - break; - - case NET_NFC_MESSAGE_LLCP_LISTEN : - { - net_nfc_response_listen_socket_t *detail_msg = (net_nfc_response_listen_socket_t *)msg->detail_message; - net_nfc_llcp_internal_socket_s *psocket_info = NULL; - - psocket_info = _find_internal_socket_info(detail_msg->client_socket); - if (psocket_info == NULL) - { - DEBUG_ERR_MSG("Wrong client socket is returned from server.."); - break; - } - psocket_info->oal_socket = detail_msg->oal_socket; - DEBUG_CLIENT_MSG ("oal socket %d", detail_msg->oal_socket); - if (psocket_info->cb != NULL) - { - psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_CONNECT : - { - net_nfc_response_connect_socket_t *detail_msg = (net_nfc_response_connect_socket_t *)msg->detail_message; - net_nfc_llcp_internal_socket_s *psocket_info = NULL; - - psocket_info = _find_internal_socket_info(detail_msg->client_socket); - if (psocket_info == NULL) - { - DEBUG_ERR_MSG("Wrong client socket is returned from server.."); - break; - } - psocket_info->oal_socket = detail_msg->oal_socket; - if (psocket_info->cb != NULL) - { - psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_CONNECT_SAP : - { - net_nfc_response_connect_sap_socket_t *detail_msg = (net_nfc_response_connect_sap_socket_t *)msg->detail_message; - net_nfc_llcp_internal_socket_s *psocket_info = NULL; - - psocket_info = _find_internal_socket_info(detail_msg->client_socket); - if (psocket_info == NULL) - { - DEBUG_ERR_MSG("Wrong client socket is returned from server.."); - break; - } - psocket_info->oal_socket = detail_msg->oal_socket; - if (psocket_info->cb != NULL) - { - psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_SEND : - { - net_nfc_response_send_socket_t *detail_msg = (net_nfc_response_send_socket_t *)msg->detail_message; - net_nfc_llcp_internal_socket_s *psocket_info = NULL; - - psocket_info = _find_internal_socket_info(detail_msg->client_socket); - if (psocket_info == NULL) - { - DEBUG_ERR_MSG("Wrong client socket is returned from server.."); - break; - } - if (psocket_info->cb != NULL) - { - psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_RECEIVE : - { - net_nfc_response_receive_socket_t *detail_msg = (net_nfc_response_receive_socket_t *)msg->detail_message; - - if (client_cb != NULL) - client_cb(msg->response_type, detail_msg->result, &(detail_msg->data), client_context->register_user_param, NULL); - } - break; - - case NET_NFC_MESSAGE_P2P_RECEIVE : - { - net_nfc_response_p2p_receive_t *detail_msg = (net_nfc_response_p2p_receive_t *)msg->detail_message; - - if (client_cb != NULL) - client_cb(msg->response_type, detail_msg->result, &(detail_msg->data), client_context->register_user_param, NULL); - } - break; - - case NET_NFC_MESSAGE_P2P_SEND : - { - net_nfc_response_p2p_send_t *detail_msg = (net_nfc_response_p2p_send_t *)msg->detail_message; - - if (client_cb != NULL) - client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, NULL); - } - break; - - case NET_NFC_MESSAGE_LLCP_DISCONNECT : - { - net_nfc_response_disconnect_socket_t *detail_msg = (net_nfc_response_disconnect_socket_t *)msg->detail_message; - net_nfc_llcp_internal_socket_s *psocket_info = NULL; - - psocket_info = _find_internal_socket_info(detail_msg->client_socket); - if (psocket_info == NULL) - { - DEBUG_ERR_MSG("Wrong client socket is returned from server.."); - break; - } - if (psocket_info->cb != NULL) - { - psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_CONFIG : - { - net_nfc_response_config_llcp_t *detail_msg = (net_nfc_response_config_llcp_t *)msg->detail_message; - - if (client_cb != NULL) - client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, NULL); - } - break; - - case NET_NFC_MESSAGE_LLCP_ERROR : - { - net_nfc_response_llcp_socket_error_t *detail_msg = (net_nfc_response_llcp_socket_error_t *)msg->detail_message; - net_nfc_llcp_internal_socket_s *psocket_info = NULL; - - psocket_info = _find_internal_socket_info(detail_msg->client_socket); - if (psocket_info == NULL) - { - DEBUG_ERR_MSG("Wrong client socket is returned from server.."); - break; - } - if (psocket_info->cb != NULL) - { - psocket_info->cb(msg->response_type, detail_msg->error, NULL, psocket_info->register_param, NULL); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_ACCEPTED : - { - net_nfc_response_incomming_llcp_t *detail_msg = (net_nfc_response_incomming_llcp_t *)msg->detail_message; - net_nfc_llcp_internal_socket_s *psocket_info = NULL; - psocket_info = _find_internal_socket_info_by_oal_socket(detail_msg->oal_socket); - if (psocket_info == NULL) - { - DEBUG_ERR_MSG("Wrong client socket is returned from server.."); - break; - } - if (psocket_info->cb != NULL) - { - net_nfc_llcp_internal_socket_s *socket_data = NULL; - _net_nfc_util_alloc_mem(socket_data, sizeof(net_nfc_llcp_internal_socket_s)); - socket_data->client_socket = socket_handle++; - socket_data->miu = detail_msg->option.miu; - socket_data->rw = detail_msg->option.rw; - socket_data->type = detail_msg->option.type; - socket_data->device_id = detail_msg->handle; - socket_data->close_requested = false; - socket_data->oal_socket = detail_msg->incomming_socket; - _append_internal_socket(socket_data); - psocket_info->cb(msg->response_type, detail_msg->result, (void *)&(socket_data->client_socket), psocket_info->register_param, NULL); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_DISCOVERED : - { - net_nfc_response_llcp_discovered_t *detail_msg = (net_nfc_response_llcp_discovered_t *)msg->detail_message; - - _net_nfc_set_llcp_current_target_id(detail_msg->handle); - _net_nfc_set_llcp_remote_configure(&(detail_msg->llcp_config_info)); - - __net_nfc_clear_tag_info_cache(client_context); - - net_nfc_tag_info_s *list = NULL; - net_nfc_get_tag_info_list(&(detail_msg->target_info_values), detail_msg->number_of_keys, &list); - - net_nfc_target_info_s *info = NULL; - if ((info = calloc(1, sizeof(net_nfc_target_info_s))) == NULL) - { - DEBUG_CLIENT_MSG("mem alloc is failed"); - _net_nfc_util_free_mem(list); - break; - } - - info->actualDataSize = 0; - info->maxDataSize = 0; - info->devType = detail_msg->devType; - info->handle = detail_msg->handle; - info->is_ndef_supported = false; - info->number_of_keys = detail_msg->number_of_keys; - info->tag_info_list = list; - - client_context->target_info = info; - - if (client_cb != NULL) - { - client_cb(msg->response_type, NET_NFC_OK, (void *)info, client_context->register_user_param, NULL); - } - } - break; - - case NET_NFC_MESSAGE_P2P_DETACHED : - { - net_nfc_response_llcp_detached_t *detail_msg = (net_nfc_response_llcp_detached_t *)msg->detail_message; - - _net_nfc_set_llcp_current_target_id(NULL); - - if (client_cb != NULL) - { - client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, NULL); - } - _net_nfc_llcp_close_all_socket(); - - } - break; - - case NET_NFC_MESSAGE_P2P_DISCOVERED : - { - net_nfc_response_p2p_discovered_t *detail_msg = (net_nfc_response_p2p_discovered_t *)msg->detail_message; - - if (client_cb != NULL) - { - client_cb(msg->response_type, detail_msg->result, (void *)detail_msg->handle, client_context->register_user_param, NULL); - } - } - break; - - case NET_NFC_MESSAGE_CONNECTION_HANDOVER : - { - net_nfc_response_connection_handover_t *detail_msg = (net_nfc_response_connection_handover_t *)msg->detail_message; - - if (detail_msg == NULL) - { - DEBUG_ERR_MSG("NET_NFC_MESSAGE_CONNECTION_HANDOVER detail_msg == NULL"); - break; - } - - if (client_cb != NULL) - { - net_nfc_connection_handover_info_s info = { 0, }; - - info.type = detail_msg->type; - info.data.length = detail_msg->data.length; - if (info.data.length > 0) - { - _net_nfc_util_alloc_mem(info.data.buffer, info.data.length); - if (info.data.buffer == NULL) - { - DEBUG_ERR_MSG("mem alloc is failed"); - break; - } - memcpy(info.data.buffer, detail_msg->data.buffer, info.data.length); - } - - client_cb(msg->response_type, detail_msg->event, (void *)&info, client_context->register_user_param, NULL); - - if (info.data.length > 0) - { - _net_nfc_util_free_mem(info.data.buffer); - } - } - } - break; - - case NET_NFC_MESSAGE_SERVICE_INIT : - { - net_nfc_response_test_t *detail_msg = (net_nfc_response_test_t *)msg->detail_message; - - DEBUG_CLIENT_MSG("NET_NFC_MESSAGE_SERVICE_INIT [%p]", detail_msg->trans_param); - - if (client_cb != NULL) - { - client_cb(NET_NFC_MESSAGE_INIT, detail_msg->result, NULL, client_context->register_user_param, NULL); - } - } - break; - - case NET_NFC_MESSAGE_SERVICE_DEINIT : - { - net_nfc_response_test_t *detail_msg = (net_nfc_response_test_t *)msg->detail_message; - - DEBUG_CLIENT_MSG("NET_NFC_MESSAGE_SERVICE_DEINIT [%p]", detail_msg->trans_param); - - if (client_cb != NULL) - { - client_cb(NET_NFC_MESSAGE_DEINIT, detail_msg->result, NULL, client_context->register_user_param, NULL); - } - } - break; - - default : - break; - } - - /* client callback must copy data to client area */ - net_nfc_util_mem_free_detail_msg(NET_NFC_UTIL_MSG_TYPE_RESPONSE, msg->response_type, msg->detail_message); - _net_nfc_util_free_mem(msg); - - return false; -} - -net_nfc_error_e net_nfc_client_dispatch_sync_response(net_nfc_response_msg_t *msg) -{ - net_nfc_error_e result = NET_NFC_OK; - client_context_t *client_context = NULL; - - DEBUG_CLIENT_MSG("synchronous callback, message = [%d]", msg->response_type); - - client_context = net_nfc_get_client_context(); - - switch (msg->response_type) - { - case NET_NFC_MESSAGE_GET_SE : - break; - - case NET_NFC_MESSAGE_SET_SE : - break; - - case NET_NFC_MESSAGE_SE_TYPE_CHANGED : - break; - - case NET_NFC_MESSAGE_CARD_EMULATION_CHANGE_SE : - { - net_nfc_response_se_change_card_emulation_t *response - = (net_nfc_response_se_change_card_emulation_t *)msg->detail_message; - - /* return */ - result = response->result; - } - break; - - case NET_NFC_MESSAGE_OPEN_INTERNAL_SE : - { - net_nfc_response_open_internal_se_t *response = (net_nfc_response_open_internal_se_t *)msg->detail_message; - net_nfc_target_handle_h *handle = (net_nfc_target_handle_h *)response->user_param; - - /* return */ - result = response->result; - - if (handle != NULL) { - *handle = (net_nfc_target_handle_h)response->handle; - } - } - break; - - case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE : - { - net_nfc_response_close_internal_se_t *response = (net_nfc_response_close_internal_se_t *)msg->detail_message; - - /* return */ - result = response->result; - } - break; - - case NET_NFC_MESSAGE_SEND_APDU_SE : - { - net_nfc_response_send_apdu_t *response = (net_nfc_response_send_apdu_t *)msg->detail_message; - data_h *data = (data_h *)response->user_param; - - /* return */ - result = response->result; - - if (data != NULL && response->data.buffer != NULL && - response->data.length > 0) { - net_nfc_create_data(data, response->data.buffer, - response->data.length); - } - } - break; - - case NET_NFC_MESSAGE_GET_ATR_SE : - { - net_nfc_response_get_atr_t *response = (net_nfc_response_get_atr_t *)msg->detail_message; - data_h *data = (data_h *)response->user_param; - - /* return */ - result = response->result; - - if (data != NULL && response->data.buffer != NULL && - response->data.length > 0) { - net_nfc_create_data(data, response->data.buffer, - response->data.length); - } - } - break; - - case NET_NFC_MESSAGE_NOTIFY : - break; - - case NET_NFC_MESSAGE_TRANSCEIVE : - break; - - case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF : - break; - - case NET_NFC_MESSAGE_IS_TAG_CONNECTED : - { - net_nfc_response_is_tag_connected_t *response = (net_nfc_response_is_tag_connected_t *)msg->detail_message; - net_nfc_response_is_tag_connected_t *context = (net_nfc_response_is_tag_connected_t *)response->trans_param; - - /* return */ - result = response->result; - - if (context != NULL) - { - context->result = response->result; - context->devType = response->devType; - } - } - break; - - case NET_NFC_MESSAGE_READ_NDEF : - break; - - case NET_NFC_GET_SERVER_STATE : - break; - - case NET_NFC_MESSAGE_SIM_TEST : - break; - - case NET_NFC_MESSAGE_PRBS_TEST : - break; - - case NET_NFC_MESSAGE_SET_EEDATA : - break; - - case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION : - break; - - case NET_NFC_MESSAGE_WRITE_NDEF : - break; - - case NET_NFC_MESSAGE_TAG_DISCOVERED : - break; - - case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO : - { - net_nfc_response_get_current_tag_info_t *response = (net_nfc_response_get_current_tag_info_t *)msg->detail_message; - net_nfc_response_get_current_tag_info_t *context = (net_nfc_response_get_current_tag_info_t *)response->trans_param; - - /* return */ - result = response->result; - - if (context != NULL) - { - context->result = response->result; - - if (response->result != NET_NFC_NOT_CONNECTED) - { - if (net_nfc_util_check_tag_filter(response->devType) == true) - { - net_nfc_target_info_s *info = NULL; - - _net_nfc_util_alloc_mem(info, sizeof(net_nfc_target_info_s)); - - info->ndefCardState = response->ndefCardState; - info->actualDataSize = response->actualDataSize; - info->maxDataSize = response->maxDataSize; - info->devType = response->devType; - info->handle = response->handle; - info->is_ndef_supported = response->is_ndef_supported; - info->number_of_keys = response->number_of_keys; - net_nfc_get_tag_info_list(&(response->target_info_values), response->number_of_keys, &info->tag_info_list); - if (response->raw_data.length > 0) - { - net_nfc_util_alloc_data(&info->raw_data, response->raw_data.length); - memcpy(info->raw_data.buffer, response->raw_data.buffer, info->raw_data.length); - } - - context->trans_param = info; - // TODO: check usage of trans_param - client_context->target_info = info; - } - else - { - /* filtered tag */ - } - } - } - } - break; - - case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE : - { - net_nfc_response_get_current_target_handle_t *response = (net_nfc_response_get_current_target_handle_t *)msg->detail_message; - net_nfc_response_get_current_target_handle_t *context = (net_nfc_response_get_current_target_handle_t *)response->trans_param; - - /* return */ - result = response->result; - - if (context != NULL) - { - context->handle = response->handle; - context->result = response->result; - } - } - break; - - case NET_NFC_MESSAGE_TAG_DETACHED : - break; - - case NET_NFC_MESSAGE_FORMAT_NDEF : - break; - - case NET_NFC_MESSAGE_SE_START_TRANSACTION : - case NET_NFC_MESSAGE_SE_END_TRANSACTION : - case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION : - case NET_NFC_MESSAGE_SE_CONNECTIVITY : - case NET_NFC_MESSAGE_SE_FIELD_ON : - case NET_NFC_MESSAGE_SE_FIELD_OFF : - break; - - case NET_NFC_MESSAGE_LLCP_LISTEN : - break; - - case NET_NFC_MESSAGE_LLCP_CONNECT : - break; - - case NET_NFC_MESSAGE_LLCP_CONNECT_SAP : - break; - - case NET_NFC_MESSAGE_LLCP_SEND : - break; - - case NET_NFC_MESSAGE_LLCP_RECEIVE : - break; - - case NET_NFC_MESSAGE_P2P_RECEIVE : - break; - - case NET_NFC_MESSAGE_P2P_SEND : - break; - - case NET_NFC_MESSAGE_LLCP_DISCONNECT : - break; - - case NET_NFC_MESSAGE_LLCP_CONFIG : - break; - - case NET_NFC_MESSAGE_LLCP_ERROR : - break; - - case NET_NFC_MESSAGE_LLCP_ACCEPTED : - break; - - case NET_NFC_MESSAGE_LLCP_DISCOVERED : - break; - - case NET_NFC_MESSAGE_P2P_DETACHED : - break; - - case NET_NFC_MESSAGE_P2P_DISCOVERED : - break; - - case NET_NFC_MESSAGE_CONNECTION_HANDOVER : - break; - - case NET_NFC_MESSAGE_SERVICE_INIT : - break; - - case NET_NFC_MESSAGE_SERVICE_DEINIT : - break; - - default : - break; - } - - /* client callback must copy data to client area */ - net_nfc_util_mem_free_detail_msg(NET_NFC_UTIL_MSG_TYPE_RESPONSE, msg->response_type, msg->detail_message); - _net_nfc_util_free_mem(msg); - - return result; -} - -static net_nfc_error_e net_nfc_get_tag_info_list(data_s *values, int number_of_keys, net_nfc_tag_info_s **list) -{ - net_nfc_tag_info_s *temp_list = NULL; - - if (list == NULL) - return NET_NFC_NULL_PARAMETER; - - /* TODO */ - _net_nfc_util_alloc_mem(temp_list, number_of_keys * sizeof(net_nfc_tag_info_s)); - if (temp_list == NULL) - { - return NET_NFC_ALLOC_FAIL; - } - - *list = temp_list; - - /* get 1 byte :: length - * get key name - * get 1 byte :: value length - * make data_h - */ - uint8_t *pBuffer = values->buffer; - - if (pBuffer == NULL) - return NET_NFC_NULL_PARAMETER; - - int index = 0; - - while (index < number_of_keys) - { - int key_length = *pBuffer; - char *key = NULL; - - _net_nfc_util_alloc_mem(key, key_length + 1); - if (key == NULL) - return NET_NFC_ALLOC_FAIL; - pBuffer = pBuffer + 1; - - /* copy key name */ - memcpy(key, pBuffer, key_length); - pBuffer = pBuffer + key_length; - - DEBUG_CLIENT_MSG("key = [%s]", key); - - /* get values length */ - uint32_t value_length = *pBuffer; - pBuffer = pBuffer + 1; - - data_h value = NULL; - - if (value_length > 0) - { - net_nfc_create_data(&value, pBuffer, value_length); - pBuffer = pBuffer + value_length; - } - - temp_list->key = key; - temp_list->value = value; - - temp_list++; - - index++; - } - return NET_NFC_OK; -} diff --git a/src/clientlib/net_nfc_client_handover.c b/src/clientlib/net_nfc_client_handover.c new file mode 100755 index 0000000..cffc0d1 --- /dev/null +++ b/src/clientlib/net_nfc_client_handover.c @@ -0,0 +1,370 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_util_internal.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 _handover_handler_t +{ + net_nfc_connection_handover_event_cb handover_event_cb; + gpointer handover_event_data; +} +handover_handler_t; + +static NetNfcGDbusHandover *handover_proxy = NULL; +static handover_handler_t handover_callbacks; + +static void p2p_connection_handover(GObject *source_object, + GAsyncResult *res, + gpointer user_data); + +static void __started(NetNfcGDbusHandover *object, + GVariant *arg_message) +{ + data_s message; + + INFO_MSG(">>> SIGNAL arrived"); + + net_nfc_util_gdbus_variant_to_data_s(arg_message, &message); + + if (handover_callbacks.handover_event_cb != NULL) { + handover_callbacks.handover_event_cb(NET_NFC_HANDOVER_START, + NET_NFC_OK, NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, + NULL, &message, + handover_callbacks.handover_event_data); + } + + net_nfc_util_clear_data(&message); +} + +static void __finished(NetNfcGDbusHandover *object, + gint arg_result, + gint arg_type, + GVariant *arg_address, + GVariant *arg_message) +{ + data_s address, message; + + INFO_MSG(">>> SIGNAL arrived"); + + net_nfc_util_gdbus_variant_to_data_s(arg_address, &address); + net_nfc_util_gdbus_variant_to_data_s(arg_message, &message); + + if (handover_callbacks.handover_event_cb != NULL) { + handover_callbacks.handover_event_cb(NET_NFC_HANDOVER_FINISH, + arg_result, arg_type, &address, &message, + handover_callbacks.handover_event_data); + } + + net_nfc_util_clear_data(&message); + net_nfc_util_clear_data(&address); +} + +static void p2p_connection_handover(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e result; + GVariant *data = NULL; + net_nfc_conn_handover_carrier_type_e type = + NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + GError *error = NULL; + data_s arg_data; + + g_assert(user_data != NULL); + + if (handover_proxy == NULL) + { + if (net_nfc_client_handover_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("handover_proxy fail"); + /* FIXME : return result of this error */ + return; + } + } + + if (net_nfc_gdbus_handover_call_request_finish(handover_proxy, + (gint *)&result, + (gint *)&type, + &data, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish" + " connection handover: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_p2p_connection_handover_completed_cb callback = + (net_nfc_p2p_connection_handover_completed_cb)func_data->callback; + + net_nfc_util_gdbus_variant_to_data_s(data, &arg_data); + + callback(result, + type, + &arg_data, + func_data->user_data); + + net_nfc_util_clear_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_connection_handover_info_s *info = + (net_nfc_connection_handover_info_s *)info_handle; + + if (info_handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (info->data.buffer != NULL) + { + _net_nfc_util_free_mem(info->data.buffer); + } + + _net_nfc_util_free_mem(info); + + return NET_NFC_OK; +} + + +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 = + (net_nfc_connection_handover_info_s *)info_handle; + + if (info_handle == NULL || type == NULL) + return NET_NFC_NULL_PARAMETER; + + *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_connection_handover_info_s *info = + (net_nfc_connection_handover_info_s *)info_handle; + + if (info_handle == NULL || data == NULL) + return NET_NFC_NULL_PARAMETER; + + return net_nfc_create_data(data, info->data.buffer, info->data.length); +} + + +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) +{ + + net_nfc_target_handle_s *tag_handle = (net_nfc_target_handle_s *)handle; + NetNfcCallback *funcdata; + + if (handover_proxy == NULL) + { + if(net_nfc_client_handover_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("handover_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + funcdata = g_try_new0(NetNfcCallback, 1); + if (funcdata == NULL) { + return NET_NFC_ALLOC_FAIL; + } + + funcdata->callback = (gpointer)callback; + funcdata->user_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; + GVariant *out_data = NULL; + net_nfc_error_e out_result = NET_NFC_OK; + net_nfc_conn_handover_carrier_type_e out_type = + NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + GError *error = NULL; + + if (handover_proxy == NULL) + { + if(net_nfc_client_handover_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("handover_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + 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_result, + (gint32 *)&out_type, + &out_data, + NULL, + &error) == TRUE) { + if (out_carrier) { + *out_carrier = out_type; + } + + if (out_ac_data) { + *out_ac_data = net_nfc_util_gdbus_variant_to_data(out_data); + } + } else { + DEBUG_ERR_MSG("handover (sync call) failed: %s",error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return out_result; +} + +NET_NFC_EXPORT_API +void net_nfc_client_handover_set_handover_event_cb( + net_nfc_connection_handover_event_cb callback, + void *user_data) +{ + if (callback == NULL) + return; + + if (handover_proxy == NULL) + { + if (net_nfc_client_handover_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("handover_proxy fail"); + return; + } + } + + handover_callbacks.handover_event_cb = callback; + handover_callbacks.handover_event_data = user_data; +} + + +NET_NFC_EXPORT_API +void net_nfc_client_handover_unset_handover_event_cb(void) +{ + handover_callbacks.handover_event_cb = NULL; + handover_callbacks.handover_event_data = NULL; +} + + +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_DO_NOT_AUTO_START, + "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; + } + + g_signal_connect(handover_proxy, "started", + G_CALLBACK(__started), NULL); + + g_signal_connect(handover_proxy, "finished", + G_CALLBACK(__finished), NULL); + + return NET_NFC_OK; +} + + +void net_nfc_client_handover_deinit(void) +{ + if (handover_proxy) + { + g_object_unref(handover_proxy); + handover_proxy = NULL; + } +} diff --git a/src/clientlib/net_nfc_client_hce.c b/src/clientlib/net_nfc_client_hce.c new file mode 100755 index 0000000..3a0b89d --- /dev/null +++ b/src/clientlib/net_nfc_client_hce.c @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_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_util_internal.h" +#include "net_nfc_client_manager.h" +#include "net_nfc_client_hce.h" + + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +typedef struct _HceHandler HceHandler; + +struct _HceHandler +{ + net_nfc_client_hce_event_cb hce_event_cb; + gpointer hce_data; +}; + +static NetNfcGDbusHce *hce_proxy = NULL; + +static HceHandler hce_handler; +static char package_name[1024]; + +static void __load_package_name() +{ + if (net_nfc_util_get_pkgid_by_pid(getpid(), + package_name, sizeof(package_name)) == false) { + DEBUG_ERR_MSG("failed to get package name, pid [%d]", getpid()); + } +} + +static void hce_event_received(GObject *source_object, guint arg_handle, + guint arg_event, GVariant *arg_apdu, gchar *arg_package) +{ + INFO_MSG(">>> SIGNAL arrived hce_apdu_receive"); + + if (hce_handler.hce_event_cb != NULL) { + + data_s apdu = { NULL, 0 }; + + net_nfc_util_gdbus_variant_to_data_s(arg_apdu, &apdu); + + hce_handler.hce_event_cb((net_nfc_target_handle_h)arg_handle, + (net_nfc_hce_event_t)arg_event, &apdu, + hce_handler.hce_data); + + net_nfc_util_clear_data(&apdu); + } +} + + + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_hce_set_event_received_cb( + net_nfc_client_hce_event_cb callback, void *user_data) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + DEBUG_CLIENT_MSG("net_nfc_client_hce_set_event_received_cb set"); + + if (hce_proxy == NULL) + { + result = net_nfc_client_hce_init(); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_client_hce_init failed, [%d]", result); + + return result; + } + } + + if (net_nfc_gdbus_hce_call_start_hce_handler_sync(hce_proxy, + net_nfc_client_gdbus_get_privilege(), &result, + NULL, &error) == true) { + hce_handler.hce_event_cb = callback; + hce_handler.hce_data = user_data; + } else { + DEBUG_ERR_MSG("net_nfc_gdbus_hce_call_start_hce_handler_sync 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_hce_unset_event_received_cb(void) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (hce_proxy == NULL) { + DEBUG_ERR_MSG("not initialized!!!"); + return NET_NFC_NOT_INITIALIZED; + } + + if (net_nfc_gdbus_hce_call_stop_hce_handler_sync(hce_proxy, + net_nfc_client_gdbus_get_privilege(), &result, + NULL, &error) == true) { + hce_handler.hce_event_cb = NULL; + hce_handler.hce_data = NULL; + } else { + DEBUG_ERR_MSG("net_nfc_gdbus_hce_call_stop_hce_handler_sync 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_hce_response_apdu_sync( + net_nfc_target_handle_h handle, + data_h resp_apdu_data) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + GVariant *arg_data = NULL; + + INFO_MSG(">>> net_nfc_client_hce_response_apdu_sync!!"); + + if (hce_proxy == NULL) + { + result = net_nfc_client_hce_init(); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_client_hce_init failed, [%d]", result); + + return result; + } + } + + arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)resp_apdu_data); + if (arg_data == NULL) + { + + INFO_MSG(">>> resp_apdu_data is null !!"); + return NET_NFC_INVALID_PARAM; + } + + if (net_nfc_gdbus_hce_call_response_apdu_sync( + hce_proxy, + GPOINTER_TO_UINT(handle), + arg_data, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == true) { + } else { + DEBUG_ERR_MSG("Response APDU failed: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +net_nfc_error_e net_nfc_client_hce_init(void) +{ + GError *error = NULL; + + DEBUG_CLIENT_MSG("net_nfc_client_hce_init call"); + + if (hce_proxy) + { + DEBUG_CLIENT_MSG("Already initialized"); + + return NET_NFC_OK; + } + + hce_proxy = net_nfc_gdbus_hce_proxy_new_for_bus_sync( + G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + "org.tizen.NetNfcService", + "/org/tizen/NetNfcService/Hce", + NULL, + &error); + + if (hce_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + + g_signal_connect(hce_proxy, "event-received", + G_CALLBACK(hce_event_received), NULL); + + /* get package name */ + __load_package_name(); + + return NET_NFC_OK; +} + +void net_nfc_client_hce_deinit(void) +{ + if (hce_proxy != NULL) + { + g_object_unref(hce_proxy); + hce_proxy = NULL; + } +} diff --git a/src/clientlib/net_nfc_client_internal_se.c b/src/clientlib/net_nfc_client_internal_se.c deleted file mode 100755 index c8bf5fe..0000000 --- a/src/clientlib/net_nfc_client_internal_se.c +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "net_nfc_typedef_private.h" -#include "net_nfc_debug_private.h" -#include "net_nfc_util_private.h" -#include "net_nfc_client_ipc_private.h" - -#ifndef NET_NFC_EXPORT_API -#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) -#endif - -NET_NFC_EXPORT_API -net_nfc_error_e net_nfc_set_card_emulation_mode_sync( - net_nfc_card_emulation_mode_t se_mode) -{ - net_nfc_error_e ret = NET_NFC_OK; - net_nfc_request_se_change_card_emulation_t request = { 0, }; - - if (se_mode < NET_NFC_SE_TYPE_NONE || se_mode > NET_NFC_SE_TYPE_UICC) - { - return NET_NFC_INVALID_PARAM; - } - - request.length = sizeof(net_nfc_request_se_change_card_emulation_t); - request.request_type = NET_NFC_MESSAGE_CARD_EMULATION_CHANGE_SE; - request.se_mode = se_mode; - - ret = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL); - - if (ret != NET_NFC_OK) - DEBUG_ERR_MSG("net_nfc_set_card_emulation_mode_sync failed [%d]", ret); - - return ret; -} - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_secure_element_type_sync( - net_nfc_se_type_e se_type) -{ - net_nfc_error_e ret = NET_NFC_OK; - net_nfc_request_set_se_t request = { 0, }; - - if (se_type < NET_NFC_SE_TYPE_NONE || se_type > NET_NFC_SE_TYPE_UICC) - { - return NET_NFC_INVALID_PARAM; - } - - request.length = sizeof(net_nfc_request_set_se_t); - request.request_type = NET_NFC_MESSAGE_SET_SE; - request.se_type = se_type; - - ret = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL); - if (ret != NET_NFC_OK) - DEBUG_ERR_MSG("net_nfc_set_secure_element_type_sync failed [%d]", ret); - - return ret; -} - - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_secure_element_type(net_nfc_se_type_e se_type, void *trans_param) -{ - net_nfc_error_e ret; - net_nfc_request_set_se_t request = { 0, }; - - if (se_type < NET_NFC_SE_TYPE_NONE || se_type > NET_NFC_SE_TYPE_UICC) - { - return NET_NFC_INVALID_PARAM; - } - - request.length = sizeof(net_nfc_request_set_se_t); - request.request_type = NET_NFC_MESSAGE_SET_SE; - request.se_type = se_type; - request.trans_param = trans_param; - - ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL); - - return ret; -} - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_secure_element_type(void *trans_param) -{ - net_nfc_error_e ret; - net_nfc_request_get_se_t request = { 0, }; - - request.length = sizeof(net_nfc_request_get_se_t); - request.request_type = NET_NFC_MESSAGE_GET_SE; - request.trans_param = trans_param; - - ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL); - - return ret; -} - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_open_internal_secure_element(net_nfc_se_type_e se_type, void *trans_param) -{ - net_nfc_error_e ret; - net_nfc_request_open_internal_se_t request = { 0, }; - - if (se_type < NET_NFC_SE_TYPE_NONE || se_type > NET_NFC_SE_TYPE_UICC) - { - return NET_NFC_INVALID_PARAM; - } - - request.length = sizeof(net_nfc_request_open_internal_se_t); - request.request_type = NET_NFC_MESSAGE_OPEN_INTERNAL_SE; - request.se_type = se_type; - request.trans_param = trans_param; - - ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL); - - return ret; -} - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_open_internal_secure_element_sync(net_nfc_se_type_e se_type, net_nfc_target_handle_h *handle) -{ - net_nfc_request_open_internal_se_t request = { 0, }; - net_nfc_target_handle_h temp = NULL; - net_nfc_error_e result; - - if (se_type < NET_NFC_SE_TYPE_NONE || se_type > NET_NFC_SE_TYPE_UICC) { - return NET_NFC_INVALID_PARAM; - } - - request.length = sizeof(net_nfc_request_open_internal_se_t); - request.request_type = NET_NFC_MESSAGE_OPEN_INTERNAL_SE; - request.se_type = se_type; - request.user_param = (uint32_t)&temp; - - result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL); - if (result == NET_NFC_OK) { - if (temp != NULL) { - *handle = temp; - } else { - DEBUG_ERR_MSG("NULL handle returned data returned"); - result = NET_NFC_OPERATION_FAIL; - } - } else{ - DEBUG_ERR_MSG("net_nfc_client_send_request_sync failed [%d]", result); - } - - return result; -} - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_close_internal_secure_element(net_nfc_target_handle_h handle, void *trans_param) -{ - net_nfc_error_e ret; - net_nfc_request_close_internal_se_t request = { 0, }; - - if (handle == NULL) - { - return NET_NFC_NULL_PARAMETER; - } - - request.length = sizeof(net_nfc_request_close_internal_se_t); - request.request_type = NET_NFC_MESSAGE_CLOSE_INTERNAL_SE; - request.handle = (net_nfc_target_handle_s *)handle; - request.trans_param = trans_param; - - ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL); - - return ret; -} - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_close_internal_secure_element_sync(net_nfc_target_handle_h handle) -{ - net_nfc_error_e result; - net_nfc_request_close_internal_se_t request = { 0, }; - - if (handle == NULL) { - return NET_NFC_NULL_PARAMETER; - } - - request.length = sizeof(net_nfc_request_close_internal_se_t); - request.request_type = NET_NFC_MESSAGE_CLOSE_INTERNAL_SE; - request.handle = (net_nfc_target_handle_s *)handle; - - result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL); - - return result; -} - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_apdu(net_nfc_target_handle_h handle, data_h apdu, void *trans_param) -{ - net_nfc_error_e ret; - net_nfc_request_send_apdu_t *request = NULL; - uint32_t length = 0; - data_s *apdu_data = (data_s *)apdu; - - if (handle == NULL || apdu_data == NULL || apdu_data->buffer == NULL || apdu_data->length == 0) - { - return NET_NFC_NULL_PARAMETER; - } - - length = sizeof(net_nfc_request_send_apdu_t) + apdu_data->length; - - _net_nfc_util_alloc_mem(request, length); - if (request == NULL) - { - return NET_NFC_ALLOC_FAIL; - } - - request->length = length; - request->request_type = NET_NFC_MESSAGE_SEND_APDU_SE; - request->handle = (net_nfc_target_handle_s *)handle; - request->trans_param = trans_param; - - request->data.length = apdu_data->length; - memcpy(&request->data.buffer, apdu_data->buffer, request->data.length); - - ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL); - - _net_nfc_util_free_mem(request); - - return ret; -} - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_apdu_sync(net_nfc_target_handle_h handle, data_h apdu, data_h *response) -{ - net_nfc_request_send_apdu_t *request = NULL; - data_s *apdu_data = (data_s *)apdu; - net_nfc_error_e result; - uint32_t length; - data_h resp = NULL; - - if (handle == NULL || apdu_data == NULL || apdu_data->buffer == NULL || apdu_data->length == 0) - { - return NET_NFC_NULL_PARAMETER; - } - - length = sizeof(net_nfc_request_send_apdu_t) + apdu_data->length; - - _net_nfc_util_alloc_mem(request, length); - if (request == NULL) - { - return NET_NFC_ALLOC_FAIL; - } - - request->length = length; - request->request_type = NET_NFC_MESSAGE_SEND_APDU_SE; - request->handle = (net_nfc_target_handle_s *)handle; - request->user_param = (uint32_t)&resp; - - request->data.length = apdu_data->length; - memcpy(&request->data.buffer, apdu_data->buffer, request->data.length); - - result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)request, NULL); - if (result == NET_NFC_OK) { - if (resp != NULL) { - *response = resp; - } else { - DEBUG_ERR_MSG("NULL response returned"); - result = NET_NFC_OPERATION_FAIL; - } - } else { - DEBUG_ERR_MSG("net_nfc_client_send_request_sync failed [%d]", result); - } - - _net_nfc_util_free_mem(request); - - return result; -} - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_atr(net_nfc_target_handle_h handle, void *trans_param) -{ - net_nfc_error_e ret; - net_nfc_request_get_atr_t request = { 0, }; - - if (handle == NULL) - { - return NET_NFC_NULL_PARAMETER; - } - - request.length = sizeof(net_nfc_request_get_atr_t); - request.request_type = NET_NFC_MESSAGE_GET_ATR_SE; - request.handle = (net_nfc_target_handle_s *)handle; - request.user_param = (uint32_t)trans_param; - - ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL); - - return ret; -} - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_atr_sync(net_nfc_target_handle_h handle, data_h *atr) -{ - net_nfc_request_get_atr_t request = { 0, }; - data_h response = NULL; - net_nfc_error_e result; - - if (handle == NULL) { - return NET_NFC_NULL_PARAMETER; - } - - request.length = sizeof(net_nfc_request_get_atr_t); - request.request_type = NET_NFC_MESSAGE_GET_ATR_SE; - request.handle = (net_nfc_target_handle_s *)handle; - request.user_param = (uint32_t)&response; - - result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL); - if (result == NET_NFC_OK) { - if (response != NULL) { - *atr = response; - } else { - result = NET_NFC_OPERATION_FAIL; - } - } - - return result; -} diff --git a/src/clientlib/net_nfc_client_ipc.c b/src/clientlib/net_nfc_client_ipc.c deleted file mode 100755 index 97d8ba9..0000000 --- a/src/clientlib/net_nfc_client_ipc.c +++ /dev/null @@ -1,1765 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "net_nfc_typedef_private.h" -#include "net_nfc_debug_private.h" -#include "net_nfc_util_defines.h" -#include "net_nfc_util_private.h" -#include "net_nfc_client_ipc_private.h" -#include "net_nfc_client_dispatcher_private.h" - -/* static variable */ -static pid_t g_client_pid; -static int g_client_sock_fd = -1; -static pthread_mutex_t g_client_ipc_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t g_client_ipc_cond = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t cb_lock = PTHREAD_MUTEX_INITIALIZER; -static net_nfc_response_cb client_cb = NULL; -static net_nfc_error_e sync_result; - -#ifdef G_MAIN_LOOP -static GIOChannel *g_client_channel = NULL; -static uint32_t g_client_src_id = 0; -#else -#ifdef USE_IPC_EPOLL -#define EPOLL_SIZE 128 -static int g_client_poll_fd = -1; -static struct epoll_event g_client_poll_event = { 0, }; -#else -static fd_set fdset_read; -#endif -static pthread_t g_poll_thread = (pthread_t)0; -#endif - -/* static function */ -static net_nfc_response_msg_t *net_nfc_client_read_response_msg(net_nfc_error_e *result); -#ifdef G_MAIN_LOOP -gboolean net_nfc_client_ipc_callback_func(GIOChannel *channel, GIOCondition condition, gpointer data); -#else -static bool net_nfc_client_ipc_polling(net_nfc_error_e *result); -static void *net_nfc_client_ipc_thread(void *data); -#endif - -///////////////////// - -inline void net_nfc_client_ipc_lock() -{ - pthread_mutex_lock(&g_client_ipc_mutex); -} - -inline void net_nfc_client_ipc_unlock() -{ - pthread_mutex_unlock(&g_client_ipc_mutex); -} - -static void net_nfc_client_prepare_sync_call(net_nfc_request_msg_t *msg) -{ - net_nfc_client_ipc_lock(); - - NET_NFC_FLAGS_SET_SYNC_CALL(msg->flags); -} - -static net_nfc_error_e net_nfc_client_wait_sync_call(int timeout) -{ - net_nfc_error_e result = NET_NFC_OPERATION_FAIL; - struct timeval now; - struct timespec ts; - - gettimeofday(&now, NULL); - ts.tv_sec = now.tv_sec + timeout; - ts.tv_nsec = now.tv_usec * 1000; - - if (pthread_cond_timedwait(&g_client_ipc_cond, &g_client_ipc_mutex, - &ts) == 0) - { - result = sync_result; - } - - return result; -} - -static void net_nfc_client_post_sync_call() -{ - net_nfc_client_ipc_unlock(); -} - -static void net_nfc_client_recv_sync_call() -{ - net_nfc_client_ipc_lock(); -} - -static void net_nfc_client_notify_sync_call(net_nfc_error_e result) -{ - sync_result = result; - - pthread_cond_signal(&g_client_ipc_cond); - net_nfc_client_ipc_unlock(); -} - -bool net_nfc_client_is_connected() -{ -#ifdef G_MAIN_LOOP - if (g_client_sock_fd != -1 && g_client_channel != NULL && g_client_src_id != 0) -#else -#ifdef USE_IPC_EPOLL - if (g_client_sock_fd != -1 && g_client_poll_fd != -1 && g_poll_thread != (pthread_t)NULL) -#else - if (g_client_sock_fd != -1 && g_poll_thread != (pthread_t)NULL) -#endif -#endif - { - return true; - } - else - { - return false; - } -} - -static net_nfc_error_e _finalize_client_socket() -{ - net_nfc_error_e result = NET_NFC_OK; - - DEBUG_CLIENT_MSG("finalize client socket"); - - net_nfc_client_ipc_lock(); - - if (g_client_sock_fd != -1) - { -#ifdef G_MAIN_LOOP - g_io_channel_unref(g_client_channel); - g_client_channel = NULL; - - g_source_remove(g_client_src_id); - g_client_src_id = 0; -#else -#if 0 - if (g_poll_thread != (pthread_t)NULL) - { -#ifdef NET_NFC_USE_SIGTERM - /* This is dangerous because of the lock inside of the thread it creates dead lock! - * it may damage the application data or lockup, sigterm can be recieved while the application codes is executed in callback function - */ - pthread_kill(g_poll_thread, SIGTERM); -#else - DEBUG_CLIENT_MSG("join epoll_thread start"); - pthread_join(g_poll_thread, NULL); - DEBUG_CLIENT_MSG("join epoll_thread end"); -#endif - } - g_poll_thread = (pthread_t)NULL; -#endif -#ifdef USE_IPC_EPOLL - if (g_client_poll_fd != -1) - { - struct epoll_event ev; - - ev.events = EPOLLIN | EPOLLET | EPOLLRDHUP | EPOLLERR; - ev.data.fd = g_client_sock_fd; - - int ret = epoll_ctl(g_client_poll_fd, EPOLL_CTL_DEL, g_client_sock_fd, &ev); - - ret = close(g_client_poll_fd); - g_client_poll_fd = -1; - DEBUG_CLIENT_MSG("epoll close, %d", ret); - } -#else - FD_CLR(g_client_sock_fd, &fdset_read); -#endif -#endif // #ifdef G_MAIN_LOOP - close(g_client_sock_fd); - g_client_sock_fd = -1; - DEBUG_CLIENT_MSG("close socket"); - } - - net_nfc_client_ipc_unlock(); - - return result; -} - -net_nfc_error_e net_nfc_client_socket_initialize() -{ - int ret; - net_nfc_error_e result = NET_NFC_OK; - - if (net_nfc_client_is_connected() == true) - { - DEBUG_CLIENT_MSG("client is already initialized"); - return NET_NFC_ALREADY_INITIALIZED; - } - - g_client_pid = getpid(); - - pthread_mutexattr_t attr; - - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); - pthread_mutex_init(&cb_lock, &attr); - -#ifdef USE_UNIX_DOMAIN - struct sockaddr_un saddrun_rv; - socklen_t len_saddr = 0; - - memset(&saddrun_rv, 0, sizeof(struct sockaddr_un)); - - net_nfc_client_ipc_lock(); - - g_client_sock_fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (g_client_sock_fd == -1) - { - DEBUG_ERR_MSG("get socket is failed"); - net_nfc_client_ipc_unlock(); - return NET_NFC_IPC_FAIL; - } - - DEBUG_CLIENT_MSG("socket is created"); - - net_nfc_util_set_non_block_socket(g_client_sock_fd); - - saddrun_rv.sun_family = AF_UNIX; - strncpy(saddrun_rv.sun_path, NET_NFC_SERVER_DOMAIN, sizeof(saddrun_rv.sun_path) - 1); - - len_saddr = sizeof(saddrun_rv.sun_family) + strlen(NET_NFC_SERVER_DOMAIN); - - if (connect(g_client_sock_fd, (struct sockaddr *)&saddrun_rv, len_saddr) < 0) - { - DEBUG_ERR_MSG("error is occured"); - result = NET_NFC_IPC_FAIL; - goto ERROR; - } -#else - struct sockaddr_in serv_addr; - memset(&serv_addr, 0x00, sizeof(struct sockaddr_in)); - - g_client_sock_fd = socket(PF_INET, SOCK_STREAM, 0); - - if (g_client_sock_fd == -1) - { - DEBUG_ERR_MSG("get socket is failed "); - net_nfc_client_ipc_unlock(); - return NET_NFC_IPC_FAIL; - } - - DEBUG_CLIENT_MSG("socket is created"); - - net_nfc_util_set_non_block_socket(g_client_sock_fd); - - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); - serv_addr.sin_port = htons(NET_NFC_SERVER_PORT); - - if ((connect(g_client_sock_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0) - { - DEBUG_ERR_MSG("error is occured"); - result = NET_NFC_IPC_FAIL; - goto ERROR; - } - -#endif - -#ifdef G_MAIN_LOOP - - GIOCondition condition = (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_IN); - - if ((g_client_channel = g_io_channel_unix_new(g_client_sock_fd)) != NULL) - { - if ((g_client_src_id = g_io_add_watch(g_client_channel, condition, net_nfc_client_ipc_callback_func, NULL)) < 1) - { - DEBUG_ERR_MSG(" g_io_add_watch is failed "); - result = NET_NFC_IPC_FAIL; - goto ERROR; - } - } - else - { - DEBUG_ERR_MSG(" g_io_channel_unix_new is failed "); - result = NET_NFC_IPC_FAIL; - goto ERROR; - } - - DEBUG_CLIENT_MSG("socket and g io channel is binded"); - -#else - -#ifdef USE_IPC_EPOLL - if ((g_client_poll_fd = epoll_create1(EPOLL_CLOEXEC)) == -1) - { - DEBUG_ERR_MSG("error is occured"); - result = NET_NFC_IPC_FAIL; - goto ERROR; - } - - memset(&g_client_poll_event, 0, sizeof(g_client_poll_event)); - - struct epoll_event ev; - - ev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR; - ev.data.fd = g_client_sock_fd; - - ret = epoll_ctl(g_client_poll_fd, EPOLL_CTL_ADD, g_client_sock_fd, &ev); -#else - FD_ZERO(&fdset_read); - FD_SET(g_client_sock_fd, &fdset_read); -#endif - - /* create polling thread and go */ - pthread_attr_t thread_attr; - pthread_attr_init(&thread_attr); - pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); - - pthread_cond_t pcond = PTHREAD_COND_INITIALIZER; - - if (pthread_create(&g_poll_thread, NULL, net_nfc_client_ipc_thread, &pcond) != 0) - { - DEBUG_ERR_MSG("error is occured"); - pthread_attr_destroy(&thread_attr); - result = NET_NFC_THREAD_CREATE_FAIL; - goto ERROR; - } - - usleep(0); - -#ifdef NET_NFC_USE_SIGTERM - pthread_cond_wait(&pcond, &g_client_ipc_mutex); -#endif - - DEBUG_CLIENT_MSG("start ipc thread = [%x]", (uint32_t)g_poll_thread); - - ////////////////////////////////// - - pthread_attr_destroy(&thread_attr); - -#endif // #ifdef G_MAIN_LOOP - net_nfc_client_ipc_unlock(); - - return NET_NFC_OK; - -ERROR : - DEBUG_ERR_MSG("error while initializing client ipc"); - - net_nfc_client_ipc_unlock(); - - _finalize_client_socket(); - - return result; -} - -#ifdef NET_NFC_USE_SIGTERM -static void thread_sig_handler(int signo) -{ - /* do nothing */ -} -#endif - -#ifndef G_MAIN_LOOP -static void *net_nfc_client_ipc_thread(void *data) -{ - DEBUG_CLIENT_MSG("net_nfc_client_ipc_thread is started = [0x%lx]", pthread_self()); - -#ifdef NET_NFC_USE_SIGTERM - - struct sigaction act; - act.sa_handler = thread_sig_handler; - sigaction(SIGTERM, &act, NULL); - - sigset_t newmask; - sigemptyset(&newmask); - sigaddset(&newmask, SIGTERM); - pthread_sigmask(SIG_UNBLOCK, &newmask, NULL); - DEBUG_CLIENT_MSG("sighandler is registered"); - -#endif - -#ifdef NET_NFC_USE_SIGTERM - net_nfc_client_ipc_lock(); - pthread_cond_signal((pthread_cond_t *)data); - net_nfc_client_ipc_unlock(); -#endif - - bool condition = true; - - while (condition == true) - { - net_nfc_error_e result = 0; - - if (net_nfc_client_ipc_polling(&result) != true) - { - switch (result) - { - case NET_NFC_OPERATION_FAIL : - DEBUG_CLIENT_MSG("shutdown request from server, stop ipc polling thread"); - _finalize_client_socket(); - condition = false; - break; - - case NET_NFC_IPC_FAIL : - DEBUG_ERR_MSG("abnormal socket close."); - _finalize_client_socket(); - condition = false; - break; - - default : - DEBUG_ERR_MSG("???"); - break; - } - } - else - { - net_nfc_response_msg_t *msg = NULL; - - DEBUG_CLIENT_MSG("message is coming from server to client"); - - msg = net_nfc_client_read_response_msg(&result); - - if (msg != NULL && msg->detail_message != NULL) - { - /* TODO : need to remove */ - net_nfc_response_msg_t *temp = (net_nfc_response_msg_t *)(msg->detail_message); -; - if (NET_NFC_FLAGS_IS_SYNC_CALL(temp->flags)) - { - net_nfc_error_e result; - - net_nfc_client_recv_sync_call(); - - /* call a callback in IPC thread */ - result = net_nfc_client_dispatch_sync_response(msg); - - /* unset sync call flag */ - net_nfc_client_notify_sync_call(result); - } - else - { - pthread_mutex_lock(&cb_lock); -#ifdef USE_GLIB_MAIN_LOOP - net_nfc_client_call_dispatcher_in_g_main_loop(client_cb, msg); -#elif USE_ECORE_MAIN_LOOP - net_nfc_client_call_dispatcher_in_ecore_main_loop(client_cb, msg); -#else - net_nfc_client_call_dispatcher_in_current_context(client_cb, msg); -#endif - pthread_mutex_unlock(&cb_lock); - } - } - else - { - /* if client is waiting for unlock signal, then unlock it. - * and send error message - * or make error response message and pass to client callback - */ - if (net_nfc_client_is_connected() == false) - { - condition = false; - } - DEBUG_ERR_MSG("cannot read response msg"); - } - } - } - - DEBUG_CLIENT_MSG("net_nfc_client_ipc_thread is terminated"); - - return (void *)NULL; -} -#endif - -#ifdef G_MAIN_LOOP -gboolean net_nfc_client_ipc_callback_func(GIOChannel *channel, GIOCondition condition, gpointer data) -{ - DEBUG_CLIENT_MSG("event is detected on client socket"); - - if(G_IO_IN & condition) - { - - int client_sock_fd = 0; - - if(channel == g_client_channel) - { - - DEBUG_CLIENT_MSG("message from server to client socket"); - - net_nfc_error_e result = NET_NFC_OK; - net_nfc_response_msg_t *msg = net_nfc_client_read_response_msg(&result); - - if(msg != NULL) - { - - net_nfc_client_call_dispatcher_in_current_context(client_cb, msg); - } - else - { - DEBUG_CLIENT_MSG("can not read response msg or callback is NULL"); - } - - } - else - { - DEBUG_CLIENT_MSG("unknown channel "); - return FALSE; - } - } - else - { - - DEBUG_CLIENT_MSG("IO ERROR. socket is closed "); - - /* clean up client context */ - net_nfc_client_socket_finalize(); - - return FALSE; - } - - return TRUE; -} -#else -bool net_nfc_client_ipc_polling(net_nfc_error_e *result) -{ - int num_of_sockets = 0; - - if (result == NULL) - { - return false; - } - - *result = NET_NFC_OK; - -#ifdef USE_IPC_EPOLL - DEBUG_CLIENT_MSG("wait event from epoll"); - - if (g_client_poll_fd == -1 || g_client_sock_fd == -1) - { - DEBUG_ERR_MSG("client is deinitialized. "); - *result = NET_NFC_IPC_FAIL; - return false; - } - - /* 0.5sec */ -#ifndef USE_EPOLL_TIMEOUT - while ((num_of_sockets = epoll_wait(g_client_poll_fd, &g_client_poll_event, 1, 300)) == 0) - { - if (g_client_poll_fd == -1) - { - DEBUG_CLIENT_MSG("client ipc thread is terminated"); - return false; - } - } -#else - num_of_sockets = epoll_wait(g_client_poll_fd, &g_client_poll_event, 1, -1); -#endif - if (num_of_sockets == 1) - { - if (g_client_poll_event.events & EPOLLRDHUP) - { - DEBUG_CLIENT_MSG("EPOLLRDHUP"); - *result = NET_NFC_OPERATION_FAIL; - return false; - } - else if (g_client_poll_event.events & EPOLLHUP) - { - DEBUG_CLIENT_MSG("EPOLLHUP"); - *result = NET_NFC_IPC_FAIL; - return false; - } - else if (g_client_poll_event.events & EPOLLERR) - { - DEBUG_CLIENT_MSG("EPOLLERR"); - *result = NET_NFC_IPC_FAIL; - return false; - } - else if (g_client_poll_event.events & EPOLLIN) - { - if (g_client_poll_event.data.fd == g_client_sock_fd) - { - return true; - } - else - { - DEBUG_ERR_MSG("unexpected socket connection"); - return false; - } - } - } - else - { - DEBUG_ERR_MSG("epoll_wait returns error"); - return false; - } -#else - DEBUG_CLIENT_MSG("wait event from select"); - - int temp = select(g_client_sock_fd + 1, &fdset_read, NULL, NULL, NULL); - - if(temp > 0) - { - if(FD_ISSET(g_client_sock_fd, &fdset_read) == true) - { - int val = 0; - int size = 0; - - if(getsockopt(g_client_sock_fd, SOL_SOCKET, SO_ERROR, &val, &size) == 0) - { - if(val != 0) - { - DEBUG_CLIENT_MSG("socket is on error"); - return false; - } - else - { - DEBUG_CLIENT_MSG("socket is readable"); - return true; - } - } - } - else - { - DEBUG_ERR_MSG("unknown error"); - *result = NET_NFC_IPC_FAIL; - return false; - } - } -#endif - - DEBUG_CLIENT_MSG("polling error"); - *result = NET_NFC_IPC_FAIL; - return false; -} -#endif - -void net_nfc_client_socket_finalize() -{ - net_nfc_client_ipc_lock(); - - if (g_client_sock_fd != -1) - { - DEBUG_CLIENT_MSG("shutdown socket, and wait EPOLLRDHUP"); - shutdown(g_client_sock_fd, SHUT_WR); - } - - net_nfc_client_ipc_unlock(); -} - -int __net_nfc_client_read_util(void **detail, size_t size) -{ - int length; - static uint8_t flushing[128]; - - if (recv(g_client_sock_fd, &length, sizeof(length), 0) != sizeof(length)) - { - return 0; - } - - *detail = NULL; - _net_nfc_util_alloc_mem(*detail, size); - - /* if the allocation is failed, this codes flush out all the buffered data */ - if (*detail == NULL) - { - size_t read_size; - int readbytes = size; - while (readbytes > 0) - { - read_size = readbytes > 128 ? 128 : readbytes; - if (recv(g_client_sock_fd, flushing, read_size, 0) <= 0) - { - return 0; - } - readbytes -= read_size; - } - return 0; - } - /* read */ - if (recv(g_client_sock_fd, *detail, size, 0) <= 0) - { - _net_nfc_util_free_mem(*detail); - return 0; - } - return 1; -} - -net_nfc_response_msg_t *net_nfc_client_read_response_msg(net_nfc_error_e *result) -{ - net_nfc_response_msg_t *resp_msg = NULL; - - _net_nfc_util_alloc_mem(resp_msg, sizeof(net_nfc_response_msg_t)); - if (resp_msg == NULL) - { - DEBUG_ERR_MSG("malloc fail"); - *result = NET_NFC_ALLOC_FAIL; - return NULL; - } - - if (recv(g_client_sock_fd, (void *)&(resp_msg->response_type), sizeof(int), 0) != sizeof(int)) - { - DEBUG_ERR_MSG("reading message is failed"); - _net_nfc_util_free_mem(resp_msg); - - return NULL; - } - -// DEBUG_MSG("<<<<< FROM SERVER <<<<< (msg [%d], length [%d])", resp_msg->response_type, length); - DEBUG_MSG("[%d] <<<<<<<<<<<<<<< (msg [%d])", g_client_pid, resp_msg->response_type); - - switch (resp_msg->response_type) - { - case NET_NFC_MESSAGE_SET_SE : - { - net_nfc_response_set_se_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_set_se_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_GET_SE : - { - net_nfc_response_get_se_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_get_se_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_SE_TYPE_CHANGED : - { - net_nfc_response_notify_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_notify_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_OPEN_INTERNAL_SE : - { - net_nfc_response_open_internal_se_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_open_internal_se_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - DEBUG_CLIENT_MSG("handle = [0x%p]", resp_detail->handle); - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE : - { - net_nfc_response_close_internal_se_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_close_internal_se_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_SEND_APDU_SE : - { - - net_nfc_response_send_apdu_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_send_apdu_t)); - if (res == 1) - { - if (resp_detail->data.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); - if (res == 2) - { - resp_msg->detail_message = resp_detail; - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->data.buffer = NULL; - } - } - if (res == 0) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - } - break; - - case NET_NFC_MESSAGE_TAG_DISCOVERED : - { - net_nfc_response_tag_discovered_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_tag_discovered_t)); - if (res == 1) - { - if (resp_detail->target_info_values.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->target_info_values.buffer), resp_detail->target_info_values.length); - if (res == 2) - { - if (resp_detail->raw_data.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->raw_data.buffer), resp_detail->raw_data.length); - if (res == 3) - { - resp_msg->detail_message = resp_detail; - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->raw_data.buffer = NULL; - } - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->target_info_values.buffer = NULL; - } - } - if (res == 0) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - } - break; - - case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO : - { - net_nfc_response_get_current_tag_info_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_get_current_tag_info_t)); - if (res == 1) - { - if (resp_detail->target_info_values.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->target_info_values.buffer), resp_detail->target_info_values.length); - if (res == 2) - { - if (resp_detail->raw_data.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->raw_data.buffer), resp_detail->raw_data.length); - if (res == 3) - { - resp_msg->detail_message = resp_detail; - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->raw_data.buffer = NULL; - } - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->target_info_values.buffer = NULL; - } - } - if (res == 0) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - } - break; - - case NET_NFC_MESSAGE_SE_START_TRANSACTION : - case NET_NFC_MESSAGE_SE_END_TRANSACTION : - case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION : - case NET_NFC_MESSAGE_SE_CONNECTIVITY : - case NET_NFC_MESSAGE_SE_FIELD_ON : - case NET_NFC_MESSAGE_SE_FIELD_OFF : - { - net_nfc_response_se_event_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_se_event_t)); - if (res == 1) - { - if (resp_detail->aid.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->aid.buffer), resp_detail->aid.length); - if (res == 2) - { - if (resp_detail->param.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->param.buffer), resp_detail->param.length); - if (res == 3) - { - resp_msg->detail_message = resp_detail; - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->param.buffer = NULL; - } - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->aid.buffer = NULL; - } - } - if (res == 0) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - } - break; - - case NET_NFC_MESSAGE_CARD_EMULATION_CHANGE_SE : - { - net_nfc_response_se_change_card_emulation_t *resp_detail = NULL; - int res = 0; - - DEBUG_CLIENT_MSG("Client Receive the NET_NFC_MESSAGE_CARD_EMULATION_CHANGE_SE"); - - res = __net_nfc_client_read_util((void **)&resp_detail, - sizeof(net_nfc_response_se_change_card_emulation_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - - } - break; - - case NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED : - { - net_nfc_response_notify_t *resp_detail = NULL; - int res = 0; - - DEBUG_CLIENT_MSG("Client Receive the NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED"); - - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_notify_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_TRANSCEIVE : - { - net_nfc_response_transceive_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_transceive_t)); - if (res == 1) - { - if (resp_detail->data.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); - if (res == 2) - { - resp_msg->detail_message = resp_detail; - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->data.buffer = NULL; - } - } - if (res == 0) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - } - break; - - case NET_NFC_MESSAGE_READ_NDEF : - { - - net_nfc_response_read_ndef_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_read_ndef_t)); - if (res == 1) - { - if (resp_detail->data.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); - if (res == 2) - { - resp_msg->detail_message = resp_detail; - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->data.buffer = NULL; - } - } - if (res == 0) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - } - break; - - case NET_NFC_MESSAGE_WRITE_NDEF : - { - net_nfc_response_write_ndef_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_write_ndef_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_SIM_TEST : - { - net_nfc_response_test_t *resp_detail = NULL; - int res = 0; - - DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_SIM_TEST"); - - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_PRBS_TEST : - { - net_nfc_response_test_t *resp_detail = NULL; - int res = 0; - - DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_PRBS_TEST"); - - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_SET_EEDATA : - { - net_nfc_response_test_t *resp_detail = NULL; - int res = 0; - - DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_SET_EEDATA"); - - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION : - { - net_nfc_response_firmware_version_t *resp_detail = NULL; - - DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_GET_FIRMWARE_VERSION"); - - if (__net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_firmware_version_t)) > 0) - { - if (__net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length) > 0) - { - resp_msg->detail_message = resp_detail; - } - else - { - _net_nfc_util_free_mem(resp_msg); - _net_nfc_util_free_mem(resp_detail); - return NULL; - } - } - else - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - } - break; - - case NET_NFC_MESSAGE_NOTIFY : - { - net_nfc_response_notify_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_notify_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - case NET_NFC_MESSAGE_TAG_DETACHED : - { - net_nfc_response_target_detached_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_target_detached_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_FORMAT_NDEF : - { - - net_nfc_response_format_ndef_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_format_ndef_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - - } - break; - - case NET_NFC_MESSAGE_LLCP_DISCOVERED : - { - net_nfc_response_llcp_discovered_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_llcp_discovered_t)); - if (res == 1) - { - if (resp_detail->target_info_values.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->target_info_values.buffer), resp_detail->target_info_values.length); - if (res == 2) - { - resp_msg->detail_message = resp_detail; - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->target_info_values.buffer = NULL; - } - } - if (res == 0) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - } - break; - - case NET_NFC_MESSAGE_P2P_DETACHED : - { - net_nfc_response_llcp_detached_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_llcp_detached_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_LLCP_LISTEN : - { - net_nfc_response_listen_socket_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_listen_socket_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - - } - break; - case NET_NFC_MESSAGE_LLCP_CONNECT : - { - net_nfc_response_connect_socket_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_connect_socket_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - - } - break; - case NET_NFC_MESSAGE_LLCP_CONNECT_SAP : - { - net_nfc_response_connect_sap_socket_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_connect_sap_socket_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - - } - break; - case NET_NFC_MESSAGE_LLCP_SEND : - { - net_nfc_response_send_socket_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_send_socket_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_LLCP_RECEIVE : - { - net_nfc_response_receive_socket_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_receive_socket_t)); - if (res == 1) - { - - if (resp_detail->data.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); - } - if (res == 2) - { - resp_msg->detail_message = resp_detail; - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->data.buffer = NULL; - } - } - break; - - case NET_NFC_MESSAGE_P2P_RECEIVE : - { - net_nfc_response_p2p_receive_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_p2p_receive_t)); - if (res == 1) - { - - if (resp_detail->data.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); - } - if (res == 2) - { - resp_msg->detail_message = resp_detail; - } - else - { - _net_nfc_util_free_mem(resp_detail); - res--; - } - } - else - { - resp_msg->detail_message = resp_detail; - resp_detail->data.buffer = NULL; - } - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE : - { - net_nfc_response_close_socket_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_close_socket_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - case NET_NFC_MESSAGE_LLCP_DISCONNECT : - { - net_nfc_response_disconnect_socket_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_disconnect_socket_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_LLCP_CONFIG : - { - net_nfc_response_config_llcp_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_config_llcp_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_LLCP_ERROR : - { - net_nfc_response_llcp_socket_error_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_llcp_socket_error_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_LLCP_ACCEPTED : - { - net_nfc_response_incomming_llcp_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_incomming_llcp_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_P2P_DISCOVERED : - { - net_nfc_response_p2p_discovered_t *resp_detail = NULL; - int res = 0; - - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_p2p_discovered_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_P2P_SEND : - { - net_nfc_response_p2p_send_t *resp_detail = NULL; - int res = 0; - - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_p2p_send_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_CONNECTION_HANDOVER : - { - net_nfc_response_connection_handover_t *resp_detail = NULL; - int res = 0; - - DEBUG_CLIENT_MSG("NET_NFC_MESSAGE_CONNECTION_HANDOVER"); - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_connection_handover_t)); - - if (res == 1) - { - if (resp_detail->data.length > 0) - { - res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); - if (res < 2) - { - DEBUG_ERR_MSG("__net_nfc_client_read_util failed. res [%d]", res); - _net_nfc_util_free_mem(resp_detail); - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - } - } - else - { - DEBUG_ERR_MSG("__net_nfc_client_read_util failed. res [%d]", res); - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_IS_TAG_CONNECTED : - { - net_nfc_response_is_tag_connected_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_is_tag_connected_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - } - break; - - case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE : - { - net_nfc_response_get_current_target_handle_t *resp_detail = NULL; - int res = 0; - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_get_current_target_handle_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - - } - break; - - case NET_NFC_MESSAGE_SERVICE_INIT : - { - net_nfc_response_test_t *resp_detail = NULL; - int res = 0; - - DEBUG_CLIENT_MSG("Client Receive the NET_NFC_MESSAGE_SERVICE_INIT"); - - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - - } - break; - - case NET_NFC_MESSAGE_SERVICE_DEINIT : - { - net_nfc_response_test_t *resp_detail = NULL; - int res = 0; - - DEBUG_CLIENT_MSG("Client Receive the NET_NFC_MESSAGE_SERVICE_DEINIT"); - - res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t)); - if (res != 1) - { - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - resp_msg->detail_message = resp_detail; - - } - break; - - default : - { - DEBUG_CLIENT_MSG("Currently NOT supported RESP TYPE = [%d]", resp_msg->response_type); - _net_nfc_util_free_mem(resp_msg); - return NULL; - } - - } - - return resp_msg; -} - -bool __net_nfc_client_send_msg(void *message, int length) -{ - bool result = (send(g_client_sock_fd, (void *)message, length, MSG_NOSIGNAL) > 0); - - if (result == false) - { - uint8_t buf[1024] = { 0x00, }; - DEBUG_ERR_MSG("send failed : %s", strerror_r(errno, (char *)buf, sizeof(buf))); - } - - return result; -} - -static char *cookies = NULL; -static int cookies_size = 0; - -void _net_nfc_client_set_cookies(const char *cookie, size_t size) -{ - if (cookie != NULL && size > 0) - { - _net_nfc_util_alloc_mem(cookies, size); - - memcpy(cookies, cookie, size); - cookies_size = size; - } -} - -void _net_nfc_client_free_cookies(void) -{ - _net_nfc_util_free_mem(cookies); - cookies_size = 0; -} - -static net_nfc_error_e _send_request(net_nfc_request_msg_t *msg, va_list list) -{ - uint8_t *send_buffer = NULL; - int total_size = 0; - int written_size = 0; - - /* calc message length */ -#ifdef SECURITY_SERVER - total_size += (sizeof(cookies_size) + cookies_size); -#endif - total_size += msg->length; - total_size += net_nfc_util_get_va_list_length(list); - - _net_nfc_util_alloc_mem(send_buffer, total_size + sizeof(total_size)); - if (send_buffer == NULL) - { - return NET_NFC_ALLOC_FAIL; - } - - /* fill message */ - /* - total length */ - memcpy(send_buffer + written_size, &total_size, sizeof(total_size)); - written_size += sizeof(total_size); - -#ifdef SECURITY_SERVER - /* -- security server cookie */ - memcpy(send_buffer + written_size, &cookies_size, sizeof(cookies_size)); - written_size += sizeof(cookies_size); - - memcpy(send_buffer + written_size, cookies, cookies_size); - written_size += cookies_size; -#endif - - /* -- request message struct */ - memcpy(send_buffer + written_size, msg, msg->length); - written_size += msg->length; - - /* -- varient arguemts */ - written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size + sizeof(total_size) - written_size, list); - - bool msg_result = __net_nfc_client_send_msg((void *)send_buffer, total_size + sizeof(total_size)); - - _net_nfc_util_free_mem(send_buffer); - sleep(0); - - if (msg_result) - { - DEBUG_MSG("[%d] >>>>>>>>>>>>>>> (msg [%d], length [%d])", g_client_pid, msg->request_type, total_size); - return NET_NFC_OK; - } - else - { - return NET_NFC_IPC_FAIL; - } -} - -net_nfc_error_e net_nfc_client_send_request(net_nfc_request_msg_t *msg, ...) -{ - va_list list; - net_nfc_error_e result = NET_NFC_OK; - - va_start(list, msg); - - net_nfc_client_ipc_lock(); - - result = _send_request(msg, list); - - net_nfc_client_ipc_unlock(); - - va_end(list); - - return result; -} - -net_nfc_error_e net_nfc_client_send_request_sync(net_nfc_request_msg_t *msg, ...) -{ - va_list list; - net_nfc_error_e result = NET_NFC_OK; - - net_nfc_client_prepare_sync_call(msg); - - va_start(list, msg); - - result = _send_request(msg, list); - - va_end(list); - - if (result == NET_NFC_OK) - { - result = net_nfc_client_wait_sync_call(3); - } - net_nfc_client_post_sync_call(); - - return result; -} - -net_nfc_error_e _net_nfc_client_register_cb(net_nfc_response_cb cb) -{ - if (cb == NULL) - { - return NET_NFC_NULL_PARAMETER; - } - - pthread_mutex_lock(&cb_lock); - client_cb = cb; - pthread_mutex_unlock(&cb_lock); - - return NET_NFC_OK; -} - -net_nfc_error_e _net_nfc_client_unregister_cb(void) -{ - if (client_cb == NULL) - { - return NET_NFC_NOT_REGISTERED; - } - - pthread_mutex_lock(&cb_lock); - client_cb = NULL; - pthread_mutex_unlock(&cb_lock); - - return NET_NFC_OK; -} diff --git a/src/clientlib/net_nfc_client_llcp.c b/src/clientlib/net_nfc_client_llcp.c new file mode 100755 index 0000000..93c2b93 --- /dev/null +++ b/src/clientlib/net_nfc_client_llcp.c @@ -0,0 +1,2533 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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, + gint error, + gpointer user_data); + +static void llcp_incoming(NetNfcGDbusLlcp *object, + guint arg_handle, + guint client_socket, + guint incoming_socket, + 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 = user_data; + net_nfc_error_e result; + GError *error = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_config_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish config: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_llcp_config_completed callback = + (net_nfc_client_llcp_config_completed)func_data->callback; + + callback(result, func_data->user_data); + } + + g_free(func_data); +} + +static void llcp_call_listen(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + LlcpFuncData *func_data = user_data; + net_nfc_error_e result; + guint32 out_client_socket = -1; + GError *error = NULL; + guint32 out_oal_socket = -1; + net_nfc_llcp_internal_socket_s *socket_data = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_listen_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + &out_client_socket, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish listen: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + 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; + + if (func_data->callback != NULL) + { + net_nfc_client_llcp_listen_completed callback = + (net_nfc_client_llcp_listen_completed)func_data->callback; + + callback(result, out_client_socket, func_data->user_data); + } + + /* TODO : release resource when socket is closed */ +// g_free(func_data); +} + +static void llcp_call_accept(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + LlcpFuncData *func_data = user_data; + net_nfc_error_e result; + GError *error = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_accept_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish accept: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_llcp_accept_completed callback = + (net_nfc_client_llcp_accept_completed)func_data->callback; + + callback(result, func_data->user_data); + } + + g_free(func_data); +} + +static void llcp_call_reject(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + LlcpFuncData *func_data = user_data; + net_nfc_error_e result; + GError *error = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_reject_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish reject: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_llcp_reject_completed callback = + (net_nfc_client_llcp_reject_completed)func_data->callback; + + callback(result, func_data->user_data); + } + + g_free(func_data); +} + +static void llcp_call_connect(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + LlcpFuncData *func_data = user_data; + net_nfc_error_e result; + guint32 out_client_socket = -1; + GError *error = NULL; + guint32 out_oal_socket = -1; + net_nfc_llcp_internal_socket_s *socket_data = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_connect_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + &out_client_socket, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish connect: %s", error->message); + result = NET_NFC_IPC_FAIL; + + 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; + + if (func_data->callback != NULL) + { + net_nfc_client_llcp_connect_completed callback = + (net_nfc_client_llcp_connect_completed)func_data->callback; + + callback(result, out_client_socket, func_data->user_data); + } + + /* TODO : release resource when socket is closed */ +// g_free(func_data); +} + +static void llcp_call_connect_sap(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + LlcpFuncData *func_data = user_data; + net_nfc_error_e result; + guint32 out_client_socket = -1; + GError *error = NULL; + guint32 out_oal_socket = -1; + net_nfc_llcp_internal_socket_s *socket_data = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_connect_sap_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + &out_client_socket, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish connect sap: %s", error->message); + result = NET_NFC_IPC_FAIL; + + 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; + + if (func_data->callback != NULL) + { + net_nfc_client_llcp_connect_sap_completed callback = + (net_nfc_client_llcp_connect_sap_completed)func_data->callback; + + callback(result, out_client_socket, func_data->user_data); + } + + /* TODO : release resource when socket is closed */ +// g_free(func_data); +} + +static void llcp_call_send(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + LlcpFuncData *func_data = user_data; + net_nfc_error_e result; + guint32 out_client_socket = -1; + GError *error = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_send_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + &out_client_socket, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish send: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_llcp_send_completed callback = + (net_nfc_client_llcp_send_completed)func_data->callback; + + callback(result, func_data->user_data); + } + + g_free(func_data); +} + +static void llcp_call_send_to(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + LlcpFuncData *func_data = user_data; + net_nfc_error_e result; + guint32 out_client_socket = -1; + GError *error = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_send_to_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + &out_client_socket, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish send to: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_llcp_send_to_completed callback = + (net_nfc_client_llcp_send_to_completed)func_data->callback; + + callback(result, func_data->user_data); + } + + g_free(func_data); +} + +static void llcp_call_receive(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + LlcpFuncData *func_data = user_data; + net_nfc_error_e result; + GVariant *variant = NULL; + GError *error = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_receive_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + &variant, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish receive: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_llcp_receive_completed callback = + (net_nfc_client_llcp_receive_completed)func_data->callback; + data_s data = { NULL, 0 }; + + net_nfc_util_gdbus_variant_to_data_s(variant, &data); + + callback(result, &data, func_data->user_data); + + net_nfc_util_clear_data(&data); + } + + g_free(func_data); +} + +static void llcp_call_receive_from(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + LlcpFuncData *func_data = user_data; + net_nfc_error_e result; + sap_t sap = 0; + GVariant *variant = NULL; + GError *error = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_receive_from_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + &sap, + &variant, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish receive from: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_llcp_receive_from_completed callback = + (net_nfc_client_llcp_receive_from_completed)func_data->callback; + data_s data = { NULL, 0 }; + + net_nfc_util_gdbus_variant_to_data_s(variant, &data); + + callback(result, sap, &data, func_data->user_data); + + net_nfc_util_clear_data(&data); + } + + g_free(func_data); +} + +static void llcp_call_close(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + LlcpFuncData *func_data = user_data; + net_nfc_error_e result; + guint32 out_client_socket = -1; + GError *error = NULL; + + net_nfc_llcp_internal_socket_s *socket_data = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_close_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + &out_client_socket, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish close: %s", error->message); + result = NET_NFC_IPC_FAIL; + + 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; + } + + if (func_data->callback != NULL) + { + net_nfc_client_llcp_close_completed callback = + (net_nfc_client_llcp_close_completed)func_data->callback; + + callback(result, func_data->user_data); + } + + g_free(func_data); +} + +static void llcp_call_disconnect(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + LlcpFuncData *func_data = user_data; + net_nfc_error_e result; + guint32 out_client_socket = -1; + GError *error = NULL; + + net_nfc_llcp_internal_socket_s *socket_data = NULL; + + g_assert(func_data != NULL); + + if (net_nfc_gdbus_llcp_call_disconnect_finish( + NET_NFC_GDBUS_LLCP(source_object), + &result, + &out_client_socket, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish disconnect: %s", error->message); + result = NET_NFC_IPC_FAIL; + + 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; + } + + if (func_data->callback != NULL) { + net_nfc_client_llcp_disconnect_completed callback = + (net_nfc_client_llcp_disconnect_completed)func_data->callback; + + callback(result, func_data->user_data); + } + + g_free(func_data); +} + +static void llcp_error(NetNfcGDbusLlcp *object, + guint arg_handle, + guint client_socket, + gint error, + gpointer user_data) +{ + INFO_MSG(">>> SIGNAL arrived"); +} + +static void llcp_incoming(NetNfcGDbusLlcp *object, + guint arg_handle, + guint client_socket, + guint incoming_socket, + 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; + + if (config == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_new0(LlcpFuncData, 1); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + 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) +{ + net_nfc_error_e result; + GVariant *variant = NULL; + GError *error = NULL; + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + 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(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("can not config: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +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) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + func_data = g_new0(LlcpFuncData, 1); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + 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->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) +{ + net_nfc_error_e result; + 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 (out_socket == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_llcp_call_listen_sync(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket_data->client_socket, + socket_data->miu, + socket_data->rw, + socket_data->type, + socket_data->sap, + service_name, + net_nfc_client_gdbus_get_privilege(), + &result, + &out_client_socket, + NULL, + &error) == true) { + 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; + } else { + DEBUG_ERR_MSG("can not listen: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_llcp_accept(net_nfc_llcp_socket_t socket, + net_nfc_client_llcp_accept_completed callback, + void *user_data) +{ + LlcpFuncData *func_data; + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_new0(LlcpFuncData, 1); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; + + net_nfc_gdbus_llcp_call_accept(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket, + net_nfc_client_gdbus_get_privilege(), + NULL, + llcp_call_accept, + func_data); + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_llcp_accept_sync(net_nfc_llcp_socket_t socket) +{ + net_nfc_error_e result; + GError *error = NULL; + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_llcp_call_accept_sync(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == false) { + DEBUG_ERR_MSG("can not connect: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_llcp_reject(net_nfc_llcp_socket_t socket, + net_nfc_client_llcp_reject_completed callback, + void *user_data) +{ + LlcpFuncData *func_data; + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_new0(LlcpFuncData, 1); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; + + net_nfc_gdbus_llcp_call_reject(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket, + net_nfc_client_gdbus_get_privilege(), + NULL, + llcp_call_reject, + func_data); + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_llcp_reject_sync(net_nfc_llcp_socket_t socket) +{ + net_nfc_error_e result; + GError *error = NULL; + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_llcp_call_reject_sync(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == false) { + DEBUG_ERR_MSG("can not connect: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +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 (service_name == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + func_data = g_new0(LlcpFuncData, 1); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + 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->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) +{ + net_nfc_error_e result; + 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 (service_name == NULL || out_socket == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_llcp_call_connect_sync(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket_data->client_socket, + socket_data->miu, + socket_data->rw, + socket_data->type, + service_name, + net_nfc_client_gdbus_get_privilege(), + &result, + &out_client_socket, + NULL, + &error) == true) { + 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; + } else { + DEBUG_ERR_MSG("can not connect: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +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 (sap == 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + func_data = g_new0(LlcpFuncData, 1); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + 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->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) +{ + net_nfc_error_e result; + 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 (out_socket == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (sap == 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_llcp_call_connect_sap_sync(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket_data->client_socket, + socket_data->miu, + socket_data->rw, + socket_data->type, + sap, + net_nfc_client_gdbus_get_privilege(), + &result, + &out_client_socket, + NULL, + &error) == true) { + 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; + } else { + DEBUG_ERR_MSG("can not connect: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +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; + net_nfc_llcp_internal_socket_s *socket_data = NULL; + + if (data == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (socket <= 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + 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); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; + + variant = net_nfc_util_gdbus_data_to_variant(data); + + net_nfc_gdbus_llcp_call_send(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket_data->client_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_error_e result; + 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 (data == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (socket <= 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + variant = net_nfc_util_gdbus_data_to_variant(data); + + if (net_nfc_gdbus_llcp_call_send_sync(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket_data->client_socket, + variant, + net_nfc_client_gdbus_get_privilege(), + &result, + &out_client_socket, + NULL, + &error) == true) { + 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; + } + } else { + DEBUG_ERR_MSG("can not call send: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + + +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; + net_nfc_llcp_internal_socket_s *socket_data = NULL; + + if (data == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (socket <= 0 || sap == 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + func_data = g_new0(LlcpFuncData, 1); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; + + variant = net_nfc_util_gdbus_data_to_variant(data); + + net_nfc_gdbus_llcp_call_send_to(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket_data->client_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_error_e result; + 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 (data == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (socket <= 0 || sap == 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + variant = net_nfc_util_gdbus_data_to_variant(data); + + if (net_nfc_gdbus_llcp_call_send_to_sync(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket_data->client_socket, + sap, + variant, + net_nfc_client_gdbus_get_privilege(), + &result, + &out_client_socket, + NULL, + &error) == true) { + 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; + } + } else { + DEBUG_ERR_MSG("can not call send to: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +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 (socket <= 0 || request_length == 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + func_data = g_new0(LlcpFuncData, 1); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + 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, + 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) +{ + net_nfc_error_e result; + GVariant *variant; + GError *error = NULL; + net_nfc_llcp_internal_socket_s *socket_data; + + if (out_data == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + *out_data = NULL; + + if (socket <= 0 || request_length == 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_llcp_call_receive_sync(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket_data->client_socket, + request_length, + net_nfc_client_gdbus_get_privilege(), + &result, + &variant, + NULL, + &error) == true) { + *out_data = net_nfc_util_gdbus_variant_to_data(variant); + } else { + DEBUG_ERR_MSG("can not call receive: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +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 (socket <= 0 || request_length == 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + 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, + 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) +{ + net_nfc_error_e result; + GError *error = NULL; + GVariant *variant; + sap_t sap; + + net_nfc_llcp_internal_socket_s *socket_data; + + if (out_sap == NULL || out_data == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + *out_data = NULL; + *out_sap = 0; + + if (socket <= 0 || request_length == 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_llcp_call_receive_from_sync(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket_data->client_socket, + request_length, + net_nfc_client_gdbus_get_privilege(), + &result, + &sap, + &variant, + NULL, + &error) == true) { + *out_sap = sap; + *out_data = net_nfc_util_gdbus_variant_to_data(variant); + } else { + DEBUG_ERR_MSG("can not call receive from: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +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 (socket <= 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + func_data = g_new0(LlcpFuncData, 1); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + 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, + 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_error_e result; + 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 (socket <= 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_llcp_call_close_sync(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket_data->client_socket, + net_nfc_client_gdbus_get_privilege(), + &result, + &out_client_socket, + NULL, + &error) == true) { + 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; + } + } else { + DEBUG_ERR_MSG("can not close: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +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 (socket <= 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + func_data = g_new0(LlcpFuncData, 1); + if (func_data == NULL) { + DEBUG_ERR_MSG("g_new0 failed"); + + return NET_NFC_ALLOC_FAIL; + } + + 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, + 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_error_e result; + 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 (socket <= 0) { + return NET_NFC_INVALID_PARAM; + } + + if (llcp_proxy == NULL) + { + if(net_nfc_client_llcp_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("llcp_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_llcp_call_disconnect_sync(llcp_proxy, + GPOINTER_TO_UINT(llcp_handle), + socket_data->client_socket, + net_nfc_client_gdbus_get_privilege(), + &result, + &out_client_socket, + NULL, + &error) == true) { + 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; + } + } else { + DEBUG_ERR_MSG("can not disconnect: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +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) +{ + net_nfc_llcp_socket_option_s *struct_option = + (net_nfc_llcp_socket_option_s *)option; + + if (option == NULL || miu == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *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) +{ + net_nfc_llcp_socket_option_s *struct_option = + (net_nfc_llcp_socket_option_s *)option; + + if (option == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + 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_DO_NOT_AUTO_START, + "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); + + g_signal_connect(llcp_proxy, "incoming", + G_CALLBACK(llcp_incoming), NULL); + + return NET_NFC_OK; +} + +void net_nfc_client_llcp_deinit(void) +{ + if (llcp_proxy) + { + g_object_unref(llcp_proxy); + llcp_proxy = NULL; + } +} diff --git a/src/clientlib/net_nfc_client_manager.c b/src/clientlib/net_nfc_client_manager.c new file mode 100755 index 0000000..42c450c --- /dev/null +++ b/src/clientlib/net_nfc_client_manager.c @@ -0,0 +1,455 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_util_internal.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 + +#define DEACTIVATE_DELAY 500 /* ms */ +#define ACTIVATE_DELAY 100 /* ms */ + +typedef struct _ManagerFuncData ManagerFuncData; + +struct _ManagerFuncData +{ + gpointer callback; + gpointer user_data; + net_nfc_error_e result; +}; + +static NetNfcGDbusManager *manager_proxy = NULL; +static NetNfcGDbusManager *auto_start_proxy = NULL; +static ManagerFuncData activated_func_data; +static int is_activated = -1; +static guint timeout_id[2]; + +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 gboolean _set_activate_time_elapsed_callback(gpointer user_data) +{ + ManagerFuncData *func_data = (ManagerFuncData *)user_data; + net_nfc_client_manager_set_active_completed callback; + + if (timeout_id[0] > 0) { + g_assert(func_data != NULL); + + g_source_remove(timeout_id[0]); + timeout_id[0] = 0; + + callback = (net_nfc_client_manager_set_active_completed)func_data->callback; + + callback(func_data->result, func_data->user_data); + + g_free(func_data); + } + + return false; +} + +static void manager_call_set_active_callback(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + ManagerFuncData *func_data = (ManagerFuncData *)user_data; + net_nfc_error_e result; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_manager_call_set_active_finish( + NET_NFC_GDBUS_MANAGER(source_object), + &result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish call_set_active: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + func_data->result = result; + net_nfc_client_get_nfc_state(&is_activated); + + if (is_activated == false) { + /* FIXME : wait several times */ + timeout_id[0] = g_timeout_add(DEACTIVATE_DELAY, + _set_activate_time_elapsed_callback, + func_data); + } else { + timeout_id[0] = g_timeout_add(ACTIVATE_DELAY, + _set_activate_time_elapsed_callback, + func_data); + } +} + +static void manager_call_get_server_state_callback(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e result; + guint out_state = 0; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_manager_call_get_server_state_finish( + NET_NFC_GDBUS_MANAGER(source_object), + &result, + &out_state, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish get_server_state: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_manager_get_server_state_completed callback = + (net_nfc_client_manager_get_server_state_completed)func_data->callback; + + callback(result, out_state, func_data->user_data); + } + + g_free(func_data); +} + +static gboolean _activated_time_elapsed_callback(gpointer user_data) +{ + net_nfc_client_manager_activated callback = + (net_nfc_client_manager_activated)activated_func_data.callback; + + if (timeout_id[1] > 0) { + g_source_remove(timeout_id[1]); + timeout_id[1] = 0; + + callback(is_activated, activated_func_data.user_data); + } + + return false; +} + +static void manager_activated(NetNfcGDbusManager *manager, + gboolean activated, + gpointer user_data) +{ + INFO_MSG(">>> SIGNAL arrived"); + DEBUG_CLIENT_MSG("activated %d", activated); + + /* update current state */ + is_activated = (int)activated; + + if (activated_func_data.callback != NULL) + { + if (is_activated == false) { + /* FIXME : wait several times */ + timeout_id[1] = g_timeout_add(DEACTIVATE_DELAY, + _activated_time_elapsed_callback, + NULL); + } else { + timeout_id[1] = g_timeout_add(ACTIVATE_DELAY, + _activated_time_elapsed_callback, + NULL); + } + } +} + +NET_NFC_EXPORT_API +void net_nfc_client_manager_set_activated( + net_nfc_client_manager_activated callback, + void *user_data) +{ + if (callback == NULL) + return; + + if (manager_proxy == NULL) + { + if (net_nfc_client_manager_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("manager_proxy fail"); + /* FIXME : return result of this error */ + return; + } + } + + activated_func_data.callback = callback; + activated_func_data.user_data = user_data; +} + +NET_NFC_EXPORT_API +void net_nfc_client_manager_unset_activated(void) +{ + activated_func_data.callback = NULL; + activated_func_data.user_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 (auto_start_proxy == NULL) { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + /* allow this function even nfc is off */ + + func_data = g_try_new0(ManagerFuncData, 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_manager_call_set_active(auto_start_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) +{ + net_nfc_error_e out_result = NET_NFC_OK; + GError *error = NULL; + + if (auto_start_proxy == NULL) { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + /* allow this function even nfc is off */ + + if (net_nfc_gdbus_manager_call_set_active_sync(auto_start_proxy, + (gboolean)state, + net_nfc_client_gdbus_get_privilege(), + &out_result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("can not call SetActive: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return out_result; +} + +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) +{ + NetNfcCallback *func_data; + + if (manager_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_NOT_ACTIVATED; + } + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) + return NET_NFC_ALLOC_FAIL; + + 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) +{ + net_nfc_error_e out_result = NET_NFC_OK; + guint out_state = 0; + GError *error = NULL; + + if (state == NULL) + return NET_NFC_NULL_PARAMETER; + + *state = 0; + + if (manager_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_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_manager_call_get_server_state_sync(manager_proxy, + net_nfc_client_gdbus_get_privilege(), + &out_result, + &out_state, + NULL, + &error) == TRUE) + { + *state = out_state; + } + else + { + DEBUG_ERR_MSG("can not call GetServerState: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return out_result; + +} + +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_DO_NOT_AUTO_START, + "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) + { + int i; + + for (i = 0; i < 2; i++) { + if (timeout_id[i] > 0) { + g_source_remove(timeout_id[i]); + timeout_id[i] = 0; + } + } + + g_object_unref(manager_proxy); + manager_proxy = NULL; + } + + if (auto_start_proxy) { + g_object_unref(auto_start_proxy); + auto_start_proxy = 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; +} diff --git a/src/clientlib/net_nfc_client_ndef.c b/src/clientlib/net_nfc_client_ndef.c new file mode 100755 index 0000000..404f36d --- /dev/null +++ b/src/clientlib/net_nfc_client_ndef.c @@ -0,0 +1,649 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_util_internal.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 + +static NetNfcGDbusNdef *ndef_proxy = NULL; + +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 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 FALSE; + } + + switch (target_info->devType) + { + case NET_NFC_ISO14443_A_PICC : + case NET_NFC_MIFARE_MINI_PICC : + case NET_NFC_MIFARE_1K_PICC : + case NET_NFC_MIFARE_4K_PICC : + case NET_NFC_MIFARE_ULTRA_PICC : + case NET_NFC_JEWEL_PICC : + 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) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + GVariant *out_data = NULL; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_ndef_call_read_finish( + NET_NFC_GDBUS_NDEF(source_object), + (gint *)&out_result, + &out_data, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish read: %s", error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_ndef_read_completed callback = + (net_nfc_client_ndef_read_completed)func_data->callback; + ndef_message_h message; + + message = net_nfc_util_gdbus_variant_to_ndef_message(out_data); + + callback(out_result, message, func_data->user_data); + + net_nfc_util_free_ndef_message(message); + } + + g_free(func_data); +} + +static void ndef_call_write(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_ndef_call_write_finish( + NET_NFC_GDBUS_NDEF(source_object), + (gint *)&out_result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish write: %s", error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_ndef_write_completed 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) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_ndef_call_make_read_only_finish( + NET_NFC_GDBUS_NDEF(source_object), + (gint *)&out_result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish make read only: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_ndef_make_read_only_completed 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) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_ndef_call_format_finish( + NET_NFC_GDBUS_NDEF(source_object), + (gint *)&out_result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish format: %s", error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_ndef_format_completed 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) +{ + NetNfcCallback *func_data; + + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (ndef_proxy == NULL) + { + if(net_nfc_client_ndef_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("tag_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_client_tag_is_connected() == FALSE) + return NET_NFC_NOT_CONNECTED; + + DEBUG_CLIENT_MSG("send request :: read ndef = [%p]", handle); + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) { + return NET_NFC_ALLOC_FAIL; + } + + 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) +{ + net_nfc_error_e out_result = NET_NFC_OK; + GVariant *out_data = NULL; + GError *error = NULL; + + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (ndef_proxy == NULL) + { + if(net_nfc_client_ndef_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("tag_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_client_tag_is_connected() == FALSE) + return NET_NFC_NOT_CONNECTED; + + DEBUG_CLIENT_MSG("send request :: read ndef = [%p]", handle); + + 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) == TRUE) { + *message = net_nfc_util_gdbus_variant_to_ndef_message(out_data); + } else { + DEBUG_ERR_MSG("can not call read: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + 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) +{ + NetNfcCallback *func_data; + GVariant *arg_data; + + if (handle == NULL || message == NULL) + return NET_NFC_NULL_PARAMETER; + + if (ndef_proxy == NULL) + { + if(net_nfc_client_ndef_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("tag_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_client_tag_is_connected() == FALSE) + return NET_NFC_NOT_CONNECTED; + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) { + return NET_NFC_ALLOC_FAIL; + } + + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; + + arg_data = net_nfc_util_gdbus_ndef_message_to_variant(message); + + 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) +{ + net_nfc_error_e out_result = NET_NFC_OK; + GError *error = NULL; + GVariant *arg_data; + + if (handle == NULL || message == NULL) + return NET_NFC_NULL_PARAMETER; + + if (ndef_proxy == NULL) + { + if(net_nfc_client_ndef_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("tag_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_client_tag_is_connected() == FALSE) + return NET_NFC_NOT_CONNECTED; + + arg_data = net_nfc_util_gdbus_ndef_message_to_variant(message); + + 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); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(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) +{ + NetNfcCallback *func_data; + + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (ndef_proxy == NULL) + { + if(net_nfc_client_ndef_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("tag_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_client_tag_is_connected() == FALSE) + return NET_NFC_NOT_CONNECTED; + + if (ndef_is_supported_tag() == FALSE) + return NET_NFC_NOT_SUPPORTED; + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) { + return NET_NFC_ALLOC_FAIL; + } + + 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) +{ + net_nfc_error_e out_result = NET_NFC_OK; + GError *error = NULL; + + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (ndef_proxy == NULL) + { + if(net_nfc_client_ndef_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("tag_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_client_tag_is_connected() == FALSE) + return NET_NFC_NOT_CONNECTED; + + 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); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(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) +{ + NetNfcCallback *func_data; + GVariant *arg_data; + + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (ndef_proxy == NULL) + { + if(net_nfc_client_ndef_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("tag_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_client_tag_is_connected() == FALSE) + return NET_NFC_NOT_CONNECTED; + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) { + return NET_NFC_ALLOC_FAIL; + } + + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; + + arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)key); + + 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) +{ + net_nfc_error_e out_result = NET_NFC_OK; + GVariant *arg_data; + GError *error = NULL; + + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (ndef_proxy == NULL) + { + if(net_nfc_client_ndef_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("tag_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_client_tag_is_connected() == FALSE) + return NET_NFC_NOT_CONNECTED; + + arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)key); + + 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); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(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_DO_NOT_AUTO_START, + "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; + } +} diff --git a/src/clientlib/net_nfc_client_ndef_message.c b/src/clientlib/net_nfc_client_ndef_message.c old mode 100644 new mode 100755 index f8268a0..d8e3f74 --- a/src/clientlib/net_nfc_client_ndef_message.c +++ b/src/clientlib/net_nfc_client_ndef_message.c @@ -14,159 +14,209 @@ * limitations under the License. */ -#include "net_nfc_debug_private.h" -#include "net_nfc_util_private.h" -#include "net_nfc_util_ndef_message.h" +#include +#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.h" // to use net_nfc_data +#include "net_nfc_data.h" + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif #ifndef NET_NFC_MANAGER_DATA_PATH -#define NET_NFC_MANAGER_DATA_PATH "/opt/data/nfc-manager-daemon" +#define NET_NFC_MANAGER_DATA_PATH "/opt/usr/share/nfc-manager-daemon" #endif #ifndef NET_NFC_MANAGER_DATA_PATH_MESSAGE -#define NET_NFC_MANAGER_DATA_PATH_MESSAGE "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"))) +#define NET_NFC_MANAGER_NDEF_FILE_NAME "ndef-message.txt" #endif /* public functions */ -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_message (ndef_message_h* ndef_message) +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); + 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) +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 tmp_data; + data_h data; - if (ndef_message == NULL || rawdata == NULL){ + if (ndef_message == NULL || rawdata == NULL) { return NET_NFC_NULL_PARAMETER; } - result = net_nfc_get_ndef_message_byte_length(ndef_message,&count); - if (result != NET_NFC_OK){ - return result; - } + *rawdata = NULL; - result = net_nfc_create_data(&tmp_data ,NULL, count); + result = net_nfc_get_ndef_message_byte_length(ndef_message, &count); if (result != NET_NFC_OK) { return result; } - result = net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s*)ndef_message, (data_s*)tmp_data); + result = net_nfc_create_data(&data ,NULL, count); if (result != NET_NFC_OK) { - net_nfc_free_data(tmp_data); return result; } - *rawdata = tmp_data; + 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_EXPORT_API +net_nfc_error_e net_nfc_create_ndef_message_from_rawdata( + ndef_message_h *ndef_message, data_h rawdata) { - if (ndef_message == NULL || rawdata == NULL ){ + net_nfc_error_e result; + ndef_message_h msg; + + if (ndef_message == NULL || rawdata == NULL) { return NET_NFC_NULL_PARAMETER; } - net_nfc_error_e result; - result = net_nfc_create_ndef_message (ndef_message); - if (result != NET_NFC_OK){ + *ndef_message = NULL; + + result = net_nfc_create_ndef_message(&msg); + if (result != NET_NFC_OK) { return result; } - return net_nfc_util_convert_rawdata_to_ndef_message((data_s*)rawdata, (ndef_message_s*)*ndef_message); -} + 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_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); - return NET_NFC_OK; + *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) +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){ + 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); + 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) +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message) { - if (ndef_message == NULL){ + if (ndef_message == NULL) { return NET_NFC_NULL_PARAMETER; } - net_nfc_error_e error = net_nfc_util_free_ndef_message((ndef_message_s *)ndef_message); - if (error != NET_NFC_OK){ - return error; - } - return error; + + 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) +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){ + ndef_message_s *msg = (ndef_message_s *)ndef_message; + + if (ndef_message == NULL || count == NULL) { return NET_NFC_NULL_PARAMETER; } - ndef_message_s * ndef_message_private = (ndef_message_s *)ndef_message; - * count = ndef_message_private->recordCount; + *count = msg->recordCount; return NET_NFC_OK; } -NET_NFC_EXPORT_API void net_nfc_ndef_print_message (ndef_message_h ndef_message ) +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_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) +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); + 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) +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); + 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) +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); + 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) +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); + 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_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, }; + char file_path[PATH_MAX] = { 0, }; FILE *fp = NULL; if (ndef_message == NULL) @@ -174,7 +224,10 @@ NET_NFC_EXPORT_API net_nfc_error_e net_nfc_retrieve_current_ndef_message(ndef_me 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); + 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) { @@ -189,29 +242,39 @@ NET_NFC_EXPORT_API net_nfc_error_e net_nfc_retrieve_current_ndef_message(ndef_me if (size > 0) { - uint8_t *buffer = NULL; + data_s data = { NULL, 0 }; - _net_nfc_util_alloc_mem(buffer, size); - if (buffer != NULL) + if (net_nfc_util_init_data(&data, size) == true) { + int current; + size_t offset = 0; + /* 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); - } + do { + current = fread(data.buffer + offset, 1, + data.length - offset, fp); + if (current > 0) + offset += current; + else + break; + } while (offset < data.length); + + if (offset == data.length) { + result = net_nfc_create_ndef_message_from_rawdata(ndef_message, &data); + } else { + DEBUG_ERR_MSG("failed to read ndef message"); } - _net_nfc_util_free_mem(buffer); + net_nfc_util_clear_data(&data); + } + else + { + result = NET_NFC_ALLOC_FAIL; } } else { - result = NET_NFC_ALLOC_FAIL; + result = NET_NFC_NO_NDEF_MESSAGE; } fclose(fp); diff --git a/src/clientlib/net_nfc_client_ndef_message_handover.c b/src/clientlib/net_nfc_client_ndef_message_handover.c new file mode 100755 index 0000000..1b90231 --- /dev/null +++ b/src/clientlib/net_nfc_client_ndef_message_handover.c @@ -0,0 +1,371 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_internal.h" +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_util_handover.h" +#include "net_nfc_ndef_message_handover.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_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, uint16_t attribute, + net_nfc_property_group_h *group) +{ + return net_nfc_util_get_carrier_config_group( + (net_nfc_carrier_config_s *)config, attribute, + (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_create_carrier_config_from_carrier( + net_nfc_carrier_config_h *config, net_nfc_ch_carrier_h carrier) +{ + return net_nfc_util_create_carrier_config_from_carrier( + (net_nfc_carrier_config_s **)config, (net_nfc_ch_carrier_s *)carrier); + +} + + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_create_handover_carrier(net_nfc_ch_carrier_h *carrier, + net_nfc_conn_handover_carrier_state_e cps) +{ + return net_nfc_util_create_handover_carrier( + (net_nfc_ch_carrier_s **)carrier, cps); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_duplicate_handover_carrier(net_nfc_ch_carrier_h *dest, + net_nfc_ch_carrier_h src) +{ + return net_nfc_util_duplicate_handover_carrier( + (net_nfc_ch_carrier_s **)dest, + (net_nfc_ch_carrier_s *)src); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_free_handover_carrier(net_nfc_ch_carrier_h carrier) +{ + return net_nfc_util_free_handover_carrier( + (net_nfc_ch_carrier_s *)carrier); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_set_handover_carrier_cps( + net_nfc_ch_carrier_h carrier, + net_nfc_conn_handover_carrier_state_e cps) +{ + return net_nfc_util_set_handover_carrier_cps( + (net_nfc_ch_carrier_s *)carrier, cps); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_handover_carrier_cps( + net_nfc_ch_carrier_h carrier, + net_nfc_conn_handover_carrier_state_e *cps) +{ + return net_nfc_util_get_handover_carrier_cps( + (net_nfc_ch_carrier_s *)carrier, cps); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_set_handover_carrier_type( + net_nfc_ch_carrier_h carrier, + net_nfc_conn_handover_carrier_type_e type) +{ + return net_nfc_util_set_handover_carrier_type( + (net_nfc_ch_carrier_s *)carrier, type); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_handover_carrier_type( + net_nfc_ch_carrier_h carrier, + net_nfc_conn_handover_carrier_type_e *type) +{ + return net_nfc_util_get_handover_carrier_type( + (net_nfc_ch_carrier_s *)carrier, type); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_append_handover_carrier_record( + net_nfc_ch_carrier_h carrier, ndef_record_h record) +{ + return net_nfc_util_append_handover_carrier_record( + (net_nfc_ch_carrier_s *)carrier, (ndef_record_s *)record); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_handover_carrier_record( + net_nfc_ch_carrier_h carrier, ndef_record_h *record) +{ + return net_nfc_util_get_handover_carrier_record( + (net_nfc_ch_carrier_s *)carrier, (ndef_record_s **)record); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_remove_handover_carrier_record( + net_nfc_ch_carrier_h carrier) +{ + return net_nfc_util_remove_handover_carrier_record( + (net_nfc_ch_carrier_s *)carrier); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_append_handover_auxiliary_record( + net_nfc_ch_carrier_h carrier, ndef_record_h record) +{ + return net_nfc_util_append_handover_auxiliary_record( + (net_nfc_ch_carrier_s *)carrier, (ndef_record_s *)record); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_handover_auxiliary_record_count( + net_nfc_ch_carrier_h carrier, uint32_t *count) +{ + return net_nfc_util_get_handover_auxiliary_record_count( + (net_nfc_ch_carrier_s *)carrier, count); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_handover_auxiliary_record( + net_nfc_ch_carrier_h carrier, int index, ndef_record_h *record) +{ + return net_nfc_util_get_handover_auxiliary_record( + (net_nfc_ch_carrier_s *)carrier, index, (ndef_record_s **)record); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_remove_handover_auxiliary_record( + net_nfc_ch_carrier_h carrier, ndef_record_h record) +{ + return net_nfc_util_remove_handover_auxiliary_record( + (net_nfc_ch_carrier_s *)carrier, (ndef_record_s *)record); +} + + + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_create_handover_message( + net_nfc_ch_message_h *message) +{ + return net_nfc_util_create_handover_message( + (net_nfc_ch_message_s **)message); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_free_handover_message( + net_nfc_ch_message_h message) +{ + return net_nfc_util_free_handover_message( + (net_nfc_ch_message_s *)message); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_handover_random_number( + net_nfc_ch_message_h message, uint16_t *random_number) +{ + return net_nfc_util_get_handover_random_number( + (net_nfc_ch_message_s *)message, random_number); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_append_handover_carrier( + net_nfc_ch_message_h message, net_nfc_ch_carrier_h carrier) +{ + return net_nfc_util_append_handover_carrier( + (net_nfc_ch_message_s *)message, + (net_nfc_ch_carrier_s *)carrier); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_handover_carrier_count( + net_nfc_ch_message_h message, uint32_t *count) +{ + return net_nfc_util_get_handover_carrier_count( + (net_nfc_ch_message_s *)message, count); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_handover_carrier( + net_nfc_ch_message_h message, int index, + net_nfc_ch_carrier_h *carrier) +{ + return net_nfc_util_get_handover_carrier( + (net_nfc_ch_message_s *)message, index, + (net_nfc_ch_carrier_s **)carrier); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_handover_carrier_by_type( + net_nfc_ch_message_h message, + net_nfc_conn_handover_carrier_type_e type, + net_nfc_ch_carrier_h *carrier) +{ + return net_nfc_util_get_handover_carrier_by_type( + (net_nfc_ch_message_s *)message, type, + (net_nfc_ch_carrier_s **)carrier); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_export_handover_to_ndef_message( + net_nfc_ch_message_h message, ndef_message_h *result) +{ + return net_nfc_util_export_handover_to_ndef_message( + (net_nfc_ch_message_s *)message, (ndef_message_s **)result); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_import_handover_from_ndef_message( + ndef_message_h msg, net_nfc_ch_message_h *result) +{ + return net_nfc_util_import_handover_from_ndef_message( + (ndef_message_s *)msg, (net_nfc_ch_message_s **)result); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_create_handover_error_record(ndef_record_h *record, uint8_t reason, uint32_t data) +{ + return net_nfc_util_create_handover_error_record((ndef_record_s **)record, reason, data); +} diff --git a/src/clientlib/net_nfc_client_ndef_record.c b/src/clientlib/net_nfc_client_ndef_record.c old mode 100644 new mode 100755 index df6cd88..9079710 --- a/src/clientlib/net_nfc_client_ndef_record.c +++ b/src/clientlib/net_nfc_client_ndef_record.c @@ -17,110 +17,131 @@ #include "net_nfc_ndef_record.h" #include "net_nfc_ndef_message.h" #include "net_nfc_data.h" -#include "net_nfc_debug_private.h" -#include "net_nfc_util_private.h" +#include "net_nfc_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) +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); + 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) +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); + 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) +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); + 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) +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); + 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) +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_record_payload(ndef_record_h record, + data_h *payload) { + ndef_record_s *struct_record = (ndef_record_s *)record; + 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) +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_record_type(ndef_record_h record, data_h *type) { + ndef_record_s *struct_record = (ndef_record_s *)record; + 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) +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_record_id(ndef_record_h record, data_h *id) { + ndef_record_s *struct_record = (ndef_record_s *)record; + 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) +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_record_tnf(ndef_record_h record, + net_nfc_record_tnf_e *TNF) { + ndef_record_s *struct_record = (ndef_record_s *)record; + 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) +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_set_record_id(ndef_record_h record, data_h id) { + data_s *tmp_id = (data_s *)id; - ndef_record_s * record_private = (ndef_record_s *)record; - data_s * id_private = (data_s *)id; - - if (id_private == NULL) + if (record == NULL || tmp_id == NULL) { return NET_NFC_NULL_PARAMETER; } - return net_nfc_util_set_record_id(record_private, id_private->buffer, id_private->length); + + return net_nfc_util_set_record_id((ndef_record_s *)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) +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_record_flags(ndef_record_h record, uint8_t *flag) { + ndef_record_s *struct_record = (ndef_record_s *)record; + 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; @@ -138,148 +159,169 @@ NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_flags(ndef_record_h record NET_NFC_EXPORT_API uint8_t net_nfc_get_record_mb(uint8_t flag) { - return (flag & 0x80) >> 7; + return ((flag >> 7) & 0x01); } NET_NFC_EXPORT_API uint8_t net_nfc_get_record_me(uint8_t flag) { - return (flag & 0x40) >> 6; + return ((flag >> 6) & 0x01); } NET_NFC_EXPORT_API uint8_t net_nfc_get_record_cf(uint8_t flag) { - return (flag & 0x20) >> 5; + 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 & 0x10) >> 4; + return ((flag >> 3) & 0x01); } -NET_NFC_EXPORT_API uint8_t net_nfc_get_record_sr(uint8_t flag) +static bool _is_text_record(ndef_record_h record) { - return (flag & 0x08) >> 3; + bool result = false; + data_h type; + + if ((net_nfc_get_record_type(record, &type) == NET_NFC_OK) && + (strncmp((char *)net_nfc_get_data_buffer(type), + TEXT_RECORD_TYPE, + net_nfc_get_data_length(type)) == 0)) + result = true; + + return result; } -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer) +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_create_text_string_from_text_record( + ndef_record_h record, char **buffer) { + net_nfc_error_e result; + data_h payload; + if (record == NULL || buffer == NULL) - return NET_NFC_ALLOC_FAIL; + { + return NET_NFC_NULL_PARAMETER; + } - data_h payload; - data_h rec_type; + *buffer = NULL; - if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK) + if (_is_text_record(record) == false) { - 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; - } + DEBUG_ERR_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) + result = net_nfc_get_record_payload(record, &payload); + if (result == NET_NFC_OK) { - uint8_t *buffer_temp; + uint8_t *buffer_temp = net_nfc_get_data_buffer(payload); uint32_t buffer_length = net_nfc_get_data_length(payload); - buffer_temp = net_nfc_get_data_buffer(payload); - if (NULL == buffer_temp) - return NET_NFC_NO_DATA_FOUND; - 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) + char *temp = NULL; + + _net_nfc_util_alloc_mem(temp, text_length + 1); + if (temp != NULL) { - memcpy(*buffer, &(buffer_temp[index]), text_length); - DEBUG_CLIENT_MSG("text = [%s]", *buffer); + memcpy(temp, &(buffer_temp[index]), text_length); + + DEBUG_CLIENT_MSG("text = [%s]", temp); + + *buffer = temp; } else { - return NET_NFC_ALLOC_FAIL; + result = NET_NFC_ALLOC_FAIL; } } - return NET_NFC_OK; + return result; } -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) +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) { + net_nfc_error_e result; + data_h payload; + if (record == NULL || lang_code_str == NULL) { - return NET_NFC_ALLOC_FAIL; + return NET_NFC_NULL_PARAMETER; } - data_h payload; - data_h rec_type; + *lang_code_str = NULL; - if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK) + if (_is_text_record(record) == false) { - 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; - } + DEBUG_ERR_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) + result = net_nfc_get_record_payload(record, &payload); + if (result == NET_NFC_OK) { + uint8_t *buffer_temp = net_nfc_get_data_buffer(payload); char *buffer = NULL; - uint8_t *buffer_temp; - - buffer_temp = net_nfc_get_data_buffer(payload); - if (NULL == buffer_temp) - return NET_NFC_NO_DATA_FOUND; int controllbyte = buffer_temp[0]; int lang_code_length = controllbyte & 0x3F; int index = 1; - if ((buffer = (char *)calloc(1, lang_code_length + 1)) != NULL) + _net_nfc_util_alloc_mem(buffer, lang_code_length + 1); + if (buffer != 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; + result = NET_NFC_ALLOC_FAIL; } } - return NET_NFC_OK; + return result; } -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) +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) { + net_nfc_error_e result; + data_h payload; + if (record == NULL || encoding == NULL) { return NET_NFC_NULL_PARAMETER; } - data_h payload; - data_h rec_type; + *encoding = NET_NFC_ENCODE_UTF_8; - if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK) + if (_is_text_record(record) == false) { - 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; - } + DEBUG_ERR_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) + result = net_nfc_get_record_payload(record, &payload); + if (result == NET_NFC_OK) { - uint8_t *buffer_temp; - - buffer_temp = net_nfc_get_data_buffer(payload); - if (NULL == buffer_temp) - return NET_NFC_NO_DATA_FOUND; + uint8_t *buffer_temp = net_nfc_get_data_buffer(payload); int controllbyte = buffer_temp[0]; @@ -287,16 +329,15 @@ NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_encoding_type_from_text_record(nd { *encoding = NET_NFC_ENCODE_UTF_16; } - else - { - *encoding = NET_NFC_ENCODE_UTF_8; - } } - return NET_NFC_OK; + return result; } -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char **uri) +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); + return net_nfc_util_create_uri_string_from_uri_record( + (ndef_record_s *)record, uri); } diff --git a/src/clientlib/net_nfc_client_p2p.c b/src/clientlib/net_nfc_client_p2p.c new file mode 100755 index 0000000..e7536e2 --- /dev/null +++ b/src/clientlib/net_nfc_client_p2p.c @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_util_internal.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 _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; + +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.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.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.p2p_data_received_cb) + { + data_s p2p_data = { NULL, }; + + 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_clear_data(&p2p_data); + } +} + +static void p2p_call_send(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_p2p_call_send_finish( + NET_NFC_GDBUS_P2P(source_object), + (gint *)&out_result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish p2p send: %s", error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_p2p_send_completed callback = + (net_nfc_client_p2p_send_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_p2p_send(net_nfc_target_handle_h handle, + data_h data, + net_nfc_client_p2p_send_completed callback, + void *user_data) +{ + GVariant *arg_data; + NetNfcCallback *func_data; + + if (p2p_proxy == NULL) + { + DEBUG_ERR_MSG("Can not get P2pProxy"); + + return NET_NFC_NOT_INITIALIZED; + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) { + return NET_NFC_ALLOC_FAIL; + } + + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; + + arg_data = net_nfc_util_gdbus_data_to_variant(data); + + net_nfc_gdbus_p2p_call_send(p2p_proxy, + 0 /* FIXME */, + 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_target_handle_h handle, + data_h data) +{ + GVariant *arg_data; + GError *error = NULL; + + net_nfc_error_e out_result; + + if (p2p_proxy == NULL) + { + DEBUG_ERR_MSG("Can not get P2pProxy"); + + return NET_NFC_NOT_INITIALIZED; + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + arg_data = net_nfc_util_gdbus_data_to_variant(data); + + if (net_nfc_gdbus_p2p_call_send_sync(p2p_proxy, + 0 /* FIXME */, + 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); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(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 (callback == NULL) + return; + + if (p2p_proxy == NULL) + { + if (net_nfc_client_p2p_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("P2pProxy fail"); + /* FIXME : return result of this error */ + return; + } + } + + 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 (callback == NULL) + return; + + if (p2p_proxy == NULL) + { + if (net_nfc_client_p2p_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("P2pProxy fail"); + /* FIXME : return result of this error */ + return; + } + } + + 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 (callback == NULL) + return; + + if (p2p_proxy == NULL) + { + if (net_nfc_client_p2p_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("P2pProxy fail"); + /* FIXME : return result of this error */ + return; + } + } + + 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) +{ + p2p_signal_handler.p2p_device_discovered_cb = NULL; + p2p_signal_handler.p2p_device_discovered_data = NULL; +} + + +NET_NFC_EXPORT_API +void net_nfc_client_p2p_unset_device_detached(void) +{ + 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) +{ + 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_DO_NOT_AUTO_START, + "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; + } + + /* FIXME : set timeout to infinite */ + g_dbus_proxy_set_default_timeout(G_DBUS_PROXY(p2p_proxy), G_MAXINT32); + + 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; + } +} diff --git a/src/clientlib/net_nfc_client_se.c b/src/clientlib/net_nfc_client_se.c new file mode 100755 index 0000000..3d5de82 --- /dev/null +++ b/src/clientlib/net_nfc_client_se.c @@ -0,0 +1,1818 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_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_util_internal.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 transaction_event_cb; + gpointer 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 NetNfcGDbusSecureElement *auto_start_proxy = NULL; + +static SeEventHandler se_eventhandler; +static SeTransEventHandler uicc_transactionEventHandler; +static SeTransEventHandler ese_transactionEventHandler; +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_rf_detected(GObject *source_object, + gint arg_se_type, + GVariant *arg_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_clear_data(&buffer_data); + } +} + +static void se_rf_detected(GObject *source_object, + gint arg_se_type, + GVariant *arg_data) +{ + + 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)NET_NFC_MESSAGE_SE_FIELD_ON, + se_eventhandler.se_event_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)NET_NFC_MESSAGE_SE_TYPE_CHANGED, + se_eventhandler.se_event_data); + } +} + + +static void se_transaction_event(GObject *source_object, + gint arg_se_type, + GVariant *arg_aid, + GVariant *arg_param, + gint fg_dispatch, + gint focus_app_pid) +{ + void *user_data = NULL; + net_nfc_client_se_transaction_event callback = NULL; + GError *error = NULL; + gint result = 0; + pid_t mypid = getpid(); + + INFO_MSG(">>> SIGNAL arrived"); + + if (fg_dispatch == true && focus_app_pid != getpgid(mypid)) { + DEBUG_MSG("skip transaction event, fg_dispatch [%d], focus_app_pid [%d]", fg_dispatch, focus_app_pid); + return; + } + + if (net_nfc_gdbus_secure_element_call_check_transaction_permission_sync( + NET_NFC_GDBUS_SECURE_ELEMENT(source_object), + arg_aid, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == false) { + DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_check_transaction_permission_sync failed : %s", error->message); + g_error_free(error); + return; + } + + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("not allowed process [%d]", result); + return; + } + + switch (arg_se_type) + { + case NET_NFC_SE_TYPE_UICC : + if (uicc_transactionEventHandler.transaction_event_cb != NULL) + { + callback = uicc_transactionEventHandler.transaction_event_cb; + user_data = uicc_transactionEventHandler.transaction_event_data; + } + break; + + case NET_NFC_SE_TYPE_ESE : + if (ese_transactionEventHandler.transaction_event_cb != NULL) + { + callback = ese_transactionEventHandler.transaction_event_cb; + user_data = ese_transactionEventHandler.transaction_event_data; + } + break; + + default : + DEBUG_ERR_MSG("Transaction event SE type wrong [%d]", arg_se_type); + break; + } + + if (callback != NULL) { + 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(arg_se_type, &aid, ¶m, user_data); + + net_nfc_util_clear_data(¶m); + net_nfc_util_clear_data(&aid); + } +} + +static void se_card_emulation_mode_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)NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED, + se_eventhandler.se_event_data); + } +} + +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) + { + + DEBUG_ERR_MSG("Could not set secure element: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + 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; + guint out_handle = 0; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_secure_element_call_open_secure_element_finish( + auto_start_proxy, + &result, + &out_handle, + res, + &error) == FALSE) + { + + DEBUG_ERR_MSG("Could not open secure element: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + 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) + { + DEBUG_ERR_MSG("Could not close secure element: %s", error->message); + result = NET_NFC_IPC_FAIL; + + 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 = NULL; + 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) + { + DEBUG_ERR_MSG("Could not send apdu: %s", error->message); + result = NET_NFC_IPC_FAIL; + + 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_clear_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 = NULL; + 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) + { + DEBUG_ERR_MSG("Could not get atr: %s", error->message); + result = NET_NFC_IPC_FAIL; + + 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_clear_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) + { + if (net_nfc_client_se_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("se_proxy fail"); + /* FIXME : return result of this error */ + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_try_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 = NET_NFC_OK; + GError *error = NULL; + + if (se_proxy == NULL) + { + if (net_nfc_client_se_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("se_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + 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); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_get_secure_element_type_sync( + net_nfc_se_type_e *se_type) +{ + net_nfc_error_e result = NET_NFC_OK; + gint type; +#if 1 + GError *error = NULL; +#endif + if (se_proxy == NULL) + { + if (net_nfc_client_se_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("se_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } +#if 0 + if (vconf_get_int(VCONFKEY_NFC_SE_TYPE, &type) == 0) { + *se_type = type; + } else { + result = NET_NFC_OPERATION_FAIL; + } +#else + if (net_nfc_gdbus_secure_element_call_get_sync( + se_proxy, + net_nfc_client_gdbus_get_privilege(), + &result, + &type, + NULL, + &error) == true) { + + DEBUG_CLIENT_MSG("type [%d]", type); + *se_type = type; + } else { + DEBUG_ERR_MSG("get secure element failed: %s", error->message); + + g_error_free(error); + + result = NET_NFC_IPC_FAIL; + } +#endif + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_set_card_emulation_mode_sync( + net_nfc_card_emulation_mode_t mode) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (se_proxy == NULL) + { + if (net_nfc_client_se_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("se_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_secure_element_call_set_card_emulation_sync( + se_proxy, + (gint)mode, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("Set card emulation failed: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_card_emulation_mode_sync( + net_nfc_card_emulation_mode_t *se_type) +{ + net_nfc_error_e result = NET_NFC_OK; + gint type; + GError *error = NULL; + + if (se_proxy == NULL) + { + if (net_nfc_client_se_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("se_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_secure_element_call_get_card_emulation_sync( + se_proxy, + net_nfc_client_gdbus_get_privilege(), + &result, + &type, + NULL, + &error) == true) { + *se_type = type; + } else { + DEBUG_ERR_MSG("get 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 (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + /* allow this function even nfc is off */ + + func_data = g_try_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( + auto_start_proxy, + (gint)se_type, + net_nfc_client_gdbus_get_privilege(), + NULL, + open_secure_element, + func_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 = NET_NFC_OK; + guint out_handle = 0; + GError *error = NULL; + + if (handle == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + /* allow this function even nfc is off */ + + if (net_nfc_gdbus_secure_element_call_open_secure_element_sync( + auto_start_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); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + 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 (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + /* allow this function even nfc is off */ + + func_data = g_try_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( + auto_start_proxy, + GPOINTER_TO_UINT(handle), + net_nfc_client_gdbus_get_privilege(), + NULL, + close_secure_element, + func_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 = NET_NFC_OK; + GError *error = NULL; + + if (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + /* allow this function even nfc is off */ + + if (net_nfc_gdbus_secure_element_call_close_secure_element_sync( + auto_start_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); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + 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 (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + /* allow this function even nfc is off */ + + func_data = g_try_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( + auto_start_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 = NET_NFC_OK; + GVariant *out_atr = NULL; + GError *error = NULL; + + if (atr == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + *atr = NULL; + + if (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + /* allow this function even nfc is off */ + + if (net_nfc_gdbus_secure_element_call_get_atr_sync( + auto_start_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); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + 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 (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + /* 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_try_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( + auto_start_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 = NET_NFC_OK; + GVariant *out_data = NULL; + GError *error = NULL; + GVariant *arg_data; + + if (response == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + *response = NULL; + + if (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + /* 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( + auto_start_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); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + 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) +{ + if (se_proxy == NULL) + { + if (net_nfc_client_se_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("se_proxy fail"); + /* FIXME : return result of this error */ + return; + } + } + + 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) +{ + se_esedetecthandler.se_ese_detected_cb = NULL; + se_esedetecthandler.se_ese_detected_data = NULL; +} + + +NET_NFC_EXPORT_API +void net_nfc_client_se_set_transaction_event_cb( + net_nfc_se_type_e se_type, + net_nfc_client_se_transaction_event callback, + void *user_data) +{ + if (se_proxy == NULL) + { + if (net_nfc_client_se_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("se_proxy fail"); + /* FIXME : return result of this error */ + return; + } + } + + if (se_type == NET_NFC_SE_TYPE_ESE) + { + ese_transactionEventHandler.transaction_event_cb = callback; + ese_transactionEventHandler.transaction_event_data = user_data; + } + else if (se_type == NET_NFC_SE_TYPE_UICC) + { + uicc_transactionEventHandler.transaction_event_cb = callback; + uicc_transactionEventHandler.transaction_event_data = user_data; + } +} + + +NET_NFC_EXPORT_API +void net_nfc_client_se_unset_transaction_event_cb(net_nfc_se_type_e type) +{ + if (type == NET_NFC_SE_TYPE_ESE) + { + ese_transactionEventHandler.transaction_event_cb = NULL; + ese_transactionEventHandler.transaction_event_data = NULL; + } + else if (type == NET_NFC_SE_TYPE_UICC) + { + uicc_transactionEventHandler.transaction_event_cb = NULL; + uicc_transactionEventHandler.transaction_event_data = NULL; + } +} + +NET_NFC_EXPORT_API +void net_nfc_client_se_set_event_cb(net_nfc_client_se_event callback, + void *user_data) +{ + if (se_proxy == NULL) + { + if (net_nfc_client_se_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("se_proxy fail"); + /* FIXME : return result of this error */ + return; + } + } + + 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) +{ + se_eventhandler.se_event_cb = NULL; + se_eventhandler.se_event_data = NULL; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_set_transaction_fg_dispatch(int mode) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + if (net_nfc_gdbus_secure_element_call_set_transaction_fg_dispatch_sync( + auto_start_proxy, + mode, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) != true) { + + DEBUG_ERR_MSG("set transaction fg dispatch failed: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_set_default_route_sync( + net_nfc_se_type_e switch_on, + net_nfc_se_type_e switch_off, + net_nfc_se_type_e battery_off) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (se_proxy == NULL) + { + result = net_nfc_client_se_init(); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result); + + return NET_NFC_NOT_INITIALIZED; + } + } + + if (net_nfc_gdbus_secure_element_call_set_default_route_sync( + se_proxy, + switch_on, + switch_off, + battery_off, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("Set Route Aid failed: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + DEBUG_CLIENT_MSG("net_nfc_gdbus_secure_element_call_set_default_route_sync end"); + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_is_activated_aid_handler_sync( + net_nfc_se_type_e se_type, const char *aid, bool *activated) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + gboolean ret = false; + + if (activated == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (se_proxy == NULL) { + result = net_nfc_client_se_init(); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result); + + return NET_NFC_NOT_INITIALIZED; + } + } + + if (net_nfc_gdbus_secure_element_call_is_activated_aid_handler_sync( + se_proxy, + se_type, + aid, + net_nfc_client_gdbus_get_privilege(), + &result, + &ret, + NULL, + &error) == true) { + *activated = ret; + } else { + DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_is_activated_aid_handler_sync failed : %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_is_activated_category_handler_sync( + net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, bool *activated) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + gboolean ret = false; + + if (activated == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (se_proxy == NULL) { + result = net_nfc_client_se_init(); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result); + + return NET_NFC_NOT_INITIALIZED; + } + } + + if (net_nfc_gdbus_secure_element_call_is_activated_category_handler_sync( + se_proxy, + se_type, + category, + net_nfc_client_gdbus_get_privilege(), + &result, + &ret, + NULL, + &error) == true) { + *activated = ret; + } else { + DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_is_activated_category_handler_sync failed : %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_get_registered_aids_count_sync( + net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + size_t *count) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + GVariant *aids = NULL; + + if (count == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (se_proxy == NULL) { + result = net_nfc_client_se_init(); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result); + + return NET_NFC_NOT_INITIALIZED; + } + } + + if (net_nfc_gdbus_secure_element_call_get_registered_aids_sync( + se_proxy, + se_type, + category, + net_nfc_client_gdbus_get_privilege(), + &result, + &aids, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_registered_aids_sync failed : %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (result == NET_NFC_OK) { + GVariantIter iter; + + g_variant_iter_init(&iter, aids); + + *count = g_variant_iter_n_children(&iter); + + g_variant_unref(aids); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_foreach_registered_aids_sync( + net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + net_nfc_client_se_registered_aid_cb callback, + void *user_data) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + GVariant *aids = NULL; + + if (callback == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (se_proxy == NULL) { + result = net_nfc_client_se_init(); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result); + + return NET_NFC_NOT_INITIALIZED; + } + } + + if (net_nfc_gdbus_secure_element_call_get_registered_aids_sync( + se_proxy, + se_type, + category, + net_nfc_client_gdbus_get_privilege(), + &result, + &aids, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_registered_aids_sync failed : %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (result == NET_NFC_OK) { + GVariantIter iter; + const gchar *aid; + gboolean manifest; + + g_variant_iter_init(&iter, aids); + + while (g_variant_iter_loop(&iter, "(sb)", &aid, &manifest) == true) { + callback(se_type, aid, (bool)manifest, user_data); + } + } + + return result; +} + + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_register_aids_sync(net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, const char *aid, ...) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (se_proxy == NULL) { + result = net_nfc_client_se_init(); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result); + + return NET_NFC_NOT_INITIALIZED; + } + } + + if (net_nfc_gdbus_secure_element_call_register_aid_sync( + se_proxy, + se_type, + category, + aid, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_register_aid_sync failed : %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_unregister_aid_sync(net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, const char *aid) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (se_proxy == NULL) { + result = net_nfc_client_se_init(); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result); + + return NET_NFC_NOT_INITIALIZED; + } + } + + if (net_nfc_gdbus_secure_element_call_unregister_aid_sync( + se_proxy, + se_type, + category, + aid, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_unregister_aid_sync failed : %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_unregister_aids_sync(net_nfc_se_type_e se_type, net_nfc_card_emulation_category_t category) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (se_proxy == NULL) { + result = net_nfc_client_se_init(); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result); + + return NET_NFC_NOT_INITIALIZED; + } + } + + if (net_nfc_gdbus_secure_element_call_unregister_aids_sync( + se_proxy, + se_type, + category, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_unregister_aids_sync failed : %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_foreach_registered_handlers_sync( + net_nfc_card_emulation_category_t category, + net_nfc_client_se_registered_handler_cb callback, + void *user_data) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + GVariant *handlers = NULL; + + if (callback == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (se_proxy == NULL) { + result = net_nfc_client_se_init(); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result); + + return NET_NFC_NOT_INITIALIZED; + } + } + + if (net_nfc_gdbus_secure_element_call_get_registered_handlers_sync( + se_proxy, + category, + net_nfc_client_gdbus_get_privilege(), + &result, + &handlers, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_registered_handlers_sync failed : %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (result == NET_NFC_OK) { + GVariantIter iter; + const gchar *handler; + + g_variant_iter_init(&iter, handlers); + + while (g_variant_iter_loop(&iter, "(s)", &handler) == true) { + callback(handler, user_data); + } + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_add_route_aid_sync( + const char *package, net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, const char *aid, + bool unlock_required, int power) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + if (net_nfc_gdbus_secure_element_call_add_route_aid_sync( + auto_start_proxy, + package, + aid, + se_type, + category, + unlock_required, + power, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("Set Route Aid failed: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + DEBUG_CLIENT_MSG("net_nfc_gdbus_secure_element_call_add_route_aid_sync end"); + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_remove_route_aid_sync( + const char *package, const char *aid) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + if (net_nfc_gdbus_secure_element_call_remove_route_aid_sync( + auto_start_proxy, + package, + aid, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("Remove Route Aid failed: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + DEBUG_CLIENT_MSG("net_nfc_gdbus_hce_call_set_route_aid_sync end"); + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_se_remove_package_aids_sync( + const char *package) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (auto_start_proxy == NULL) + { + GError *error = NULL; + + auto_start_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 (auto_start_proxy == NULL) + { + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; + } + } + + if (net_nfc_gdbus_secure_element_call_remove_package_aids_sync( + auto_start_proxy, + package, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("Remove Package Aid failed: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + DEBUG_CLIENT_MSG("net_nfc_client_se_remove_package_aids_sync end"); + + return result; +} + + +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_DO_NOT_AUTO_START, + "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); + + g_signal_connect(se_proxy, "card-emulation-mode-changed", + G_CALLBACK(se_card_emulation_mode_changed), NULL); + + g_signal_connect(se_proxy, "rf-detected", + G_CALLBACK(se_rf_detected), NULL); + + return NET_NFC_OK; +} + + +void net_nfc_client_se_deinit(void) +{ + if (se_proxy) + { + g_object_unref(se_proxy); + se_proxy = NULL; + } + + if (auto_start_proxy) + { + g_object_unref(auto_start_proxy); + auto_start_proxy = NULL; + } +} diff --git a/src/clientlib/net_nfc_client_sign_record.c b/src/clientlib/net_nfc_client_sign_record.c new file mode 100755 index 0000000..9d93847 --- /dev/null +++ b/src/clientlib/net_nfc_client_sign_record.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "net_nfc_util_sign_record.h" + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_sign_records(ndef_message_h msg, int begin_index, int end_index, char *cert_file, char *password) +{ + return net_nfc_util_sign_records((ndef_message_s *)msg, begin_index, end_index, cert_file, password); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_sign_ndef_message(ndef_message_h msg, char *cert_file, char *password) +{ + return net_nfc_util_sign_ndef_message((ndef_message_s *)msg, cert_file, password); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_verify_signature_ndef_message(ndef_message_h msg) +{ + return net_nfc_util_verify_signature_ndef_message((ndef_message_s *)msg); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_verify_signature_records(ndef_record_h begin_record, ndef_record_h sign_record) +{ + return net_nfc_util_verify_signature_records((ndef_record_s *)begin_record, (ndef_record_s *)sign_record); +} diff --git a/src/clientlib/net_nfc_client_snep.c b/src/clientlib/net_nfc_client_snep.c new file mode 100755 index 0000000..50e8af2 --- /dev/null +++ b/src/clientlib/net_nfc_client_snep.c @@ -0,0 +1,526 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 void snep_send_client_request(GObject *source_object, + GAsyncResult *res, + gpointer user_data); + +/*********************************************************************/ + +static void snep_send_client_request(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GVariant *parameter = (GVariant *)user_data; + net_nfc_error_e out_result; + net_nfc_snep_type_t out_type = NET_NFC_SNEP_GET; + GVariant *out_data = NULL; + GError *error = NULL; + net_nfc_client_snep_event_cb callback; + void *user_param; + net_nfc_snep_handle_h handle; + + g_assert(parameter != NULL); + + 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); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + g_variant_get(parameter, "(uuu)", + (guint *)&callback, + (guint *)&user_param, + (guint *)&handle); + + if (callback != NULL) { + ndef_message_h message; + + message = net_nfc_util_gdbus_variant_to_ndef_message(out_data); + + callback(handle, out_type, out_result, + message, user_param); + + net_nfc_free_ndef_message(message); + } + + g_variant_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_NOT_INITIALIZED; + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + + 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); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + + g_variant_unref(parameter); + } + + 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_NOT_INITIALIZED; + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + + 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); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + + g_variant_unref(parameter); + } + + 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_NOT_ACTIVATED; + } + + parameter = g_variant_new("(uuu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data), + GPOINTER_TO_UINT(target)); + + ndef_msg = net_nfc_util_gdbus_ndef_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 || + resp_type == NULL || response == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *response = NULL; + + if (snep_proxy == NULL) + { + DEBUG_ERR_MSG("Can not get Snep Proxy"); + + return NET_NFC_NOT_INITIALIZED; + } + + arg_msg = net_nfc_util_gdbus_ndef_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) == TRUE) + { + 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); + } + } + else + { + DEBUG_ERR_MSG(" send client request (sync call) failed: %s", + error->message); + g_error_free(error); + + return NET_NFC_IPC_FAIL; + } + + + 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_NOT_ACTIVATED; + } + + 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); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + 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; + + message = net_nfc_util_gdbus_variant_to_ndef_message( + arg_ndef_msg); + + callback(GUINT_TO_POINTER(arg_handle), + arg_event, + arg_result, + message, + user_data); + + net_nfc_free_ndef_message(message); + } +#if 0 /* remove temporary... */ + if (arg_event == NET_NFC_LLCP_UNREGISTERED) { + g_variant_unref(parameter); + } +#endif + } +} + +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) + { + if(net_nfc_client_snep_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("Snep Proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + 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); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + + g_variant_unref(parameter); + } + + 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_NOT_INITIALIZED; + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + 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); + result = NET_NFC_IPC_FAIL; + + g_error_free(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_DO_NOT_AUTO_START, + "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; + } +} diff --git a/src/clientlib/net_nfc_client_system_handler.c b/src/clientlib/net_nfc_client_system_handler.c new file mode 100755 index 0000000..19bce60 --- /dev/null +++ b/src/clientlib/net_nfc_client_system_handler.c @@ -0,0 +1,325 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_ndef_message.h" +#include "net_nfc_gdbus.h" +#include "net_nfc_client.h" +#include "net_nfc_client_util_internal.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 + +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) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e result; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_popup_call_set_finish( + NET_NFC_GDBUS_POPUP(source_object), + &result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish popup_set_active: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_popup_set_state_callback callback = + (net_nfc_client_popup_set_state_callback)func_data->callback; + + callback(result, func_data->user_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) +{ + NetNfcCallback *func_data; + + if (popup_proxy == NULL) + { + if(net_nfc_client_sys_handler_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("popup_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL ) + return NET_NFC_ALLOC_FAIL; + + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; + + net_nfc_gdbus_popup_call_set(popup_proxy, + state, + CHECK_FOREGROUND, + 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) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (popup_proxy == NULL) + { + if(net_nfc_client_sys_handler_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("popup_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_popup_call_set_sync(popup_proxy, + state, + CHECK_FOREGROUND, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("can not call SetActive: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +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) +{ + NetNfcCallback *func_data; + + if (popup_proxy == NULL) + { + if(net_nfc_client_sys_handler_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("popup_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) + return NET_NFC_ALLOC_FAIL; + + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; + + net_nfc_gdbus_popup_call_set(popup_proxy, + state, + NO_CHECK_FOREGROUND, + 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) +{ + net_nfc_error_e result; + GError *error = NULL; + + if (popup_proxy == NULL) + { + if(net_nfc_client_sys_handler_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("popup_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_popup_call_set_sync(popup_proxy, + state, + NO_CHECK_FOREGROUND, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("can not call SetActive: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state( + int enable) +{ + popup_state = enable; + + return net_nfc_client_sys_handler_set_state_sync(enable); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state_force( + int enable) +{ + popup_state = enable; + + return net_nfc_client_sys_handler_set_state_force_sync(enable); +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_sys_handler_get_launch_popup_state( + int *state) +{ + net_nfc_error_e result = NET_NFC_OK; + gint out_state = NET_NFC_LAUNCH_APP_SELECT; + GError *error = NULL; + + if (state == NULL) + return NET_NFC_NULL_PARAMETER; + + *state = NET_NFC_LAUNCH_APP_SELECT; + + if (popup_proxy == NULL) { + if(net_nfc_client_sys_handler_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("popup_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_popup_call_get_sync(popup_proxy, + net_nfc_client_gdbus_get_privilege(), + &result, + &out_state, + NULL, + &error) == true) { + *state = out_state; + } else { + + DEBUG_ERR_MSG("net_nfc_gdbus_popup_call_get_sync failed: %s", + error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return result; +} + +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_DO_NOT_AUTO_START, + "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; + } +} diff --git a/src/clientlib/net_nfc_client_tag.c b/src/clientlib/net_nfc_client_tag.c index 4de116e..75cde4b 100755 --- a/src/clientlib/net_nfc_client_tag.c +++ b/src/clientlib/net_nfc_client_tag.c @@ -4,7 +4,7 @@ * Licensed under the Flora License, Version 1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - + * * http://floralicense.org/license/ * * Unless required by applicable law or agreed to in writing, software @@ -14,462 +14,947 @@ * limitations under the License. */ -#include -#include - -#include "net_nfc_tag.h" -#include "net_nfc_typedef_private.h" -#include "net_nfc_client_ipc_private.h" -#include "net_nfc_debug_private.h" -#include "net_nfc_util_private.h" -#include "net_nfc_util_ndef_message.h" -#include "net_nfc_client_nfc_private.h" +#include "net_nfc_typedef_internal.h" +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_gdbus_internal.h" +#include "net_nfc_util_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_util_internal.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 -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_format_ndef(net_nfc_target_handle_h handle, data_h key, void *trans_param) +static NetNfcGDbusTag *tag_proxy = NULL; + +static NetNfcCallback tag_discovered_func_data; +static NetNfcCallback tag_detached_func_data; + +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); + +#if 0 +/* 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); +#endif +/* 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_error_e ret; - net_nfc_request_format_ndef_t *request = NULL; - uint32_t length = 0; - data_s *struct_key = (data_s *)key; + net_nfc_event_filter_e converted = NET_NFC_ALL_ENABLE; + + DEBUG_CLIENT_MSG("client filter = %d", client_filter); - if (handle == NULL) + if (type >= NET_NFC_ISO14443_A_PICC && + type <= NET_NFC_MIFARE_DESFIRE_PICC) { - return NET_NFC_NULL_PARAMETER; + converted = NET_NFC_ISO14443A_ENABLE; } - - length = sizeof(net_nfc_request_format_ndef_t); - if (struct_key != NULL) + else if (type >= NET_NFC_ISO14443_B_PICC && + type <= NET_NFC_ISO14443_BPRIME_PICC) { - length += struct_key->length; + converted = NET_NFC_ISO14443B_ENABLE; } - - _net_nfc_util_alloc_mem(request, length); - if (request == NULL) + else if (type == NET_NFC_FELICA_PICC) { - return NET_NFC_ALLOC_FAIL; + converted = NET_NFC_FELICA_ENABLE; } - - request->length = length; - request->request_type = NET_NFC_MESSAGE_FORMAT_NDEF; - request->handle = (net_nfc_target_handle_s *)handle; - request->trans_param = trans_param; - - if (struct_key != NULL && struct_key->length > 0) + else if (type == NET_NFC_JEWEL_PICC) { - request->key.length = struct_key->length; - memcpy(&request->key.buffer, struct_key->buffer, request->key.length); + converted = NET_NFC_FELICA_ENABLE; + } + else if (type == NET_NFC_ISO15693_PICC) + { + converted = NET_NFC_ISO15693_ENABLE; } - ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL); - - _net_nfc_util_free_mem(request); + if ((converted & client_filter) == 0) + return FALSE; - return ret; + return TRUE; } -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_tag_filter(net_nfc_event_filter_e config) +static void tag_get_info_list(guint8 *buffer, + gint number_of_keys, + net_nfc_tag_info_s **list) { - client_context_t *client_context = net_nfc_get_client_context(); + net_nfc_tag_info_s *tmp_list = NULL; + net_nfc_tag_info_s *current = NULL; - pthread_mutex_lock(&(client_context->g_client_lock)); - client_context->filter = config; - pthread_mutex_unlock(&(client_context->g_client_lock)); + gint i = 0; + gint length; - return NET_NFC_OK; -} + guint8 *pos = buffer; -NET_NFC_EXPORT_API net_nfc_event_filter_e net_nfc_get_tag_filter() -{ + 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++; - client_context_t *client_context = net_nfc_get_client_context(); + value = NULL; + if (length > 0) + { + net_nfc_create_data(&value, pos, length); + pos += length; + } - pthread_mutex_lock(&(client_context->g_client_lock)); - net_nfc_event_filter_e filter = client_context->filter; - pthread_mutex_unlock(&(client_context->g_client_lock)); + current->value = value; + + current++; + i++; + } - return filter; + *list = tmp_list; } -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_transceive(net_nfc_target_handle_h handle, data_h rawdata, void *trans_param) +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) { - net_nfc_error_e ret; - net_nfc_request_transceive_t *request = NULL; - client_context_t *client_context_tmp = NULL; - net_nfc_target_info_s *target_info = NULL; - uint32_t length = 0; - data_s *data = (data_s *)rawdata; - uint8_t *send_buffer; + guint8 *buffer = NULL; + net_nfc_target_info_s *info_data = NULL; + net_nfc_tag_info_s *list = NULL; - DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle); + if (info == NULL) + return; - if (handle == NULL || rawdata == NULL) - { - return NET_NFC_NULL_PARAMETER; - } + net_nfc_util_gdbus_variant_to_buffer(target_info_values, + &buffer, NULL); + + tag_get_info_list(buffer, number_of_keys, &list); - if (!net_nfc_tag_is_connected()) + 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; +} +#if 0 +static void tag_is_tag_connected(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + gboolean out_is_connected = false; + net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_tag_call_is_tag_connected_finish( + NET_NFC_GDBUS_TAG(source_object), + &out_result, + &out_is_connected, + (gint32 *)&out_dev_type, + res, + &error) == FALSE) { - return NET_NFC_OPERATION_FAIL; + DEBUG_ERR_MSG("Can not finish is_tag_connected: %s", + error->message); + g_error_free(error); + + out_result = NET_NFC_IPC_FAIL; } - client_context_tmp = net_nfc_get_client_context(); - if (client_context_tmp == NULL || client_context_tmp->target_info == NULL) + if (func_data->callback != NULL) { - return NET_NFC_NO_DATA_FOUND; + net_nfc_client_tag_is_tag_connected_completed callback = + (net_nfc_client_tag_is_tag_connected_completed)func_data->callback; + + if (out_is_connected == FALSE) + out_result = NET_NFC_NOT_CONNECTED; + + callback(out_result, out_dev_type, func_data->user_data); } - /* fill trans information struct */ - target_info = client_context_tmp->target_info; - switch (target_info->devType) + g_free(func_data); +} + +static void tag_get_current_tag_info(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result = NET_NFC_OK; + + net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; + gboolean out_is_connected = FALSE; + gboolean out_is_ndef_supported = FALSE; + guchar out_ndef_card_state = 0; + guint out_handle = 0; + guint out_max_data_size = 0; + guint out_actual_data_size = 0; + guint out_number_of_keys = 0; + GVariant *out_target_info_values = NULL; + GVariant *out_raw_data = NULL; + + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_tag_call_get_current_tag_info_finish ( + NET_NFC_GDBUS_TAG(source_object), + &out_result, + &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) { - case NET_NFC_MIFARE_MINI_PICC : - case NET_NFC_MIFARE_1K_PICC : - case NET_NFC_MIFARE_4K_PICC : - case NET_NFC_MIFARE_ULTRA_PICC : - { - length = sizeof(net_nfc_request_transceive_t) + data->length + 2; + out_result = NET_NFC_IPC_FAIL; - _net_nfc_util_alloc_mem(request, length); - if (request == NULL) - { - return NET_NFC_ALLOC_FAIL; - } + DEBUG_ERR_MSG("Can not finish get_current_tag_info: %s", + error->message); + g_error_free(error); + } - _net_nfc_util_alloc_mem(send_buffer, data->length + 2); - if (send_buffer == NULL) - { - _net_nfc_util_free_mem(request); - return NET_NFC_ALLOC_FAIL; - } + if (out_result == NET_NFC_OK && out_is_connected == true) { + net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info); + client_target_info = NULL; + + if (tag_check_filter(out_dev_type) == true) { + 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, + &client_target_info); + } else { + INFO_MSG("The detected target is filtered out, type [%d]", out_dev_type); + + out_is_connected = false; + } + } - memcpy(send_buffer, data->buffer, data->length); - net_nfc_util_compute_CRC(CRC_A, send_buffer, data->length + 2); + if (func_data->callback != NULL) + { + net_nfc_client_tag_get_current_tag_info_completed callback = + (net_nfc_client_tag_get_current_tag_info_completed)func_data->callback; - memcpy(&request->info.trans_data.buffer, send_buffer, data->length + 2); + if (out_result == NET_NFC_OK && out_is_connected == false) + out_result = NET_NFC_NOT_CONNECTED; - request->info.trans_data.length = data->length + 2; + callback(out_result, client_target_info, func_data->user_data); + } - _net_nfc_util_free_mem(send_buffer); - } - break; + g_free(func_data); +} - case NET_NFC_JEWEL_PICC : - { - if (data->length > 9) - { - return NET_NFC_INVALID_PARAM; - } +static void tag_get_current_target_handle(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result = NET_NFC_OK; + net_nfc_target_handle_h out_handle = NULL; + net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; + gboolean out_is_connected = false; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_tag_call_get_current_target_handle_finish( + NET_NFC_GDBUS_TAG(source_object), + &out_result, + &out_is_connected, + (guint *)&out_handle, + (gint *)&out_dev_type, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish get_current_target_handle: %s", + error->message); + g_error_free(error); - length = sizeof(net_nfc_request_transceive_t) + 9; + out_result = NET_NFC_IPC_FAIL; + } - _net_nfc_util_alloc_mem(request, length); - if (request == NULL) - { - return NET_NFC_ALLOC_FAIL; - } + if (func_data->callback != NULL) + { + net_nfc_client_tag_get_current_target_handle_completed callback = + (net_nfc_client_tag_get_current_target_handle_completed)func_data->callback; - _net_nfc_util_alloc_mem(send_buffer, 9); - if (send_buffer == NULL) - { - _net_nfc_util_free_mem(request); - return NET_NFC_ALLOC_FAIL; - } + if (out_result == NET_NFC_OK && out_is_connected == FALSE) + out_result = NET_NFC_NOT_CONNECTED; - memcpy(send_buffer, data->buffer, data->length); - net_nfc_util_compute_CRC(CRC_B, send_buffer, 9); + callback(out_result, + GUINT_TO_POINTER(out_handle), + func_data->user_data); + } - memcpy(&request->info.trans_data.buffer, send_buffer, 9); + g_free(func_data); +} +#endif +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) +{ + INFO_MSG(">>> SIGNAL arrived"); - request->info.trans_data.length = 9; + net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info); + client_target_info = NULL; - _net_nfc_util_free_mem(send_buffer); - } - break; + if (tag_check_filter(arg_dev_type) == FALSE) { + INFO_MSG("The detected target is filtered out, type [%d]", arg_dev_type); - default : - { - length = sizeof(net_nfc_request_transceive_t) + data->length; + return; + } - _net_nfc_util_alloc_mem(request, length); - if (request == NULL) - { - return NET_NFC_ALLOC_FAIL; - } + 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, + &client_target_info); + + if (tag_discovered_func_data.callback != NULL) { + net_nfc_client_tag_tag_discovered callback = + (net_nfc_client_tag_tag_discovered)tag_discovered_func_data.callback; + + callback(client_target_info, + tag_discovered_func_data.user_data); + } +} - memcpy(&request->info.trans_data.buffer, data->buffer, data->length); +static void tag_tag_detached(NetNfcGDbusTag *object, + guint arg_handle, + gint arg_dev_type, + gpointer user_data) +{ + INFO_MSG(">>> SIGNAL arrived"); + + if (tag_check_filter(arg_dev_type) == TRUE) { + if (tag_detached_func_data.callback != NULL) { + net_nfc_client_tag_tag_detached callback = + (net_nfc_client_tag_tag_detached)tag_detached_func_data.callback; - request->info.trans_data.length = data->length; + callback(tag_detached_func_data.user_data); } - break; + } else { + INFO_MSG("The detected target is filtered out, type [%d]", arg_dev_type); } - /* fill request message */ - request->length = length; - request->request_type = NET_NFC_MESSAGE_TRANSCEIVE; - request->handle = (net_nfc_target_handle_s *)handle; - request->trans_param = trans_param; - request->info.dev_type = (uint32_t)target_info->devType; + net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info); + client_target_info = NULL; +} + +/* internal function */ +gboolean net_nfc_client_tag_is_connected(void) +{ + if (client_target_info == NULL) + return FALSE; - ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL); + if (client_target_info->handle == NULL) + return FALSE; - _net_nfc_util_free_mem(request); + return TRUE; +} - return ret; +net_nfc_target_info_s *net_nfc_client_tag_get_client_target_info(void) +{ + return client_target_info; } -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_read_tag(net_nfc_target_handle_h handle, void *trans_param) +/* public APIs */ +#if 0 +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) { - net_nfc_error_e ret; - net_nfc_request_read_ndef_t request = { 0, }; + NetNfcCallback *func_data; - DEBUG_CLIENT_MSG("send reqeust :: read ndef = [%p]", handle); + if (tag_proxy == NULL) + return NET_NFC_NOT_INITIALIZED; - if (handle == 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_tag_is_connected()) - { - return NET_NFC_OPERATION_FAIL; - } + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) + return NET_NFC_ALLOC_FAIL; - request.length = sizeof(net_nfc_request_read_ndef_t); - request.request_type = NET_NFC_MESSAGE_READ_NDEF; - request.handle = (net_nfc_target_handle_s *)handle; - request.trans_param = trans_param; + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; - ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL); + net_nfc_gdbus_tag_call_is_tag_connected(tag_proxy, + net_nfc_client_gdbus_get_privilege(), + NULL, + tag_is_tag_connected, + func_data); - return ret; + return NET_NFC_OK; } - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_write_ndef(net_nfc_target_handle_h handle, ndef_message_h msg, void *trans_param) +#endif +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_request_write_ndef_t *request = NULL; - net_nfc_error_e result; - data_s data; - uint32_t length = 0, ndef_length = 0; + net_nfc_target_info_s *info; + net_nfc_error_e result = NET_NFC_OK; + net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; + gboolean out_is_connected = false; + GError *error = NULL; - DEBUG_CLIENT_MSG("send reqeust :: write ndef = [%p]", handle); + if (tag_proxy == NULL) + return NET_NFC_NOT_INITIALIZED; - if (handle == NULL || msg == NULL) - { - return NET_NFC_NULL_PARAMETER; + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; } - if (!net_nfc_tag_is_connected()) - { - return NET_NFC_OPERATION_FAIL; - } + info = net_nfc_client_tag_get_client_target_info(); + if (info == NULL) { + /* try to request target information from server */ + if (net_nfc_gdbus_tag_call_is_tag_connected_sync(tag_proxy, + net_nfc_client_gdbus_get_privilege(), + &result, + &out_is_connected, + (gint *)&out_dev_type, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not get is_tag_connected result: %s", + error->message); + result = NET_NFC_IPC_FAIL; - ndef_length = net_nfc_util_get_ndef_message_length((ndef_message_s *)msg); - if (ndef_length == 0) - { - return NET_NFC_INVALID_PARAM; + g_error_free(error); + + return result; + } + + if (out_is_connected == true) { + if (dev_type) + *dev_type = out_dev_type; + + result = NET_NFC_OK; + } else { + result = NET_NFC_NOT_CONNECTED; + } + } else { + /* target was connected */ + if (dev_type != NULL) { + *dev_type = info->devType; + } + + result = NET_NFC_OK; } - length = sizeof(net_nfc_request_write_ndef_t) + ndef_length; + return result; +} +#if 0 +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) +{ + NetNfcCallback *func_data; + + if (tag_proxy == NULL) + return NET_NFC_NOT_INITIALIZED; - _net_nfc_util_alloc_mem(request, length); - if (request == NULL) - { + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_INVALID_STATE; + } + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) { return NET_NFC_ALLOC_FAIL; } - /* fill request message */ - request->length = length; - request->request_type = NET_NFC_MESSAGE_WRITE_NDEF; - request->handle = (net_nfc_target_handle_s *)handle; - request->trans_param = trans_param; - request->data.length = ndef_length; + 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; +} +#endif + + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_barcode_get_barcode_sync( + unsigned char **barcode, int* barcode_len) +{ + data_s *data; + GError *error = NULL; + GVariant *out_barcode = NULL; + net_nfc_error_e result = NET_NFC_OK; + + if (tag_proxy == NULL) + return NET_NFC_NOT_INITIALIZED; - data.length = ndef_length; - data.buffer = request->data.buffer; + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } - result = net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s *)msg, &data); - if (result != NET_NFC_OK) + if (net_nfc_gdbus_tag_call_get_barcode_sync(tag_proxy, + net_nfc_client_gdbus_get_privilege(), + &result, + &out_barcode, + NULL, + &error) == FALSE) { - DEBUG_CLIENT_MSG("NDEF to rawdata is failed (reason:%d)", result); - _net_nfc_util_free_mem(request); + DEBUG_ERR_MSG("Can no get barcode result: %s", error->message); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); + return result; } - result = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL); + if(result == NET_NFC_OK) + { + data = g_new0(data_s, 1); + net_nfc_util_gdbus_variant_to_data_s(out_barcode, data); - _net_nfc_util_free_mem(request); + if(data == NULL || data->buffer == NULL || data->length == 0) + return NET_NFC_OPERATION_FAIL; + + //alloc barcode + *barcode_len = data->length; + *barcode = (unsigned char *)calloc(*barcode_len, sizeof(unsigned char)); + memcpy(*barcode, data->buffer, *barcode_len); + + if (data != NULL) { + net_nfc_util_free_data(data); + } + } return result; } -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_is_tag_connected(void *trans_param) +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_request_is_tag_connected_t request = { 0, }; - net_nfc_error_e result; + net_nfc_error_e result = NET_NFC_OK; + net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; + gboolean out_is_connected = false; + gboolean out_is_ndef_supported = false; + guchar out_ndef_card_state = 0; + guint out_handle = 0; + guint out_max_data_size = 0; + guint out_actual_data_size = 0; + guint out_number_of_keys = 0; + GVariant *out_target_info_values = NULL; + GVariant *out_raw_data = NULL; + GError *error = NULL; + + if (tag_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_NOT_ACTIVATED; + } + + if (net_nfc_client_tag_get_client_target_info() == NULL) { + /* try to request target information from server */ + if (net_nfc_gdbus_tag_call_get_current_tag_info_sync(tag_proxy, + net_nfc_client_gdbus_get_privilege(), + &result, + &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); + result = NET_NFC_IPC_FAIL; + + g_error_free(error); - request.length = sizeof(net_nfc_request_is_tag_connected_t); - request.request_type = NET_NFC_MESSAGE_IS_TAG_CONNECTED; - request.trans_param = trans_param; + return result; + } - result = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL); + if (result == NET_NFC_OK) { + if (out_is_connected == true) { + if (tag_check_filter(out_dev_type) == true) { + 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, + &client_target_info); + + result = NET_NFC_OK; + } else { + INFO_MSG("The detected target is filtered out"); + + result = NET_NFC_NOT_CONNECTED; + } + } else { + result = NET_NFC_NOT_CONNECTED; + } + } + } else { + result = NET_NFC_OK; + } + + if (result == NET_NFC_OK && info != NULL) { + *info = client_target_info; + } return result; } - -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_is_tag_connected_sync(int *dev_type) +#if 0 +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) { - net_nfc_request_is_tag_connected_t request = { 0, }; - net_nfc_response_is_tag_connected_t context = { 0, }; - net_nfc_error_e result; + NetNfcCallback *func_data; - if (dev_type == NULL) - return NET_NFC_INVALID_PARAM; + if (tag_proxy == NULL) + return NET_NFC_NOT_INITIALIZED; - request.length = sizeof(net_nfc_request_is_tag_connected_t); - request.request_type = NET_NFC_MESSAGE_IS_TAG_CONNECTED; - request.trans_param = (void *)&context; + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_INVALID_STATE; + } - result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL); - if (result == NET_NFC_OK) - { - *dev_type = context.devType; + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) { + return NET_NFC_ALLOC_FAIL; } - return result; -} + 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); -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_make_read_only_ndef_tag(net_nfc_target_handle_h handle, void *trans_param) + return NET_NFC_OK; +} +#endif +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_info_s *info; net_nfc_error_e result; - net_nfc_request_make_read_only_ndef_t request = { 0, }; - client_context_t *tmp_client_context = NULL; - net_nfc_target_info_s *target_info = NULL; + net_nfc_target_type_e out_dev_type = NET_NFC_UNKNOWN_TARGET; + gboolean out_is_connected = false; + guint out_handle = 0; + GError *error = NULL; - DEBUG_CLIENT_MSG("send reqeust :: make read only ndef tag = [%p]", handle); + if (tag_proxy == NULL) + return NET_NFC_NOT_INITIALIZED; - if (handle == NULL) - { - return NET_NFC_NULL_PARAMETER; + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; } - if (!net_nfc_tag_is_connected()) - { - return NET_NFC_OPERATION_FAIL; - } + info = net_nfc_client_tag_get_client_target_info(); + if (info == NULL) { + if (net_nfc_gdbus_tag_call_get_current_target_handle_sync( + tag_proxy, + net_nfc_client_gdbus_get_privilege(), + &result, + &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); + result = NET_NFC_IPC_FAIL; - tmp_client_context = net_nfc_get_client_context(); - if (tmp_client_context != NULL) - { - target_info = tmp_client_context->target_info; + g_error_free(error); - if (target_info != NULL) - { - bool is_supported_tag = false; - - switch (target_info->devType) - { - case NET_NFC_ISO14443_A_PICC : - case NET_NFC_MIFARE_MINI_PICC : - case NET_NFC_MIFARE_1K_PICC : - case NET_NFC_MIFARE_4K_PICC : - case NET_NFC_MIFARE_ULTRA_PICC : - case NET_NFC_JEWEL_PICC : - is_supported_tag = true; - break; - default : - is_supported_tag = false; - break; - } + return result; + } - if (!is_supported_tag) - { - DEBUG_MSG("not supported tag for read only ndef tag"); - return NET_NFC_NOT_SUPPORTED; + if (result == NET_NFC_OK) { + if (out_is_connected == true) { + if (handle) + *handle = GUINT_TO_POINTER(out_handle); + + result = NET_NFC_OK; + } else { + result = NET_NFC_NOT_CONNECTED; } } + } else if (info->devType == NET_NFC_NFCIP1_INITIATOR || + info->devType == NET_NFC_NFCIP1_TARGET) { + if (handle) + *handle = info->handle; + + result = NET_NFC_OK; + } else { + result = NET_NFC_NOT_CONNECTED; } - request.length = sizeof(net_nfc_request_make_read_only_ndef_t); - request.request_type = NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF; - request.handle = (net_nfc_target_handle_s *)handle; - request.trans_param = trans_param; - - result = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL); - return result; } -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_tag_info(void *trans_param) +NET_NFC_EXPORT_API +void net_nfc_client_tag_set_tag_discovered( + net_nfc_client_tag_tag_discovered callback, + void *user_data) { - net_nfc_request_get_current_tag_info_t request = { 0, }; - net_nfc_error_e result = NET_NFC_OK; - - request.length = sizeof(net_nfc_request_get_current_tag_info_t); - request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO; - request.trans_param = trans_param; + if (callback == NULL) + return; - result = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL); + if (tag_proxy == NULL) + { + if (net_nfc_client_tag_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("tag_proxy fail"); + /* FIXME : return result of this error */ + return; + } + } - return result; + tag_discovered_func_data.callback = (gpointer)callback; + tag_discovered_func_data.user_data = user_data; } -NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_tag_info_sync(net_nfc_target_info_h *info) +NET_NFC_EXPORT_API +void net_nfc_client_tag_unset_tag_discovered(void) { - net_nfc_request_get_current_tag_info_t request = { 0, }; - net_nfc_response_get_current_tag_info_t response = { 0, }; - net_nfc_error_e result = NET_NFC_OK; + tag_discovered_func_data.callback = NULL; + tag_discovered_func_data.user_data = NULL; +} - request.length = sizeof(net_nfc_request_get_current_tag_info_t); - request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO; - request.trans_param = (void *)&response; +NET_NFC_EXPORT_API +void net_nfc_client_tag_set_tag_detached( + net_nfc_client_tag_tag_detached callback, + void *user_data) +{ + if (callback == NULL) + return; - result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL); - if (result == NET_NFC_OK) + if (tag_proxy == NULL) { - /* already allocated memory */ - net_nfc_duplicate_target_info((net_nfc_target_info_h)response.trans_param, info); + if (net_nfc_client_tag_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("tag_proxy fail"); + /* FIXME : return result of this error */ + return; + } } - return result; + tag_detached_func_data.callback = (gpointer)callback; + tag_detached_func_data.user_data = user_data; } -bool net_nfc_util_check_tag_filter(net_nfc_target_type_e type) +NET_NFC_EXPORT_API +void net_nfc_client_tag_unset_tag_detached(void) { - net_nfc_event_filter_e current_filter = net_nfc_get_tag_filter(); - net_nfc_event_filter_e converted = NET_NFC_ALL_ENABLE; + tag_detached_func_data.callback = NULL; + tag_detached_func_data.user_data = NULL; +} - DEBUG_CLIENT_MSG("filter = [%d]", current_filter); +NET_NFC_EXPORT_API +void net_nfc_client_tag_set_filter(net_nfc_event_filter_e filter) +{ + client_filter = 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) +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) { - converted = NET_NFC_FELICA_ENABLE; + DEBUG_CLIENT_MSG("Alrady initialized"); + + return NET_NFC_OK; } - else if (type == NET_NFC_JEWEL_PICC) + + if (client_target_info) { - converted = NET_NFC_FELICA_ENABLE; + net_nfc_release_tag_info( + (net_nfc_target_info_h)client_target_info); + client_target_info = NULL; } - else if (type == NET_NFC_ISO15693_PICC) + + 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_DO_NOT_AUTO_START, + "org.tizen.NetNfcService", + "/org/tizen/NetNfcService/Tag", + NULL, + &error); + if (tag_proxy == NULL) { - converted = NET_NFC_ISO15693_ENABLE; + DEBUG_ERR_MSG("Can not create proxy : %s", error->message); + g_error_free(error); + + return NET_NFC_UNKNOWN_ERROR; } - if ((converted & current_filter) == 0) + 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) +{ + client_filter = NET_NFC_ALL_ENABLE; + + net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info); + client_target_info = NULL; + + net_nfc_client_tag_unset_tag_discovered(); + net_nfc_client_tag_unset_tag_detached(); + + if (tag_proxy) { - return false; + g_object_unref(tag_proxy); + tag_proxy = NULL; } - - return true; } diff --git a/src/clientlib/net_nfc_client_tag_felica.c b/src/clientlib/net_nfc_client_tag_felica.c new file mode 100755 index 0000000..38fc02d --- /dev/null +++ b/src/clientlib/net_nfc_client_tag_felica.c @@ -0,0 +1,524 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "net_nfc_client_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); +} diff --git a/src/clientlib/net_nfc_client_tag_jewel.c b/src/clientlib/net_nfc_client_tag_jewel.c new file mode 100755 index 0000000..c044c5a --- /dev/null +++ b/src/clientlib/net_nfc_client_tag_jewel.c @@ -0,0 +1,363 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "net_nfc_client_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); +} diff --git a/src/clientlib/net_nfc_client_tag_mifare.c b/src/clientlib/net_nfc_client_tag_mifare.c new file mode 100755 index 0000000..5c1b115 --- /dev/null +++ b/src/clientlib/net_nfc_client_tag_mifare.c @@ -0,0 +1,937 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include + +#include "net_nfc_client_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[2] = { 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; + + + rawdata.buffer = send_buffer; + rawdata.length = 2; + + 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 */ + send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE; + + _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 */ + send_buffer_length = 1 + 1 + + ((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; + + *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*/ + send_buffer_length = 1 + 1 + MIFARE_BLOCK_SIZE; + + _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 */ + send_buffer_length = 1 + 1 + ((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; + + *temp = MIFARE_CMD_WRITE_BLOCK; + temp++; + + *temp = addr; + temp++; + + memcpy(temp, + ((data_s*)data)->buffer, + ((data_s*)data)->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 */ + send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE; + + _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 */ + send_buffer_length = 1 + 1 + ((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; + + *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 */ + send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE; + + _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 */ + send_buffer_length = 1 + 1 + ((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; + + *temp = MIFARE_CMD_WRITE_BLOCK; + temp++; + + *temp = addr; + temp++; + + memcpy(temp, + ((data_s*)data)->buffer, + ((data_s*)data)->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); +} + diff --git a/src/clientlib/net_nfc_client_target_info.c b/src/clientlib/net_nfc_client_target_info.c new file mode 100755 index 0000000..3dd77de --- /dev/null +++ b/src/clientlib/net_nfc_client_target_info.c @@ -0,0 +1,371 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_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" +#include "net_nfc_ndef_message.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) +{ + net_nfc_target_info_s *target_info_private = + (net_nfc_target_info_s *)target_info; + + if (type == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *type = NET_NFC_UNKNOWN_TARGET; + + if (target_info == NULL) + { + return NET_NFC_INVALID_HANDLE; + } + + *type = target_info_private->devType; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_h target_info, + net_nfc_target_handle_h *handle) +{ + net_nfc_target_info_s *target_info_private = + (net_nfc_target_info_s *)target_info; + + if (handle == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *handle = NULL; + + if (target_info == NULL) + { + return NET_NFC_INVALID_HANDLE; + } + + *handle = (net_nfc_target_handle_h)target_info_private->handle; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_tag_ndef_support(net_nfc_target_info_h target_info, + bool *is_support) +{ + net_nfc_target_info_s *target_info_private = + (net_nfc_target_info_s *)target_info; + + if (target_info == NULL || is_support == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *is_support = (bool)target_info_private->is_ndef_supported; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_tag_ndef_state(net_nfc_target_info_h target_info, + net_nfc_ndef_card_state_e *state) +{ + net_nfc_target_info_s *target_info_private = + (net_nfc_target_info_s *)target_info; + + if (target_info == NULL || state == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *state = (net_nfc_ndef_card_state_e)target_info_private->ndefCardState; + + 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) +{ + net_nfc_target_info_s *target_info_private = + (net_nfc_target_info_s *)target_info; + + if (target_info == NULL || max_size == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *max_size = target_info_private->maxDataSize; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_tag_actual_data_size( + net_nfc_target_info_h target_info, uint32_t * actual_data) +{ + net_nfc_target_info_s *target_info_private = + (net_nfc_target_info_s *)target_info; + + if (target_info == NULL || actual_data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *actual_data = target_info_private->actualDataSize; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, + char ***keys, int * number_of_keys) +{ + net_nfc_target_info_s *handle = (net_nfc_target_info_s *)target_info; + int i = 0; + + if (keys == NULL || number_of_keys == NULL || target_info == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (handle->tag_info_list == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (handle->number_of_keys <= 0) + { + return NET_NFC_NO_DATA_FOUND; + } + + DEBUG_CLIENT_MSG("number of keys = [%d]", handle->number_of_keys); + + if (handle->keylist != NULL) + { + *number_of_keys = handle->number_of_keys; + *keys = handle->keylist; + + return NET_NFC_OK; + } + + i = handle->number_of_keys * sizeof(char *); + + _net_nfc_util_alloc_mem(*keys, i); + 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; + + /* store local context */ + 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) +{ + net_nfc_target_info_s *handle = (net_nfc_target_info_s *)target_info; + net_nfc_tag_info_s *tag_info; + + if (target_info == NULL || key == NULL || value == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (handle->tag_info_list == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + int i = 0; + + 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_NO_DATA_FOUND; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_get_tag_ndef_message(net_nfc_target_info_h target_info, + ndef_message_h *msg) +{ + net_nfc_target_info_s *target_info_private = + (net_nfc_target_info_s *)target_info; + net_nfc_error_e result; + + if (target_info == NULL || msg == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + result = net_nfc_create_ndef_message_from_rawdata(msg, + (data_h)&target_info_private->raw_data); + + return result; +} + +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_init_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 _release_tag_info(net_nfc_target_info_s *info) +{ + 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; + + 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_clear_data(&info->raw_data); + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_release_tag_info(net_nfc_target_info_h target_info) +{ + net_nfc_target_info_s *info = (net_nfc_target_info_s *)target_info; + net_nfc_error_e result; + + if (info == NULL) + return NET_NFC_NULL_PARAMETER; + + result = _release_tag_info(info); + + _net_nfc_util_free_mem(info); + + return result; +} diff --git a/src/clientlib/net_nfc_client_test.c b/src/clientlib/net_nfc_client_test.c new file mode 100755 index 0000000..6558995 --- /dev/null +++ b/src/clientlib/net_nfc_client_test.c @@ -0,0 +1,704 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_util_internal.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 + +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 void test_call_ese_test_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) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_test_call_sim_test_finish( + NET_NFC_GDBUS_TEST(source_object), + (gint *)&out_result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish sim_test: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_test_sim_test_completed callback = + (net_nfc_client_test_sim_test_completed)func_data->callback; + + callback(out_result, func_data->user_data); + } + + g_free(func_data); +} + +static void test_call_prbs_test_callback(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_test_call_prbs_test_finish( + NET_NFC_GDBUS_TEST(source_object), + (gint *)&out_result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish prbs test: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_test_prbs_test_completed callback = + (net_nfc_client_test_prbs_test_completed)func_data->callback; + + callback(out_result, func_data->user_data); + } + + g_free(func_data); +} + +static void test_call_get_firmware_version_callback(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + gchar *out_version = NULL; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_test_call_get_firmware_version_finish( + NET_NFC_GDBUS_TEST(source_object), + (gint *)&out_result, + &out_version, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish get_firmware_version: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_test_get_firmware_version_completed callback = + (net_nfc_client_test_get_firmware_version_completed)func_data->callback; + + callback(out_result, out_version, func_data->user_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) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_test_call_set_ee_data_finish( + NET_NFC_GDBUS_TEST(source_object), + (gint *)&out_result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish set_ee_data: %s\n", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_test_set_ee_data_completed callback = + (net_nfc_client_test_set_ee_data_completed)func_data->callback; + + callback(out_result, func_data->user_data); + } + + g_free(func_data); +} + +static void test_call_ese_test_callback(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_test_call_ese_test_finish( + NET_NFC_GDBUS_TEST(source_object), + (gint *)&out_result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish sim_test: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + net_nfc_client_test_ese_test_completed callback = + (net_nfc_client_test_ese_test_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) +{ + NetNfcCallback *func_data; + + if (test_proxy == NULL) + { + if(net_nfc_client_test_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("test_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) + return NET_NFC_ALLOC_FAIL; + + 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) +{ + net_nfc_error_e out_result = NET_NFC_OK; + GError *error = NULL; + + if (test_proxy == NULL) + { + if(net_nfc_client_test_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("test_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_test_call_sim_test_sync(test_proxy, + net_nfc_client_gdbus_get_privilege(), + (gint *)&out_result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("can not call SimTest: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(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) +{ + NetNfcCallback *func_data; + + if (test_proxy == NULL) + { + if(net_nfc_client_test_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("test_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) + return NET_NFC_ALLOC_FAIL; + + 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) +{ + net_nfc_error_e out_result = NET_NFC_OK; + GError *error = NULL; + + if (test_proxy == NULL) + { + if(net_nfc_client_test_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("test_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + 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_ERR_MSG("can not call PrbsTest: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(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) +{ + NetNfcCallback *func_data; + + if (test_proxy == NULL) + { + if(net_nfc_client_test_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("test_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) + return NET_NFC_ALLOC_FAIL; + + 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) +{ + net_nfc_error_e out_result = NET_NFC_OK; + gchar *out_version = NULL; + GError *error = NULL; + + if (version == NULL) + return NET_NFC_NULL_PARAMETER; + + *version = NULL; + + if (test_proxy == NULL) + { + if(net_nfc_client_test_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("test_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + 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) == TRUE) + { + *version = out_version; + } + else + { + DEBUG_ERR_MSG("can not call Get Firmware version: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + 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) +{ + NetNfcCallback *func_data; + GVariant *variant; + + if (test_proxy == NULL) + { + if(net_nfc_client_test_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("test_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) { + return NET_NFC_ALLOC_FAIL; + } + + 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) +{ + net_nfc_error_e out_result = NET_NFC_OK; + GVariant *variant = NULL; + GError *error = NULL; + + if (test_proxy == NULL) + { + if(net_nfc_client_test_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("test_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + 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_ERR_MSG("can not call SetEeTest: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return out_result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_test_ese_test( + net_nfc_client_test_ese_test_completed callback, + void *user_data) +{ + NetNfcCallback *func_data; + + DEBUG_CLIENT_MSG("NFC ESE Test!!!!"); + + if (test_proxy == NULL) + { + if(net_nfc_client_test_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("test_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) + return NET_NFC_ALLOC_FAIL; + + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; + + net_nfc_gdbus_test_call_ese_test(test_proxy, + net_nfc_client_gdbus_get_privilege(), + NULL, + test_call_ese_test_callback, + func_data); + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_test_ese_test_sync(void) +{ + net_nfc_error_e out_result = NET_NFC_OK; + GError *error = NULL; + + DEBUG_CLIENT_MSG("NFC ESE Test SYNC!!!!"); + + if (test_proxy == NULL) + { + if(net_nfc_client_test_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("test_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_test_call_ese_test_sync(test_proxy, + net_nfc_client_gdbus_get_privilege(), + (gint *)&out_result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("can not call ESE Test: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + return out_result; +} + +NET_NFC_EXPORT_API +net_nfc_error_e net_nfc_client_test_set_se_tech_type_sync( + net_nfc_se_type_e type, int tech) +{ + net_nfc_error_e out_result = NET_NFC_OK; + GError *error = NULL; + + if (test_proxy == NULL) + { + if(net_nfc_client_test_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("test_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + if (net_nfc_gdbus_test_call_set_se_tech_type_sync(test_proxy, + (guint32)type, + (guint32)tech, + net_nfc_client_gdbus_get_privilege(), + (gint *)&out_result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("can not call SetSeTechType: %s", + error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(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_DO_NOT_AUTO_START, + "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; + } +} diff --git a/src/clientlib/net_nfc_client_transceive.c b/src/clientlib/net_nfc_client_transceive.c new file mode 100755 index 0000000..2fc820c --- /dev/null +++ b/src/clientlib/net_nfc_client_transceive.c @@ -0,0 +1,473 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_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_util_internal.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); + +static GVariant *transceive_data_to_transceive_variant( + net_nfc_target_type_e devType, + data_s *data) +{ + data_s transceive_info = { NULL, }; + GVariant *variant; + + 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_init_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_init_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_init_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_clear_data(&transceive_info); + + return variant; +} + +static void transceive_data_call(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + GVariant *out_data = NULL; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_transceive_call_transceive_data_finish( + NET_NFC_GDBUS_TRANSCEIVE(source_object), + (gint *)&out_result, + &out_data, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish transceive: %s", error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + data_s resp = { NULL, }; + + net_nfc_util_gdbus_variant_to_data_s(out_data, &resp); + + ((nfc_transceive_data_callback)func_data->callback)( + out_result, + &resp, + func_data->user_data); + + net_nfc_util_clear_data(&resp); + } + + g_free(func_data); +} + +static void transceive_call(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e out_result; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_transceive_call_transceive_finish( + NET_NFC_GDBUS_TRANSCEIVE(source_object), + (gint *)&out_result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Can not finish transceive: %s", error->message); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(error); + } + + if (func_data->callback != NULL) + { + ((nfc_transceive_callback)func_data->callback)( + out_result, + func_data->user_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; + NetNfcCallback *funcdata; + GVariant *arg_data; + + if (transceive_proxy == NULL) + { + if(net_nfc_client_transceive_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("transceive_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + target_info = net_nfc_client_tag_get_client_target_info(); + if (target_info == NULL || target_info->handle == NULL) + return NET_NFC_NOT_CONNECTED; + + DEBUG_CLIENT_MSG("send request :: transceive = [%p]", handle); + + arg_data = transceive_data_to_transceive_variant(target_info->devType, + rawdata); + if (arg_data == NULL) { + return NET_NFC_INVALID_PARAM; + } + + funcdata = g_try_new0(NetNfcCallback, 1); + if (funcdata == NULL) { + g_variant_unref(arg_data); + + return NET_NFC_ALLOC_FAIL; + } + + funcdata->callback = (gpointer)callback; + funcdata->user_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; + NetNfcCallback *funcdata; + GVariant *arg_data; + + if (transceive_proxy == NULL) + { + if(net_nfc_client_transceive_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("transceive_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + 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_NOT_ACTIVATED; + } + + target_info = net_nfc_client_tag_get_client_target_info(); + if (target_info == NULL || target_info->handle == NULL) + return NET_NFC_NOT_CONNECTED; + + DEBUG_CLIENT_MSG("send request :: transceive = [%p]", handle); + + arg_data = transceive_data_to_transceive_variant(target_info->devType, + rawdata); + if (arg_data == NULL) { + return NET_NFC_INVALID_PARAM; + } + + funcdata = g_try_new0(NetNfcCallback, 1); + if (funcdata == NULL) { + g_variant_unref(arg_data); + + return NET_NFC_ALLOC_FAIL; + } + + funcdata->callback = (gpointer)callback; + funcdata->user_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; + net_nfc_error_e out_result = NET_NFC_OK; + GError *error = NULL; + GVariant *arg_data; + + if (handle == NULL || rawdata == NULL) + return NET_NFC_NULL_PARAMETER; + + if (transceive_proxy == NULL) + { + if(net_nfc_client_transceive_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("transceive_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + target_info = net_nfc_client_tag_get_client_target_info(); + if (target_info == NULL || target_info->handle == NULL) + return NET_NFC_NOT_CONNECTED; + + DEBUG_CLIENT_MSG("send request :: transceive = [%p]", handle); + + arg_data = transceive_data_to_transceive_variant(target_info->devType, + rawdata); + if (arg_data == NULL) + return NET_NFC_ALLOC_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); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(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; + net_nfc_error_e out_result = NET_NFC_OK; + GVariant *out_data = NULL; + GError *error = NULL; + GVariant *arg_data; + + if (handle == NULL || rawdata == NULL) + return NET_NFC_NULL_PARAMETER; + + if (transceive_proxy == NULL) + { + if(net_nfc_client_transceive_init() != NET_NFC_OK) + { + DEBUG_ERR_MSG("transceive_proxy fail"); + return NET_NFC_NOT_INITIALIZED; + } + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_NOT_ACTIVATED; + } + + target_info = net_nfc_client_tag_get_client_target_info(); + if (target_info == NULL || target_info->handle == NULL) + return NET_NFC_NOT_CONNECTED; + + DEBUG_CLIENT_MSG("send request :: transceive = [%p]", handle); + + arg_data = transceive_data_to_transceive_variant(target_info->devType, + rawdata); + if (arg_data == NULL) + return NET_NFC_ALLOC_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); + out_result = NET_NFC_IPC_FAIL; + + g_error_free(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_DO_NOT_AUTO_START, + "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; + } +} diff --git a/src/clientlib/net_nfc_client_util.c b/src/clientlib/net_nfc_client_util.c new file mode 100755 index 0000000..60e6125 --- /dev/null +++ b/src/clientlib/net_nfc_client_util.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "net_nfc_client_util_internal.h" + diff --git a/src/clientlib/nfc.pc.in b/src/clientlib/nfc.pc.in new file mode 100755 index 0000000..1930885 --- /dev/null +++ b/src/clientlib/nfc.pc.in @@ -0,0 +1,11 @@ +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 diff --git a/src/commonlib/CMakeLists.txt b/src/commonlib/CMakeLists.txt old mode 100644 new mode 100755 index d77aab2..3d60700 --- a/src/commonlib/CMakeLists.txt +++ b/src/commonlib/CMakeLists.txt @@ -5,6 +5,15 @@ 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) @@ -14,7 +23,8 @@ IF("${CMAKE_BUILD_TYPE}" STREQUAL "") ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") INCLUDE(FindPkgConfig) -pkg_check_modules(commonlib_pkges REQUIRED glib-2.0 dlog bluetooth-api libssl) +pkg_check_modules(commonlib_pkges REQUIRED + glib-2.0 gio-2.0 gio-unix-2.0 dlog bluetooth-api openssl aul pkgmgr-info) FOREACH(flag ${commonlib_pkges_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -41,10 +51,6 @@ IF("${ARCH}" MATCHES "^arm.*") ENDIF() ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") -#ADD_DEFINITIONS("-DSLP_DEBUG") -ADD_DEFINITIONS("-DNFC_DEBUG_USE_DLOG -D_GNU_SOURCE") -#ADD_DEFINITIONS("-DUSE_UNIX_DOMAIN") -#ADD_DEFINITIONS("-DSECURITY_SERVER") ADD_LIBRARY(${NFC_COMMON_LIB} SHARED ${COMMON_LIB_SRCS}) SET_TARGET_PROPERTIES(${NFC_COMMON_LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) @@ -54,9 +60,9 @@ TARGET_LINK_LIBRARIES(${NFC_COMMON_LIB} ${commonlib_pkges_LDFLAGS}) SET(COMMON_LIB_HEADER include/net_nfc_typedef.h - include/net_nfc_util_private.h + include/net_nfc_util_internal.h include/net_nfc_oem_controller.h - include/net_nfc_typedef_private.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 @@ -64,8 +70,18 @@ SET(COMMON_LIB_HEADER ) 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_INSTALL_DIR}/pkgconfig) -INSTALL(TARGETS ${NFC_COMMON_LIB} DESTINATION ${LIB_INSTALL_DIR}) + +IF (TIZEN_ARCH_64) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc DESTINATION /usr/lib64/pkgconfig) +ELSE (TIZEN_ARCH_64) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc DESTINATION /usr/lib/pkgconfig) +ENDIF(TIZEN_ARCH_64) + +IF (TIZEN_ARCH_64) + INSTALL(TARGETS ${NFC_COMMON_LIB} DESTINATION lib64) +ELSE (TIZEN_ARCH_64) + INSTALL(TARGETS ${NFC_COMMON_LIB} DESTINATION lib) +ENDIF(TIZEN_ARCH_64) FOREACH(hfile ${COMMON_LIB_HEADER}) INSTALL(FILES ${hfile} DESTINATION include/nfc-common-lib) diff --git a/src/commonlib/include/net_nfc_debug_internal.h b/src/commonlib/include/net_nfc_debug_internal.h new file mode 100755 index 0000000..8a7f25f --- /dev/null +++ b/src/commonlib/include/net_nfc_debug_internal.h @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 +#include +#include +#include +#include + +// below define should define before dlog.h +#define LOG_SERVER_TAG "NET_NFC_MANAGER" +#define LOG_CLIENT_TAG "NET_NFC_CLIENT" + +#include + +#define LOG_COLOR_RED "\033[0;31m" +#define LOG_COLOR_GREEN "\033[0;32m" +#define LOG_COLOR_BROWN "\033[0;33m" +#define LOG_COLOR_BLUE "\033[0;34m" +#define LOG_COLOR_PURPLE "\033[0;35m" +#define LOG_COLOR_CYAN "\033[0;36m" +#define LOG_COLOR_LIGHTBLUE "\033[0;37m" +#define LOG_COLOR_END "\033[0;m" + +/* nfc_log_to_file */ +extern FILE *nfc_log_file; +#define NFC_DLOG_FILE "/opt/usr/share/nfc_debug/nfc_mgr_dlog.txt" + +/* tag */ +const char *net_nfc_get_log_tag(); + +#define NFC_LOGD(format, arg...) LOG(LOG_DEBUG, net_nfc_get_log_tag(), format, ##arg) +#define NFC_LOGI(format, arg...) LOG(LOG_INFO, net_nfc_get_log_tag(), format, ##arg) +#define NFC_LOGW(format, arg...) LOG(LOG_WARN, net_nfc_get_log_tag(), format, ##arg) +#define NFC_LOGE(format, arg...) LOG(LOG_ERROR, net_nfc_get_log_tag(), format, ##arg) + +#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) \ + { \ + struct tm *local_tm; \ + char timeBuf[50]; \ + time_t rawtime; time (&rawtime); \ + local_tm = localtime(&rawtime); \ + if(local_tm != NULL) { \ + strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", local_tm); \ + 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_ADDON_MSG(format, args...) \ + do { \ + NFC_LOGD(LOG_COLOR_BLUE format LOG_COLOR_END, ##args); \ + if (nfc_log_file) \ + { \ + struct tm *local_tm; \ + char timeBuf[50]; \ + time_t rawtime; time (&rawtime); \ + local_tm = localtime(&rawtime); \ + if(local_tm != NULL) { \ + strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", local_tm); \ + 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) \ + { \ + struct tm *local_tm; \ + char timeBuf[50]; \ + time_t rawtime; time (&rawtime); \ + local_tm = localtime(&rawtime); \ + if(local_tm != NULL) { \ + strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", local_tm); \ + 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) \ + { \ + struct tm *local_tm; \ + char timeBuf[50]; \ + time_t rawtime; time (&rawtime); \ + local_tm = localtime(&rawtime); \ + if(local_tm != NULL) { \ + strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", local_tm); \ + 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_LOGE(LOG_COLOR_RED format LOG_COLOR_END, ##args);\ + if (nfc_log_file) \ + { \ + struct tm *local_tm; \ + char timeBuf[50]; \ + time_t rawtime; time (&rawtime); \ + local_tm = localtime(&rawtime); \ + if(local_tm != NULL) { \ + strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", local_tm); \ + 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) \ + { \ + struct tm *local_tm; \ + char timeBuf[50]; \ + time_t rawtime; time (&rawtime); \ + local_tm = localtime(&rawtime); \ + if(local_tm != NULL) { \ + strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", local_tm); \ + 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) \ + { \ + struct tm *local_tm; \ + char timeBuf[50]; \ + time_t rawtime; time (&rawtime); \ + local_tm = localtime(&rawtime); \ + if(local_tm != NULL) { \ + strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", local_tm); \ + 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__ diff --git a/src/commonlib/include/net_nfc_oem_controller.h b/src/commonlib/include/net_nfc_oem_controller.h new file mode 100755 index 0000000..7b897f1 --- /dev/null +++ b/src/commonlib/include/net_nfc_oem_controller.h @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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, hce_apdu_listener_cb hce_apdu_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 bool (*net_nfc_oem_controller_ese_test)(net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_test_set_se_tech_type)(net_nfc_error_e *result, net_nfc_se_type_e type, uint32_t tech); + +/* hce api*/ +typedef bool (*net_nfc_oem_controller_hce_response_apdu)(net_nfc_target_handle_s *handle, data_s *command, net_nfc_error_e *result); + +typedef bool (*net_nfc_oem_controller_secure_element_route_aid)(data_s *aid, net_nfc_se_type_e se_type, + int power, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_secure_element_unroute_aid)(data_s *aid, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_secure_element_commit_routing)(net_nfc_error_e *result); + +typedef bool (*net_nfc_oem_controller_secure_element_set_default_route)( + net_nfc_se_type_e switch_on, + net_nfc_se_type_e switch_off, + net_nfc_se_type_e battery_off, net_nfc_error_e *result); + +typedef bool (*net_nfc_oem_controller_secure_element_clear_aid_table)(net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_secure_element_get_aid_tablesize)(int *AIDTableSize, + net_nfc_error_e *result); + +typedef bool (*net_nfc_oem_controller_secure_element_set_route_entry) + (net_nfc_se_entry_type_e type, net_nfc_se_tech_protocol_type_e value, + net_nfc_se_type_e route, int power, net_nfc_error_e *result); + +typedef bool (*net_nfc_oem_controller_secure_element_clear_routing_entry) + (net_nfc_se_entry_type_e type, net_nfc_error_e *result); + +typedef bool (*net_nfc_oem_controller_set_screen_state) + (net_nfc_screen_state_type_e screen_state, net_nfc_error_e *result); + + + +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_ese_test ese_test; + + 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_controller_test_set_se_tech_type test_set_se_tech_type; + + net_nfc_oem_controller_hce_response_apdu hce_response_apdu; + net_nfc_oem_controller_secure_element_route_aid route_aid; + net_nfc_oem_controller_secure_element_unroute_aid unroute_aid; + net_nfc_oem_controller_secure_element_commit_routing commit_routing; + net_nfc_oem_controller_secure_element_set_default_route set_default_route; + net_nfc_oem_controller_secure_element_clear_aid_table clear_aid_table; + net_nfc_oem_controller_secure_element_get_aid_tablesize get_aid_tablesize; + + + net_nfc_oem_controller_secure_element_set_route_entry set_routing_entry; + net_nfc_oem_controller_secure_element_clear_routing_entry clear_routing_entry; + net_nfc_oem_controller_set_screen_state set_screen_state; +} net_nfc_oem_interface_s; + +#endif //__NET_NFC_OEM_CONTROLLER_H__ diff --git a/src/commonlib/include/net_nfc_typedef.h b/src/commonlib/include/net_nfc_typedef.h old mode 100644 new mode 100755 index e1e3398..5938d3d --- a/src/commonlib/include/net_nfc_typedef.h +++ b/src/commonlib/include/net_nfc_typedef.h @@ -1,19 +1,20 @@ /* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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. + */ +#ifndef __NET_NFC_TYPEDEF_H__ +#define __NET_NFC_TYPEDEF_H__ /** NFC Manager @@ -25,9 +26,6 @@ */ -#ifndef __NET_NFC_TYPEDEF_H__ -#define __NET_NFC_TYPEDEF_H__ - /** @defgroup NET_NFC_MANAGER The description of NFC Manager @defgroup NET_NFC_TYPEDEF Defines and structures @@ -122,6 +120,8 @@ typedef enum /*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 */ +/*967*/NET_NFC_PERMISSION_DENIED, /**< privilege check is failed */ +/*966*/NET_NFC_NOT_ACTIVATED, /**< Application tries to request without activation */ /*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 */ @@ -181,7 +181,7 @@ typedef enum NET_NFC_MESSAGE_TAG_DETACHED, /**< Type: Notify Event,
When a tag or SE is disappeared, you got this event.
The data contains the target info , need to cast to net_nfc_target_info_h but it does not have detail target info
please, do not use "net_nfc_get_tag_info_keys" when you got this event*/ - /*10*/NET_NFC_MESSAGE_FORMAT_NDEF, /**< Type: Response Event
After complete "net_nfc_format_ndef", this event is delivered */ +/*10*/ NET_NFC_MESSAGE_FORMAT_NDEF, /**< Type: Response Event
After complete "net_nfc_format_ndef", this event is delivered */ NET_NFC_MESSAGE_LLCP_DISCOVERED,/**< Type: Notify Event
When LLCP is discovered and remote device is support llcp, you receive this event
data pointer contains the remote llcp configuration info. Cast to net_nfc_llcp_config_info_h*/ NET_NFC_MESSAGE_P2P_DETACHED, /**< Type: Notify Event
When LLCP is de-activated by removing the device, you receive this event*/ @@ -194,21 +194,19 @@ typedef enum 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 */ +/*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_SE_CARD_EMULATION_CHANGED, /**< Type: Notify Event, indicates card emulation mode is changed*/ - NET_NFC_MESSAGE_CONNECTION_HANDOVER, /**< Type: Response Event.
The result of connection handover. If it has been completed successfully, this event will include the information of alternative carrier. */ NET_NFC_MESSAGE_SET_SE, NET_NFC_MESSAGE_GET_SE, NET_NFC_MESSAGE_OPEN_INTERNAL_SE, NET_NFC_MESSAGE_CLOSE_INTERNAL_SE, - /*30*/NET_NFC_MESSAGE_SEND_APDU_SE, +/*30*/ NET_NFC_MESSAGE_SEND_APDU_SE, NET_NFC_MESSAGE_GET_ATR_SE, - NET_NFC_MESSAGE_CARD_EMULATION_CHANGE_SE, NET_NFC_GET_SERVER_STATE, NET_NFC_MESSAGE_SIM_TEST, @@ -221,6 +219,21 @@ typedef enum 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, + +/*47*/ NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED, + NET_NFC_MESSAGE_ROUTING_HOST_EMU_DEACTIVATED, + NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA, } net_nfc_message_e; typedef enum @@ -244,6 +257,8 @@ typedef enum NET_NFC_FELICA_PICC, NET_NFC_JEWEL_PICC, NET_NFC_ISO15693_PICC, + NET_NFC_BARCODE_128_PICC, + NET_NFC_BARCODE_256_PICC, /* NFC-IP1 Device Types */ NET_NFC_NFCIP1_TARGET, @@ -354,7 +369,12 @@ typedef enum
data pointer contains received data (Cast to data_h)*/ NET_NFC_MESSAGE_LLCP_RECEIVE_FROM, /**< Type: Response Event,
"net_nfc_receive_llcp_from" operation is completed (connectionless mode)*/ NET_NFC_MESSAGE_LLCP_DISCONNECT, /**< Type: Response Event,
"net_nfc_disconnect_llcp" request is completed */ - NET_NFC_MESSAGE_LLCP_ERROR, /**< Type: Notify Event,
when the socket is disconnected or rejected, you may receive this event */ + NET_NFC_MESSAGE_LLCP_ERROR, /**< Type: Notify Event,
when the socket is disconnected, you may receive this event */ + NET_NFC_MESSAGE_LLCP_CONNECT_REQ, /**< Type: Notify Event,
when the peer requests connect, you may receive this event */ + NET_NFC_MESSAGE_LLCP_ACCEPT, /**< Type: Response Event
this event indicates "net_nfc_accept_llcp" requested is completed*/ + NET_NFC_MESSAGE_LLCP_REJECT, /**< Type: Response Event
this event indicates "net_nfc_reject_llcp" requested is completed*/ + NET_NFC_MESSAGE_LLCP_REJECTED, /**< Type: Notify Event,
when the socket is rejected, you may receive this event */ + NET_NFC_MESSAGE_LLCP_CLOSE, /**< Type: Response Event,
"net_nfc_close_llcp_socket" request is completed */ } net_nfc_llcp_message_e; @@ -392,6 +412,8 @@ 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); @@ -402,29 +424,17 @@ typedef void (*net_nfc_internal_se_response_cb)(net_nfc_message_e message, net_n 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); +// handover 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_WIFI_WPS, /* Wifi Protected Setup */ +#define NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS + NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P, /* Wifi Peer-to-Peer */ +#define NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P +#define NET_NFC_CONN_HANDOVER_CARRIER_WIFI_DIRECT NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P + NET_NFC_CONN_HANDOVER_CARRIER_BT_LE, NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, } net_nfc_conn_handover_carrier_type_e; @@ -471,6 +481,26 @@ typedef enum NET_NFC_WIFI_ATTRIBUTE_VERSION2 = 0x00, } net_nfc_carrier_wifi_attribute_e; +typedef enum +{ + NET_NFC_WIFI_P2P_ATTRIBUTE_MANUFACTURER = 0x1021, + NET_NFC_WIFI_P2P_ATTRIBUTE_MODEL_NAME = 0x1023, + NET_NFC_WIFI_P2P_ATTRIBUTE_MODEL_NUMBER = 0x1024, + NET_NFC_WIFI_P2P_ATTRIBUTE_OOB_DEVICE_PASSWORD = 0x102C, + NET_NFC_WIFI_P2P_ATTRIBUTE_RF_BANDS = 0x103C, + NET_NFC_WIFI_P2P_ATTRIBUTE_SERIAL_NUMBER = 0x1042, + NET_NFC_WIFI_P2P_ATTRIBUTE_UUID_E = 0x1047, + NET_NFC_WIFI_P2P_ATTRIBUTE_VEN_EXT = 0x1049, + + NET_NFC_WIFI_P2P_ATTRIBUTE_CAPABILITY = 0x02, + NET_NFC_WIFI_P2P_ATTRIBUTE_DEVICE_INFO = 0x0D, + NET_NFC_WIFI_P2P_ATTRIBUTE_OOB_GROUP_OWNER_NEGO_CHANNEL = 0x13, + NET_NFC_WIFI_P2P_ATTRIBUTE_CHANNEL_LIST = 0x0B, + NET_NFC_WIFI_P2P_ATTRIBUTE_GROUP_INFO = 0x0E, + NET_NFC_WIFI_P2P_ATTRIBUTE_GROUP_ID = 0x0F, +} +net_nfc_carrier_wifi_p2p_attribute_e; + typedef enum { NET_NFC_BT_ATTRIBUTE_UUID16_PART = 0x02, /* More 16-bit UUIDs available */ @@ -493,20 +523,43 @@ typedef enum 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 struct _net_nfc_ch_message_s *net_nfc_ch_message_h; +typedef struct _net_nfc_ch_carrier_s *net_nfc_ch_carrier_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_HCE = 0x04, /* SDCard type is not currently supported */ } net_nfc_se_type_e; + typedef enum + { + NET_NFC_SE_INVALID_ENTRY = 0x00, /**< Indicates SE type is Invalid */ + NET_NFC_SE_TECH_ENTRY = 0x01, /*Technology*/ + NET_NFC_SE_PROTOCOL_ENTRY = 0x02, /*Protocol*/ +} net_nfc_se_entry_type_e; + typedef enum { - NET_NFC_CARD_EMELATION_ENABLE = 0, - NET_NFC_CARD_EMULATION_DISABLE, -} -net_nfc_card_emulation_mode_t; + NET_NFC_SE_INVALID_TECH_PROTO = 0x00, /**< Indicates SE type is Invalid */ + NET_NFC_SE_TECH_A_ISODEP = 0x01,/*Type A /ISO DEP*/ + NET_NFC_SE_TECH_B_NFCDEP = 0x02,/*Type B / NFC DEP*/ + NET_NFC_SE_TECH_A_B_ISO_NFC_DEP = 0x03,/*Type B / NFC DEP*/ + NET_NFC_SE_TECH_F = 0x04,/*Type F*/ +} net_nfc_se_tech_protocol_type_e; + +typedef enum +{ + NET_NFC_SE_INVALID = 0x00, /**< Indicates SE type is Invalid */ + NET_NFC_SE_SWITCH_ON = 0x01,/* Target On*/ + NET_NFC_SE_SWITCH_OFF = 0x02,/*Target Off*/ + NET_NFC_SE_SCREEN_OFF = 0x08, + NET_NFC_SE_SCREEN_ON_LOCK = 0x10, + NET_NFC_SE_SCREEN_ON_UNLOCK = 0x20, +} net_nfc_se_power_state_type_e; typedef enum { @@ -525,6 +578,45 @@ typedef enum 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_EMULATION_DISABLE = 0, + NET_NFC_CARD_EMELATION_ENABLE +} +net_nfc_card_emulation_mode_t; + +typedef enum +{ + NET_NFC_HCE_EVENT_DEACTIVATED = 0, + NET_NFC_HCE_EVENT_ACTIVATED = 1, + NET_NFC_HCE_EVENT_APDU_RECEIVED = 2, +} +net_nfc_hce_event_t; + +typedef enum +{ + NET_NFC_CARD_EMULATION_CATEGORY_UNKNOWN = 0, + NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT = 1, + NET_NFC_CARD_EMULATION_CATEGORY_OTHER = 2, + NET_NFC_CARD_EMULATION_CATEGORY_MAX = 3, +} +net_nfc_card_emulation_category_t; + #ifdef __cplusplus } #endif @@ -533,5 +625,4 @@ typedef enum @} */ -#endif - +#endif //__NET_NFC_TYPEDEF_H__ diff --git a/src/commonlib/include/net_nfc_typedef_internal.h b/src/commonlib/include/net_nfc_typedef_internal.h new file mode 100755 index 0000000..6cf81d9 --- /dev/null +++ b/src/commonlib/include/net_nfc_typedef_internal.h @@ -0,0 +1,465 @@ + /* + * Copyright 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_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_hce_apdu_t +{ + NET_NFC_REQUEST_MSG_HEADER + + data_s apdu; +} net_nfc_request_hce_apdu_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; + +// 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); + + +/*HCE CB*/ +typedef void (*hce_active_listener_cb)(void *user_param); +typedef void (*hce_deactive_listener_cb)(void *user_param); +typedef void (*hce_apdu_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_policy_e +{ + SECURE_ELEMENT_POLICY_INVALID = 0x00, + SECURE_ELEMENT_POLICY_UICC_ON = 0x01, + SECURE_ELEMENT_POLICY_UICC_OFF = 0x02, + SECURE_ELEMENT_POLICY_ESE_ON = 0x03, + SECURE_ELEMENT_POLICY_ESE_OFF = 0x04, + SECURE_ELEMENT_POLICY_HCE_ON = 0x05, + SECURE_ELEMENT_POLICY_HCE_OFF = 0x06 +} net_nfc_secure_element_policy_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, /** Reader B structure includes the available information - * related to the discovered ISO14443B remote device. This information - * is updated for every device discovery. - * \note None. - * - */ -typedef struct _net_nfc_sIso14443BInfo_t -{ - union net_nfc_uAtqBInfo - { - struct net_nfc_sAtqBInfo - { - uint8_t Pupi[NET_NFC_PUPI_LENGTH]; /**< PUPI information of the TYPE B Tag Discovered */ - uint8_t AppData[NET_NFC_APP_DATA_B_LENGTH]; /**< Application Data of the TYPE B Tag Discovered */ - uint8_t ProtInfo[NET_NFC_PROT_INFO_B_LENGTH]; /**< Protocol Information of the TYPE B Tag Discovered */ - } AtqResInfo; - uint8_t AtqRes[NET_NFC_ATQB_LENGTH]; /**< ATQB Response Information of TYPE B Tag Discovered */ - } AtqB; - - uint8_t HiLayerResp[NET_NFC_MAX_ATR_LENGTH]; /**< Higher Layer Response information in answer to ATRRIB Command for Type B */ - uint8_t HiLayerRespLength; /**< Higher Layer Response length */ - uint8_t Afi; /**< Application Family Identifier of TYPE B Tag Discovered */ - uint8_t MaxDataRate; /**< Maximum data rate supported by the TYPE B Tag Discovered */ -} net_nfc_sIso14443BInfo_t; - -/** \ingroup grp_hal_nfci - * - * \brief Remote Device Reader B prime RF Gate Information Container - * - */ -typedef struct _net_nfc_sIso14443BPrimeInfo_t -{ - void *BPrimeCtxt; -} net_nfc_sIso14443BPrimeInfo_t; - -/** \ingroup grp_hal_nfci - * - * \brief Remote Device Jewel Reader RF Gate Information Container - * - * The Jewel Reader structure includes the available information - * related to the discovered Jewel remote device. This information - * is updated for every device discovery. - * \note None. - * - */ -typedef struct _net_nfc_sJewelInfo_t -{ - uint8_t Uid[NET_NFC_MAX_UID_LENGTH]; /**< UID information of the TYPE A Tag Discovered */ - uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_MAX_UID_LENGTH i.e., 10 */ - uint8_t HeaderRom0; /**< Header Rom byte zero */ - uint8_t HeaderRom1; /**< Header Rom byte one */ - -} net_nfc_sJewelInfo_t; - -/** \ingroup grp_hal_nfci - * - * \brief Remote Device Felica Reader RF Gate Information Container - * - * The Felica Reader structure includes the available information - * related to the discovered Felica remote device. This information - * is updated for every device discovery. - * \note None. - * - */ -typedef struct _net_nfc_sFelicaInfo_t -{ - uint8_t IDm[(NET_NFC_FEL_ID_LEN + 2)]; /**< Current ID of Felica tag */ - uint8_t IDmLength; /**< IDm length, shall not be greater than NET_NFC_FEL_ID_LEN i.e., 8 */ - uint8_t PMm[NET_NFC_FEL_PM_LEN]; /**< Current PM of Felica tag */ - uint8_t SystemCode[NET_NFC_FEL_SYS_CODE_LEN]; /**< System code of Felica tag */ -} net_nfc_sFelicaInfo_t; - -/** \ingroup grp_hal_nfci - * - * \brief Remote Device Reader 15693 RF Gate Information Container - * - * The Reader A structure includes the available information - * related to the discovered ISO15693 remote device. This information - * is updated for every device discovery. - * \note None. - * - */ - -typedef struct _net_nfc_sIso15693Info_t -{ - uint8_t Uid[NET_NFC_15693_UID_LENGTH]; /**< UID information of the 15693 Tag Discovered */ - uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_15693_UID_LENGTH i.e., 8 */ - uint8_t Dsfid; /**< DSF information of the 15693 Tag Discovered */ - uint8_t Flags; /**< Information about the Flags in the 15693 Tag Discovered */ - uint8_t Afi; /**< Application Family Identifier of 15693 Tag Discovered */ -} net_nfc_sIso15693Info_t; - -/** \ingroup grp_hal_nfci - * - * \brief NFC Data Rate Supported between the Reader and the Target - * - * The \ref Halnet_nfc_eDataRate enum lists all the Data Rate - * values to be used to determine the rate at which the data is transmitted - * to the target. - * - * \note None. - */ - -/** \ingroup grp_hal_nfci - * - * \brief NFCIP1 Data rates - * - */ -typedef enum net_nfc_eDataRate_t -{ - net_nfc_eDataRate_106 = 0x00U, - net_nfc_eDataRate_212, - net_nfc_eDataRate_424, - net_nfc_eDataRate_RFU -} net_nfc_eDataRate_t; - -/** \ingroup grp_hal_nfci - * - * \brief NFCIP1 Gate Information Container - * - * The NFCIP1 structure includes the available information - * related to the discovered NFCIP1 remote device. This information - * is updated for every device discovery. - * \note None. - * - */ -typedef struct _net_nfc_sNfcIPInfo_t -{ - /* Contains the random NFCID3I conveyed with the ATR_REQ. - always 10 bytes length - or contains the random NFCID3T conveyed with the ATR_RES. - always 10 bytes length */ - uint8_t NFCID[NET_NFC_MAX_UID_LENGTH]; - uint8_t NFCID_Length; - /* ATR_RES = General bytes length, Max length = 48 bytes */ - uint8_t ATRInfo[NET_NFC_MAX_ATR_LENGTH]; - uint8_t ATRInfo_Length; - /**< SAK information of the tag discovered */ - uint8_t SelRes; - /**< ATQA information of the tag discovered */ - uint8_t SenseRes[NET_NFC_ATQA_LENGTH]; - /**< Is Detection Mode of the NFCIP Target Active */ - uint8_t nfcip_Active; - /**< Maximum frame length supported by the NFCIP device */ - uint16_t MaxFrameLength; - /**< Data rate supported by the NFCIP device */ - net_nfc_eDataRate_t nfcip_Datarate; - -} net_nfc_sNfcIPInfo_t; - -typedef union net_nfc_remoteDevInfo_t -{ - net_nfc_sIso14443AInfo_t Iso14443A_Info; - net_nfc_sIso14443BInfo_t Iso14443B_Info; - net_nfc_sIso14443BPrimeInfo_t Iso14443BPrime_Info; - net_nfc_sNfcIPInfo_t NfcIP_Info; - net_nfc_sFelicaInfo_t Felica_Info; - net_nfc_sJewelInfo_t Jewel_Info; - net_nfc_sIso15693Info_t Iso15693_Info; -} net_nfc_remoteDevInfo_t; - -typedef struct _net_nfc_tag_info_s -{ - char *key; - data_h value; -} net_nfc_tag_info_s; - -typedef struct _net_nfc_target_info_s -{ - net_nfc_target_handle_s *handle; - net_nfc_target_type_e devType; - uint8_t is_ndef_supported; - uint8_t ndefCardState; - uint32_t maxDataSize; - uint32_t actualDataSize; - int number_of_keys; - net_nfc_tag_info_s *tag_info_list; - char **keylist; - data_s raw_data; -} net_nfc_target_info_s; - -typedef enum _net_nfc_secure_element_type_e -{ - SECURE_ELEMENT_TYPE_INVALID = 0x00, /**< Indicates SE type is Invalid */ - SECURE_ELEMENT_TYPE_ESE = 0x01, /**< Indicates SE type is SmartMX */ - SECURE_ELEMENT_TYPE_UICC = 0x02, /** "net_nfc_close_llcp_socket" request is completed */ - NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE, - NET_NFC_MESSAGE_SERVICE_WATCH_DOG, - NET_NFC_MESSAGE_SERVICE_CLEANER, - NET_NFC_MESSAGE_SERVICE_SET_LAUNCH_STATE, -} net_nfc_message_service_e; - -typedef enum _net_nfc_se_command_e -{ - NET_NFC_SE_CMD_UICC_ON = 0, - NET_NFC_SE_CMD_ESE_ON, - NET_NFC_SE_CMD_ALL_OFF, - NET_NFC_SE_CMD_ALL_ON, -} net_nfc_se_command_e; - -/* connection handover info */ - -typedef enum -{ - NET_NFC_CONN_HANDOVER_ERR_REASON_RESERVED = 0x00, - NET_NFC_CONN_HANDOVER_ERR_REASON_TEMP_MEM_CONSTRAINT, - NET_NFC_CONN_HANDOVER_ERR_REASON_PERM_MEM_CONSTRAINT, - NET_NFC_CONN_HANDOVER_ERR_REASON_CARRIER_SPECIFIC_CONSTRAINT, -} net_nfc_conn_handover_error_reason_e; - -/* WIFI Info */ -typedef struct _net_nfc_carrier_property_s -{ - bool is_group; - uint16_t attribute; - uint16_t length; - void *data; -} net_nfc_carrier_property_s; - -typedef struct _net_nfc_carrier_config_s -{ - net_nfc_conn_handover_carrier_type_e type; - int length; - struct _GList *data; -} net_nfc_carrier_config_s; - -typedef struct _net_nfc_sub_field_s -{ - uint16_t length; - uint8_t value[0]; -} -__attribute__((packed)) net_nfc_sub_field_s; - -typedef struct _net_nfc_signature_record_s -{ - uint8_t version; - uint8_t sign_type : 7; - uint8_t uri_present : 1; - net_nfc_sub_field_s signature; -} -__attribute__((packed)) net_nfc_signature_record_s; - -typedef struct _net_nfc_certificate_chain_s -{ - uint8_t num_of_certs : 4; - uint8_t cert_format : 3; - uint8_t uri_present : 1; - uint8_t cert_store[0]; -} -__attribute__((packed)) net_nfc_certificate_chain_s; - -#define SMART_POSTER_RECORD_TYPE "Sp" -#define URI_RECORD_TYPE "U" -#define TEXT_RECORD_TYPE "T" -#define GC_RECORD_TYPE "Gc" -#define SIGNATURE_RECORD_TYPE "Sig" -#define CONN_HANDOVER_REQ_RECORD_TYPE "Hr" -#define CONN_HANDOVER_SEL_RECORD_TYPE "Hs" -#define CONN_HANDOVER_CAR_RECORD_TYPE "Hc" -#define COLLISION_DETECT_RECORD_TYPE "cr" -#define ALTERNATIVE_RECORD_TYPE "ac" -#define ERROR_RECORD_TYPE "err" - -#define URI_SCHEM_FILE "file://" - -#define UICC_TARGET_HANDLE 0xFF - - -#endif diff --git a/src/commonlib/include/net_nfc_util_defines.h b/src/commonlib/include/net_nfc_util_defines.h new file mode 100755 index 0000000..500a03c --- /dev/null +++ b/src/commonlib/include/net_nfc_util_defines.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#endif //__NET_NFC_UTIL_DEFINES_H__ diff --git a/src/commonlib/include/net_nfc_util_gdbus_internal.h b/src/commonlib/include/net_nfc_util_gdbus_internal.h new file mode 100644 index 0000000..0d7d682 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_gdbus_internal.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#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); + +ndef_message_s *net_nfc_util_gdbus_variant_to_ndef_message(GVariant *variant); + +GVariant *net_nfc_util_gdbus_ndef_message_to_variant( + const ndef_message_s *message); + +#endif //__NET_NFC_UTIL_GDBUS_INTERNAL_H__ diff --git a/src/commonlib/include/net_nfc_util_handover.h b/src/commonlib/include/net_nfc_util_handover.h new file mode 100755 index 0000000..a901d98 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_handover.h @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 /* assign connection handover service access point */ + +#define CH_REQ_RECORD_TYPE "Hr" +#define CH_REQ_RECORD_TYPE_LEN 2 +#define CH_SEL_RECORD_TYPE "Hs" +#define CH_SEL_RECORD_TYPE_LEN 2 +#define CH_CAR_RECORD_TYPE "Hc" +#define CH_CAR_RECORD_TYPE_LEN 2 +#define CH_MED_RECORD_TYPE "Hm" +#define CH_MED_RECORD_TYPE_LEN 2 +#define CH_INI_RECORD_TYPE "Hi" +#define CH_INI_RECORD_TYPE_LEN 2 +#define CH_CR_RECORD_TYPE "cr" +#define CH_CR_RECORD_TYPE_LEN 2 +#define CH_AC_RECORD_TYPE "ac" +#define CH_AC_RECORD_TYPE_LEN 2 +#define CH_ERR_RECORD_TYPE "err" +#define CH_ERR_RECORD_TYPE_LEN 3 + +#define CH_WIFI_WPS_MIME "application/vnd.wfa.wsc" +#define CH_WIFI_WPS_MIME_LEN 23 +#define CH_WIFI_BSS_MIME CH_WIFI_WPS_MIME +#define CH_WIFI_P2P_MIME "application/vnd.wfa.p2p" +#define CH_WIFI_P2P_MIME_LEN 23 +#define CH_WIFI_IBSS_MIME CH_WIFI_P2P_MIME +#define CH_WIFI_DIRECT_MIME CH_WIFI_P2P_MIME + +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; + uint32_t length; + struct _GNode *data; +} net_nfc_carrier_config_s; + + +typedef enum +{ + NET_NFC_CH_TYPE_UNKNOWN, + NET_NFC_CH_TYPE_REQUEST, + NET_NFC_CH_TYPE_SELECT, + NET_NFC_CH_TYPE_MEDIATION, + NET_NFC_CH_TYPE_INITIAITE, + NET_NFC_CH_TYPE_MAX, +} +net_nfc_ch_type_e; + +typedef struct _net_nfc_ch_carrier_s +{ + net_nfc_conn_handover_carrier_type_e type; + net_nfc_conn_handover_carrier_state_e cps; + ndef_record_s *carrier_record; + struct _GList *aux_records; +} +net_nfc_ch_carrier_s; + +typedef struct _net_nfc_ch_message_s +{ + net_nfc_ch_type_e type; + uint8_t version; + uint16_t cr; + struct _GList *carriers; +} +net_nfc_ch_message_s; + +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, uint16_t attribute, + 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_create_carrier_config_from_carrier( + net_nfc_carrier_config_s **config, net_nfc_ch_carrier_s *carrier); + +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_create_handover_carrier( + net_nfc_ch_carrier_s **carrier, + net_nfc_conn_handover_carrier_state_e cps); + +net_nfc_error_e net_nfc_util_duplicate_handover_carrier( + net_nfc_ch_carrier_s **dest, + net_nfc_ch_carrier_s *src); + +net_nfc_error_e net_nfc_util_free_handover_carrier( + net_nfc_ch_carrier_s *carrier); + +net_nfc_error_e net_nfc_util_set_handover_carrier_cps( + net_nfc_ch_carrier_s *carrier, + net_nfc_conn_handover_carrier_state_e cps); + +net_nfc_error_e net_nfc_util_get_handover_carrier_cps( + net_nfc_ch_carrier_s *carrier, + net_nfc_conn_handover_carrier_state_e *cps); + +net_nfc_error_e net_nfc_util_set_handover_carrier_type( + net_nfc_ch_carrier_s *carrier, + net_nfc_conn_handover_carrier_type_e type); + +net_nfc_error_e net_nfc_util_get_handover_carrier_type( + net_nfc_ch_carrier_s *carrier, + net_nfc_conn_handover_carrier_type_e *type); + +net_nfc_error_e net_nfc_util_append_handover_carrier_record( + net_nfc_ch_carrier_s *carrier, ndef_record_s *record); + +net_nfc_error_e net_nfc_util_get_handover_carrier_record( + net_nfc_ch_carrier_s *carrier, ndef_record_s **record); + +net_nfc_error_e net_nfc_util_remove_handover_carrier_record( + net_nfc_ch_carrier_s *carrier); + +net_nfc_error_e net_nfc_util_append_handover_auxiliary_record( + net_nfc_ch_carrier_s *carrier, ndef_record_s *record); + +net_nfc_error_e net_nfc_util_get_handover_auxiliary_record_count( + net_nfc_ch_carrier_s *carrier, uint32_t *count); + +net_nfc_error_e net_nfc_util_get_handover_auxiliary_record( + net_nfc_ch_carrier_s *carrier, int index, ndef_record_s **record); + +net_nfc_error_e net_nfc_util_remove_handover_auxiliary_record( + net_nfc_ch_carrier_s *carrier, ndef_record_s *record); + + +net_nfc_error_e net_nfc_util_create_handover_message( + net_nfc_ch_message_s **message); + +net_nfc_error_e net_nfc_util_free_handover_message( + net_nfc_ch_message_s *message); + +net_nfc_error_e net_nfc_util_set_handover_message_type( + net_nfc_ch_message_s *message, net_nfc_ch_type_e type); + +net_nfc_error_e net_nfc_util_get_handover_message_type( + net_nfc_ch_message_s *message, net_nfc_ch_type_e *type); + +net_nfc_error_e net_nfc_util_get_handover_random_number( + net_nfc_ch_message_s *message, uint16_t *random_number); + +net_nfc_error_e net_nfc_util_append_handover_carrier( + net_nfc_ch_message_s *message, net_nfc_ch_carrier_s *carrier); + +net_nfc_error_e net_nfc_util_get_handover_carrier_count( + net_nfc_ch_message_s *message, uint32_t *count); + +net_nfc_error_e net_nfc_util_get_handover_carrier( + net_nfc_ch_message_s *message, int index, + net_nfc_ch_carrier_s **carrier); + +net_nfc_error_e net_nfc_util_get_handover_carrier_by_type( + net_nfc_ch_message_s *message, + net_nfc_conn_handover_carrier_type_e type, + net_nfc_ch_carrier_s **carrier); + + +net_nfc_error_e net_nfc_util_export_handover_to_ndef_message( + net_nfc_ch_message_s *message, ndef_message_s **result); + +net_nfc_error_e net_nfc_util_import_handover_from_ndef_message( + ndef_message_s *msg, net_nfc_ch_message_s **result); + +net_nfc_error_e net_nfc_util_get_handover_random_number( + net_nfc_ch_message_s *message, uint16_t *random_number); + +net_nfc_error_e net_nfc_util_get_selector_power_status( + net_nfc_ch_message_s *message, + net_nfc_conn_handover_carrier_state_e *cps); + +#ifdef __cplusplus +} +#endif + +#endif //__NET_NFC_UTIL_HANDOVER_H__ diff --git a/src/commonlib/include/net_nfc_util_handover_internal.h b/src/commonlib/include/net_nfc_util_handover_internal.h new file mode 100755 index 0000000..9eea854 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_handover_internal.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_INTERNAL_H__ +#define __NET_NFC_UTIL_HANDOVER_INTERNAL_H__ + +#include "net_nfc_typedef_internal.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* Bluetooth */ +bool net_nfc_util_handover_bt_check_carrier_record(ndef_record_s *record); + +net_nfc_error_e net_nfc_util_handover_bt_create_record_from_config( + ndef_record_s **record, net_nfc_carrier_config_s *config); + +net_nfc_error_e net_nfc_util_handover_bt_create_config_from_record( + net_nfc_carrier_config_s **config, ndef_record_s *record); + + +/* Wifi protected setup */ +bool net_nfc_util_handover_wps_check_carrier_record(ndef_record_s *record); + +net_nfc_error_e net_nfc_util_handover_wps_create_record_from_config( + ndef_record_s **record, net_nfc_carrier_config_s *config); + +net_nfc_error_e net_nfc_util_handover_wps_create_config_from_record( + net_nfc_carrier_config_s **config, ndef_record_s *record); + +/* Wifi direct setup */ +bool net_nfc_util_handover_wfd_check_carrier_record(ndef_record_s *record); + +net_nfc_error_e net_nfc_util_handover_wfd_create_record_from_config( + ndef_record_s **record, net_nfc_carrier_config_s *config); + +net_nfc_error_e net_nfc_util_handover_wfd_create_config_from_record( + net_nfc_carrier_config_s **config, ndef_record_s *record); + +#ifdef __cplusplus +} +#endif + +#endif //__NET_NFC_UTIL_HANDOVER_INTERNAL_H__ diff --git a/src/commonlib/include/net_nfc_util_hce.h b/src/commonlib/include/net_nfc_util_hce.h new file mode 100644 index 0000000..b1f7c81 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_hce.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_HCE_H__ +#define __NET_NFC_UTIL_HCE_H__ + +#include "net_nfc_typedef_internal.h" + +#define NET_NFC_HCE_INS_SELECT (uint8_t)0xA4 +#define NET_NFC_HCE_INS_READ_BINARY (uint8_t)0xB0 +#define NET_NFC_HCE_INS_UPDATE_BINARY (uint8_t)0xD6 + +#define NET_NFC_HCE_P1_SELECT_BY_FID (uint8_t)0x00 +#define NET_NFC_HCE_P1_SELECT_BY_NAME (uint8_t)0x04 + +#define NET_NFC_HCE_P2_SELECT_FIRST_OCC (uint8_t)0x0C + + +#define NET_NFC_HCE_SW_SUCCESS (uint16_t)0x9000 +#define NET_NFC_HCE_SW_SUCCESS (uint16_t)0x9000 + +#define NET_NFC_HCE_SW_WRONG_LENGTH (uint16_t)0x6700 +#define NET_NFC_HCE_SW_COMMAND_NOT_ALLOWED (uint16_t)0x6900 +#define NET_NFC_HCE_SW_SECURITY_FAILED (uint16_t)0x6982 +#define NET_NFC_HCE_SW_FUNC_NOT_SUPPORTED (uint16_t)0x6A81 +#define NET_NFC_HCE_SW_FILE_NOT_FOUND (uint16_t)0x6A82 +#define NET_NFC_HCE_SW_INCORRECT_P1_TO_P2 (uint16_t)0x6A86 +#define NET_NFC_HCE_SW_LC_INCONSIST_P1_TO_P2 (uint16_t)0x6A87 +#define NET_NFC_HCE_SW_REF_DATA_NOT_FOUND (uint16_t)0x6A88 +#define NET_NFC_HCE_SW_WRONG_PARAMETER (uint16_t)0x6B00 +#define NET_NFC_HCE_SW_INS_NOT_SUPPORTED (uint16_t)0x6D00 +#define NET_NFC_HCE_SW_CLASS_NOT_SUPPORTED (uint16_t)0x6E00 + +#define NET_NFC_HCE_INVALID_VALUE (uint16_t)0xFFFF + +typedef struct _net_nfc_apdu_data_t +{ + uint16_t cla; + uint16_t ins; + uint16_t p1; + uint16_t p2; + uint16_t lc; + uint8_t *data; + uint16_t le; +} +net_nfc_apdu_data_t; + + +net_nfc_apdu_data_t *net_nfc_util_hce_create_apdu_data(); + +void net_nfc_util_hce_free_apdu_data(net_nfc_apdu_data_t *apdu_data); + +net_nfc_error_e net_nfc_util_hce_extract_parameter(data_s *apdu, + net_nfc_apdu_data_t *apdu_data); + +net_nfc_error_e net_nfc_util_hce_generate_apdu(net_nfc_apdu_data_t *apdu_data, + data_s **apdu); + +#endif //__NET_NFC_UTIL_HCE_H__ diff --git a/src/commonlib/include/net_nfc_util_internal.h b/src/commonlib/include/net_nfc_util_internal.h new file mode 100755 index 0000000..06f5f94 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_internal.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 +#include +#include + +#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__) + +data_s *net_nfc_util_create_data(uint32_t length); +bool net_nfc_util_init_data(data_s *data, uint32_t length); +data_s *net_nfc_util_duplicate_data(data_s *src); +bool net_nfc_util_append_data(data_s *dest, data_s *src); +void net_nfc_util_clear_data(data_s *data); +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); + +uint32_t net_nfc_util_create_memory_handle(void *address); +void *net_nfc_util_get_memory_address(uint32_t handle); +void net_nfc_util_destroy_memory_handle(uint32_t handle); + + +bool net_nfc_util_aid_check_validity(const char *aid); +bool net_nfc_util_aid_is_prefix(const char *aid); +bool net_nfc_util_aid_is_matched(const char *aid_criteria, + const char *aid_target); + +bool net_nfc_util_get_pkgid_by_pid(pid_t pid, char *pkgid, size_t len); + +bool net_nfc_util_hex_string_to_binary(const char *str, data_s *result); +bool net_nfc_util_binary_to_hex_string(data_s *data, char *out_buf, uint32_t max_len); + + +#endif //__NET_NFC_UTIL_INTERNAL_H__ diff --git a/src/commonlib/include/net_nfc_util_ndef_message.h b/src/commonlib/include/net_nfc_util_ndef_message.h new file mode 100755 index 0000000..6bd2ee5 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_ndef_message.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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. */ + +typedef void (*net_nfc_foreach_ndef_records_cb)(ndef_record_s *record, + void *user_data); +/* + 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); + +void net_nfc_util_foreach_ndef_records(ndef_message_s *msg, + net_nfc_foreach_ndef_records_cb func, void *user_data); + +net_nfc_error_e net_nfc_util_check_ndef_message_rawdata(data_s *rawdata); + +#endif //__NET_NFC_UTIL_NDEF_MESSAGE_H__ diff --git a/src/commonlib/include/net_nfc_util_ndef_record.h b/src/commonlib/include/net_nfc_util_ndef_record.h new file mode 100755 index 0000000..a16a938 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_ndef_record.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ diff --git a/src/commonlib/include/net_nfc_util_openssl_internal.h b/src/commonlib/include/net_nfc_util_openssl_internal.h new file mode 100755 index 0000000..28aa669 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_openssl_internal.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +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__ diff --git a/src/commonlib/include/net_nfc_util_private.h b/src/commonlib/include/net_nfc_util_private.h deleted file mode 100644 index 6967411..0000000 --- a/src/commonlib/include/net_nfc_util_private.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __NET_NFC_UTIL_H__ -#define __NET_NFC_UTIL_H__ - -#include -#include -#include - -#include "net_nfc_typedef_private.h" - -#define NET_NFC_REVERSE_ORDER_6_BYTES(__array) \ - do \ - { \ - uint16_t __x = htons(*(uint16_t *)(__array + 4)); \ - *(uint32_t *)(__array + 2) = htonl(*(uint32_t *)(__array)); \ - *(uint16_t *)(__array) = __x; \ - } while (0); - -#define NET_NFC_REVERSE_ORDER_16_BYTES(array) \ - do \ - { \ - uint32_t __x1 = htonl(*(uint32_t *)(array + 12)); \ - uint32_t __x2 = htonl(*(uint32_t *)(array + 8)); \ - *(uint32_t *)(array + 8) = htonl(*(uint32_t *)(array + 4)); \ - *(uint32_t *)(array + 12) = htonl(*(uint32_t *)(array)); \ - *(uint32_t *)(array) = __x1; \ - *(uint32_t *)(array + 4) = __x2; \ - } while (0); - - -typedef enum -{ - CRC_A = 0x00, - CRC_B, -} CRC_type_e; - -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); - -void net_nfc_util_mem_free_detail_msg(int msg_type, int message, void *data); - -net_nfc_conn_handover_carrier_state_e net_nfc_util_get_cps(net_nfc_conn_handover_carrier_type_e carrier_type); - -uint8_t *net_nfc_util_get_local_bt_address(); -void net_nfc_util_enable_bluetooth(void); - -bool net_nfc_util_strip_string(char *buffer, int buffer_length); - -void net_nfc_util_compute_CRC(CRC_type_e CRC_type, uint8_t *buffer, uint32_t length); - -const char *net_nfc_util_get_schema_string(int index); - -#endif diff --git a/src/commonlib/include/net_nfc_util_sign_record.h b/src/commonlib/include/net_nfc_util_sign_record.h new file mode 100755 index 0000000..f0bd3a8 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_sign_record.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ + diff --git a/src/commonlib/net_nfc.xml b/src/commonlib/net_nfc.xml new file mode 100755 index 0000000..e40d822 --- /dev/null +++ b/src/commonlib/net_nfc.xml @@ -0,0 +1,856 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/commonlib/net_nfc_util.c b/src/commonlib/net_nfc_util.c index 86c0ccd..c185c1e 100644 --- a/src/commonlib/net_nfc_util.c +++ b/src/commonlib/net_nfc_util.c @@ -19,14 +19,17 @@ #include #include #include +#include // platform header +#include "aul.h" +#include "pkgmgr-info.h" #include #include // nfc-manager header -#include "net_nfc_util_private.h" -#include "net_nfc_debug_private.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_debug_internal.h" #include "net_nfc_oem_controller.h" #include "net_nfc_util_defines.h" @@ -82,7 +85,7 @@ static uint8_t *bt_addr = NULL; #define NET_NFC_MANAGER_NAME "nfc-manager-daemon" static const char *log_tag = LOG_CLIENT_TAG; extern char *__progname; -FILE *nfc_log_file = NULL; +FILE *nfc_log_file; const char *net_nfc_get_log_tag() { @@ -103,6 +106,7 @@ void __attribute__ ((destructor)) lib_fini() void net_nfc_manager_init_log() { + struct tm *local_tm; nfc_log_file = fopen(NFC_DLOG_FILE, "a+"); if (nfc_log_file != NULL) { @@ -110,10 +114,15 @@ void net_nfc_manager_init_log() 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); + local_tm = localtime(&rawtime); + + if(local_tm != NULL) + { + strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", local_tm); + fprintf(nfc_log_file, "\n%s",timeBuf); + fprintf(nfc_log_file, "========== log begin, pid [%d] =========", getpid()); + fflush(nfc_log_file); + } } else { @@ -123,18 +132,24 @@ void net_nfc_manager_init_log() void net_nfc_manager_fini_log() { + struct tm *local_tm; 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; + local_tm = localtime(&rawtime); + + if(local_tm != NULL) + { + strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", local_tm); + 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; + } } } @@ -142,17 +157,17 @@ NET_NFC_EXPORT_API void __net_nfc_util_free_mem(void **mem, char *filename, unsi { if (mem == NULL) { - DEBUG_MSG("FILE: %s, LINE:%d, Invalid parameter in mem free util, mem is NULL", filename, line); + SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in mem free util, mem is NULL", filename, line); return; } if (*mem == NULL) { - DEBUG_MSG("FILE: %s, LINE:%d, Invalid Parameter in mem free util, *mem is NULL", filename, line); + SECURE_LOGD("FILE: %s, LINE:%d, Invalid Parameter in mem free util, *mem is NULL", filename, line); return; } - free(*mem); + g_free(*mem); *mem = NULL; } @@ -160,20 +175,20 @@ NET_NFC_EXPORT_API void __net_nfc_util_alloc_mem(void **mem, int size, char *fil { if (mem == NULL || size <= 0) { - DEBUG_MSG("FILE: %s, LINE:%d, Invalid parameter in mem alloc util, mem [%p], size [%d]", filename, line, mem, size); + SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in mem alloc util, mem [%p], size [%d]", filename, line, mem, size); return; } if (*mem != NULL) { - DEBUG_MSG("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *mem); + SECURE_LOGD("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *mem); } - *mem = calloc(1, size); + *mem = g_malloc0(size); if (*mem == NULL) { - DEBUG_ERR_MSG("FILE: %s, LINE:%d, Allocation is failed, size [%d]", filename, line, size); + SECURE_LOGD("FILE: %s, LINE:%d, Allocation is failed, size [%d]", filename, line, size); } } @@ -181,24 +196,36 @@ NET_NFC_EXPORT_API void __net_nfc_util_strdup(char **output, const char *origin, { if (output == NULL || origin == NULL) { - DEBUG_MSG("FILE: %s, LINE:%d, Invalid parameter in strdup, output [%p], origin [%p]", filename, line, output, origin); + SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in strdup, output [%p], origin [%p]", filename, line, output, origin); return; } if (*output != NULL) { - DEBUG_MSG("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *output); + SECURE_LOGD("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *output); } - *output = strdup(origin); + *output = g_strdup(origin); if (*output == NULL) { - DEBUG_ERR_MSG("FILE: %s, LINE:%d, strdup failed", filename, line); + 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) +NET_NFC_EXPORT_API data_s *net_nfc_util_create_data(uint32_t length) +{ + data_s *data; + + _net_nfc_util_alloc_mem(data, sizeof(*data)); + if (length > 0) { + net_nfc_util_init_data(data, length); + } + + return data; +} + +NET_NFC_EXPORT_API bool net_nfc_util_init_data(data_s *data, uint32_t length) { if (data == NULL || length == 0) return false; @@ -212,91 +239,66 @@ NET_NFC_EXPORT_API bool net_nfc_util_alloc_data(data_s *data, uint32_t length) return true; } -NET_NFC_EXPORT_API bool net_nfc_util_duplicate_data(data_s *dest, net_nfc_data_s *src) +NET_NFC_EXPORT_API data_s *net_nfc_util_duplicate_data(data_s *src) { - if (dest == NULL || src == NULL || src->length == 0) - return false; + data_s *data; - if (net_nfc_util_alloc_data(dest, src->length) == false) + if (src == NULL || src->length == 0) return false; - memcpy(dest->buffer, src->buffer, dest->length); + data = net_nfc_util_create_data(src->length); + if (data != NULL) { + memcpy(data->buffer, src->buffer, data->length); + } - return true; + return data; } -NET_NFC_EXPORT_API void net_nfc_util_free_data(data_s *data) +NET_NFC_EXPORT_API bool net_nfc_util_append_data(data_s *dest, data_s *src) { - if (data == NULL || data->buffer == NULL) - return; + data_s *data; + + if (dest == NULL || src == NULL || src->length == 0) + return false; + + data = net_nfc_util_create_data(dest->length + src->length); + if (data != NULL) { + if (dest->length > 0) { + memcpy(data->buffer, dest->buffer, dest->length); + } + memcpy(data->buffer + dest->length, src->buffer, src->length); - _net_nfc_util_free_mem(data->buffer); + net_nfc_util_clear_data(dest); + net_nfc_util_init_data(dest, data->length); + memcpy(dest->buffer, data->buffer, data->length); + + net_nfc_util_free_data(data); + } + + return true; } -NET_NFC_EXPORT_API void net_nfc_util_mem_free_detail_msg(int msg_type, int message, void *data) +NET_NFC_EXPORT_API void net_nfc_util_clear_data(data_s *data) { if (data == NULL) return; - if (msg_type == NET_NFC_UTIL_MSG_TYPE_REQUEST) - { - _net_nfc_util_free_mem(data); + if (data->buffer != NULL) { + _net_nfc_util_free_mem(data->buffer); + data->buffer = NULL; } - else if (msg_type == NET_NFC_UTIL_MSG_TYPE_RESPONSE) - { - switch (message) - { - case NET_NFC_MESSAGE_READ_NDEF : - { - net_nfc_response_read_ndef_t *msg = (net_nfc_response_read_ndef_t *)data; - _net_nfc_util_free_mem(msg->data.buffer); - } - break; - case NET_NFC_MESSAGE_TRANSCEIVE : - { - net_nfc_response_transceive_t *msg = (net_nfc_response_transceive_t *)data; - _net_nfc_util_free_mem(msg->data.buffer); - } - break; - case NET_NFC_MESSAGE_TAG_DISCOVERED : - { - net_nfc_response_tag_discovered_t *msg = (net_nfc_response_tag_discovered_t *)data; - _net_nfc_util_free_mem(msg->target_info_values.buffer); - _net_nfc_util_free_mem(msg->raw_data.buffer); - } - break; - case NET_NFC_MESSAGE_LLCP_RECEIVE : - { - net_nfc_response_receive_socket_t *msg = (net_nfc_response_receive_socket_t *)data; - _net_nfc_util_free_mem(msg->data.buffer); - } - break; - - case NET_NFC_MESSAGE_P2P_RECEIVE : - { - net_nfc_response_p2p_receive_t *msg = (net_nfc_response_p2p_receive_t *)data; - _net_nfc_util_free_mem(msg->data.buffer); - } - break; + data->length = 0; +} - case NET_NFC_MESSAGE_SEND_APDU_SE : - { - net_nfc_response_send_apdu_t *msg = (net_nfc_response_send_apdu_t *)data; - _net_nfc_util_free_mem(msg->data.buffer); - } - break; +NET_NFC_EXPORT_API void net_nfc_util_free_data(data_s *data) +{ + if (data == NULL) + return; - default : - break; - } + net_nfc_util_clear_data(data); - _net_nfc_util_free_mem(data); - } - else - { - DEBUG_MSG("unknown message type"); - } + _net_nfc_util_free_mem(data); } net_nfc_conn_handover_carrier_state_e net_nfc_util_get_cps(net_nfc_conn_handover_carrier_type_e carrier_type) @@ -349,6 +351,9 @@ net_nfc_conn_handover_carrier_state_e net_nfc_util_get_cps(net_nfc_conn_handover return cps; } +#define BLUETOOTH_ADDRESS_LENGTH 6 +#define HIDDEN_BT_ADDR_FILE "/opt/etc/.bd_addr" + uint8_t *net_nfc_util_get_local_bt_address() { if (bt_addr != NULL) @@ -504,3 +509,247 @@ const char *net_nfc_util_get_schema_string(int index) else return schema[index]; } + +#define MAX_HANDLE 65535 +#define NEXT_HANDLE(__x) ((__x) == MAX_HANDLE ? 1 : ((__x) + 1)) + +static uint32_t next_handle = 1; +static GHashTable *handle_table; + +static void *_get_memory_address(uint32_t handle) +{ + return g_hash_table_lookup(handle_table, + (gconstpointer)handle); +} + +uint32_t net_nfc_util_create_memory_handle(void *address) +{ + uint32_t handle; + + if (handle_table == NULL) { + handle_table = g_hash_table_new(g_int_hash, g_int_equal); + } + + g_assert(g_hash_table_size(handle_table) < MAX_HANDLE); + + g_hash_table_insert(handle_table, (gpointer)next_handle, + (gpointer)address); + + handle = next_handle; + + /* find next available handle */ + do { + next_handle = NEXT_HANDLE(next_handle); + } while (_get_memory_address(next_handle) != NULL); + + return handle; +} + +void *net_nfc_util_get_memory_address(uint32_t handle) +{ + void *address; + + if (handle_table == NULL || handle == 0 || handle > MAX_HANDLE) + return NULL; + + address = _get_memory_address(handle); + + return address; +} + +void net_nfc_util_destroy_memory_handle(uint32_t handle) +{ + if (handle_table == NULL || handle == 0 || handle > MAX_HANDLE) + return; + + g_hash_table_remove(handle_table, (gconstpointer)handle); +} + +#define IS_HEX(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'A' && (c) <= 'F') || \ + ((c) >= 'a' && (c) <= 'f')) + +bool net_nfc_util_aid_check_validity(const char *aid) +{ + const char *temp = aid; + bool asterisk = false; + + if (aid == NULL || strlen(aid) == 0) { + return false; + } + + while (*temp != '\0') { + if (asterisk == true) { + /* asterisk sould be placed at last */ + return false; + } + + if (IS_HEX(*temp) == false) { + if (*temp == '*') { + asterisk = true; + } else { + /* wrong character */ + return false; + } + } + + temp++; + } + + return true; +} + +bool net_nfc_util_aid_is_prefix(const char *aid) +{ + size_t len; + + if (net_nfc_util_aid_check_validity(aid) == false) { + return false; + } + + len = strlen(aid); + + return (aid[len - 1] == '*'); +} + +bool net_nfc_util_aid_is_matched(const char *aid_criteria, + const char *aid_target) +{ + const char *criteria = aid_criteria; + const char *target = aid_target; + bool is_prefix; + bool result; + + if (net_nfc_util_aid_check_validity(criteria) == false) { + return false; + } + + if (net_nfc_util_aid_check_validity(target) == false) { + return false; + } + + is_prefix = net_nfc_util_aid_is_prefix(target); + + while (true) { + if (*criteria == *target) { + if (*criteria == '\0') { + result = true; + break; + } + } else if (*criteria == '*') { + if (is_prefix == true) { + /* different prefix */ + result = false; + break; + } else { + /* prefix matched */ + result = true; + break; + } + } else { + result = false; + break; + } + + criteria++; + target++; + } + + return result; +} + +bool net_nfc_util_get_pkgid_by_pid(pid_t pid, char *pkgid, size_t len) +{ + pkgmgrinfo_appinfo_h appinfo = NULL; + char *temp = NULL; + char package[1024]; + int ret; + bool result = false; + + /* get pkgid id from pid */ + ret = aul_app_get_pkgname_bypid(pid, package, sizeof(package)); + if (ret < 0) { + DEBUG_ERR_MSG("aul_app_get_pkgname_bypid failed [%d]", ret); + + goto END; + } + + ret = pkgmgrinfo_appinfo_get_appinfo(package, &appinfo); + if (ret < 0) { + DEBUG_ERR_MSG("pkgmgrinfo_appinfo_get_appinfo failed, [%d]", ret); + + goto END; + } + + ret = pkgmgrinfo_appinfo_get_pkgid(appinfo, &temp); + if (ret < 0) { + DEBUG_ERR_MSG("pkgmgrinfo_appinfo_get_pkgid failed, [%d]", ret); + + goto END; + } + + result = (snprintf(pkgid, len, "%s", temp) > 0); + +END : + if (appinfo != NULL) { + pkgmgrinfo_appinfo_destroy_appinfo(appinfo); + } + + return result; +} + +#define TO_BINARY(x) (((x) >= '0' && (x) <= '9') ? ((x) - '0') : (((x) >= 'A' && (x) <= 'F') ? ((x) - 'A' + 10) : (((x) >= 'a' && (x) <= 'f') ? ((x) - 'a' + 10) : 0))) + +bool net_nfc_util_hex_string_to_binary(const char *str, data_s *result) +{ + size_t len, i; + + if (str == NULL || result == NULL) { + return false; + } + + len = strlen(str); + if (len < 2) { + return false; + } + + for (i = 0; i < len; i++) { + if (IS_HEX(str[i]) == false) { + return false; + } + } + + len /= 2; + + if (net_nfc_util_init_data(result, len) == false) { + return false; + } + + for (i = 0; i < len; i++) { + result->buffer[i] = TO_BINARY(str[i << 1]) << 4; + result->buffer[i] |= TO_BINARY(str[(i << 1) + 1]); + } + + return true; +} + +bool net_nfc_util_binary_to_hex_string(data_s *data, char *out_buf, uint32_t max_len) +{ + int current = 0; + uint8_t *buffer; + size_t len; + + if (data == NULL || data->buffer == NULL || data->length == 0 || + out_buf == NULL || max_len == 0) + return false; + + buffer = data->buffer; + len = data->length; + + while (len > 0 && current < max_len) { + current += snprintf(out_buf + current, max_len - current, + "%02X", *(buffer++)); + len--; + } + + return true; +} diff --git a/src/commonlib/net_nfc_util_gdbus.c b/src/commonlib/net_nfc_util_gdbus.c new file mode 100755 index 0000000..2e4d5d5 --- /dev/null +++ b/src/commonlib/net_nfc_util_gdbus.c @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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" +#include "net_nfc_util_ndef_message.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; + guint size; + data_s *result = NULL; + + if (variant == NULL) + return result; + + g_variant_get(variant, "a(y)", &iter); + + size = g_variant_iter_n_children(iter); + if (size > 0) { + result = net_nfc_util_create_data(size); + if (result != NULL && result->buffer != NULL) + { + guint i = 0; + guint8 element; + + while (g_variant_iter_loop(iter, "(y)", &element)) + { + *(result->buffer + i) = element; + i++; + } + + g_variant_iter_free(iter); + } + } + + return result; +} + +void net_nfc_util_gdbus_variant_to_data_s(GVariant *variant, data_s *data) +{ + GVariantIter *iter; + guint size; + + 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); + if (size > 0) { + if (net_nfc_util_init_data(data, size) == true) { + guint i = 0; + guint8 element; + + while (g_variant_iter_loop(iter, "(y)", &element)) + { + *(data->buffer + i) = element; + i++; + } + + g_variant_iter_free(iter); + } + } +} + +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); + } +} + +ndef_message_s *net_nfc_util_gdbus_variant_to_ndef_message(GVariant *variant) +{ + ndef_message_s *message = NULL; + data_s data = { NULL, 0 }; + + if (variant == NULL) + return NULL; + + net_nfc_util_gdbus_variant_to_data_s(variant, &data); + + if (data.buffer && data.length > 0) + { + ndef_message_s *temp = NULL; + + if (net_nfc_util_create_ndef_message(&temp) == NET_NFC_OK) { + if (net_nfc_util_convert_rawdata_to_ndef_message( + &data, temp) == NET_NFC_OK) { + message = temp; + } else { + DEBUG_ERR_MSG("net_nfc_create_ndef_message_from_rawdata failed"); + + net_nfc_util_free_ndef_message(temp); + } + } else { + DEBUG_ERR_MSG("net_nfc_util_create_ndef_message failed"); + } + + net_nfc_util_clear_data(&data); + } + + return message; +} + +GVariant *net_nfc_util_gdbus_ndef_message_to_variant( + const ndef_message_s *message) +{ + GVariant *variant = NULL; + data_s temp = { NULL, 0 }; + data_s *data = NULL; + size_t length; + + length = net_nfc_util_get_ndef_message_length( + (ndef_message_s *)message); + if (length > 0) { + if (net_nfc_util_init_data(&temp, length) == true) { + if (net_nfc_util_convert_ndef_message_to_rawdata( + (ndef_message_s *)message, + &temp) == NET_NFC_OK) { + data = &temp; + } else { + DEBUG_ERR_MSG("can not convert ndef_message to rawdata"); + } + } else { + DEBUG_ERR_MSG("net_nfc_util_alloc_data failed"); + } + } else { + DEBUG_ERR_MSG("message length is 0"); + } + + variant = net_nfc_util_gdbus_data_to_variant(data); + + if (data != NULL) + net_nfc_util_clear_data(data); + + return variant; +} diff --git a/src/commonlib/net_nfc_util_handover.c b/src/commonlib/net_nfc_util_handover.c new file mode 100755 index 0000000..9bf08f6 --- /dev/null +++ b/src/commonlib/net_nfc_util_handover.c @@ -0,0 +1,1524 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_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" +#include "net_nfc_util_handover_internal.h" + + +#define CHECK_TYPE(__x, __y) (\ + (__x.length == __y##_LEN) && \ + (memcmp(__x.buffer, __y, __y##_LEN) == 0)) + +static gboolean _find_by_attribute_cb(GNode *node, gpointer data) +{ + net_nfc_carrier_property_s *prop = node->data; + gpointer *temp = data; + gboolean result; + + if (prop != NULL && prop->attribute == (uint16_t)(uint32_t)temp[0]) { + temp[1] = node; + + result = true; + } else { + result = false; + } + + return result; +} + +static GNode *__find_property_by_attribute(GNode *list, + uint16_t attribute) +{ + gpointer context[2]; + + context[0] = (gpointer)(uint32_t)attribute; + context[1] = NULL; + + g_node_traverse(list, G_IN_ORDER, G_TRAVERSE_ALL, + -1, _find_by_attribute_cb, context); + + return (GNode *)context[1]; +} + +static gboolean _destroy_cb(GNode *node, gpointer data) +{ + net_nfc_carrier_property_s *prop = node->data; + + if (prop != NULL) { + if (prop->is_group) { + prop->data = NULL; + } + + _net_nfc_util_free_mem(prop->data); + _net_nfc_util_free_mem(prop); + } + + return false; +} + +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)->data = g_node_new(NULL); + + return NET_NFC_OK; +} + +static net_nfc_error_e _append_tree_node(GNode *root, uint16_t attribute, + uint16_t size, uint8_t *data) +{ + net_nfc_error_e result; + net_nfc_carrier_property_s *elem = NULL; + + _net_nfc_util_alloc_mem(elem, sizeof (net_nfc_carrier_property_s)); + if (elem != NULL) { + _net_nfc_util_alloc_mem(elem->data, size); + if (elem->data != NULL) { + elem->attribute = attribute; + elem->length = size; + elem->is_group = false; + memcpy(elem->data, data, size); + + g_node_append_data(root, elem); + + result = NET_NFC_OK; + } else { + _net_nfc_util_free_mem(elem); + result = NET_NFC_ALLOC_FAIL; + } + + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} + +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) +{ + DEBUG_MSG("ADD property: [ATTRIB:0x%02X, SIZE:%d]", attribute, size); + + if (config == NULL || data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (__find_property_by_attribute(config->data, attribute) != NULL) + { + return NET_NFC_ALREADY_REGISTERED; + } + + return _append_tree_node(config->data, attribute, size, data); +} + +static void _release_tree(GNode *root) +{ + g_node_traverse(root, G_IN_ORDER, G_TRAVERSE_ALL, + -1, _destroy_cb, NULL); + g_node_destroy(root); +} + +net_nfc_error_e net_nfc_util_remove_carrier_config_property( + net_nfc_carrier_config_s *config, uint16_t attribute) +{ + net_nfc_error_e result; + GNode *node; + + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + node = __find_property_by_attribute(config->data, attribute); + if (node != NULL) { + _release_tree(node); + + result = NET_NFC_OK; + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + return result; +} + +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) +{ + GNode *node; + net_nfc_error_e result; + + if (config == NULL || size == NULL || data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + node = __find_property_by_attribute(config->data, attribute); + if (node != NULL) { + net_nfc_carrier_property_s *elem = node->data; + + if (elem->is_group == false) { + *size = elem->length; + *data = elem->data; + + result = NET_NFC_OK; + } else { + *size = 0; + *data = NULL; + + result = NET_NFC_NO_DATA_FOUND; + } + } else { + *size = 0; + *data = NULL; + + result = NET_NFC_NO_DATA_FOUND; + } + + return result; +} + +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 (__find_property_by_attribute(config->data, + group->attribute) != NULL) { + return NET_NFC_ALREADY_REGISTERED; + } + + g_node_append_data(config->data, group); + + 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 (__find_property_by_attribute(config->data, + group->attribute) != NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + net_nfc_util_free_carrier_group(group); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_carrier_config_group( + net_nfc_carrier_config_s *config, + uint16_t attribute, net_nfc_carrier_property_s **group) +{ + GNode *node; + net_nfc_error_e result; + + if (config == NULL || group == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + node = __find_property_by_attribute(config->data, attribute); + if (node != NULL) { + net_nfc_carrier_property_s *temp = node->data; + + if (temp->is_group) { + *group = node->data; + + result = NET_NFC_OK; + } else { + result = NET_NFC_NO_DATA_FOUND; + } + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + return result; +} + +net_nfc_error_e net_nfc_util_free_carrier_config( + net_nfc_carrier_config_s *config) +{ + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _release_tree(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) +{ + net_nfc_carrier_property_s *temp; + net_nfc_error_e result; + + if (group == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _net_nfc_util_alloc_mem(temp, sizeof(net_nfc_carrier_property_s)); + if (temp != NULL) { + (*group)->attribute = attribute; + (*group)->length = 0; + (*group)->is_group = true; + (*group)->data = g_node_new(temp); + + result = NET_NFC_OK; + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} + +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) +{ + 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_attribute(group->data, attribute) != NULL) + { + return NET_NFC_ALREADY_REGISTERED; + } + +// group->length += size + 2 * __net_nfc_get_size_of_attribute(attribute); +// DEBUG_MSG("ADD group completed total length %d", group->length); + + return _append_tree_node((GNode *)group->data, attribute, size, 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) +{ + GNode *node; + net_nfc_error_e result; + + if (group == NULL || size == NULL || data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + node = __find_property_by_attribute((GNode *)(group->data), attribute); + if (node != NULL) { + net_nfc_carrier_property_s *elem = node->data; + + *size = elem->length; + *data = elem->data; + + result = NET_NFC_OK; + } else { + *size = 0; + *data = NULL; + + result = NET_NFC_NO_DATA_FOUND; + } + + return result; +} + +net_nfc_error_e net_nfc_util_remove_carrier_config_group_property( + net_nfc_carrier_property_s *group, uint16_t attribute) +{ + GNode *node; + net_nfc_error_e result; + + if (group == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + node = __find_property_by_attribute((GNode *)(group->data), attribute); + if (node != NULL) { + _release_tree(node); + + result = NET_NFC_OK; + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + return result; +} + +net_nfc_error_e net_nfc_util_free_carrier_group( + net_nfc_carrier_property_s *group) +{ + if (group == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _release_tree(group->data); + + return NET_NFC_OK; +} + +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 result; + + if (record == NULL || config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + switch (config->type) { + case NET_NFC_CONN_HANDOVER_CARRIER_BT : + result = net_nfc_util_handover_bt_create_record_from_config(record, config); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS : + result = net_nfc_util_handover_wps_create_record_from_config(record, config); + break; + + default : + result = NET_NFC_NOT_SUPPORTED; + break; + } + + return result; +} + +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; + + if (record == NULL || config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (net_nfc_util_handover_bt_check_carrier_record(record)) { + result = net_nfc_util_handover_bt_create_config_from_record(config, record); + } else if (net_nfc_util_handover_wps_check_carrier_record(record)) { + result = net_nfc_util_handover_wps_create_config_from_record(config, record); + } else { + result = NET_NFC_NOT_SUPPORTED; + } + + return result; +} + +net_nfc_error_e net_nfc_util_create_carrier_config_from_carrier( + net_nfc_carrier_config_s **config, net_nfc_ch_carrier_s *carrier) +{ + net_nfc_error_e result; + ndef_record_s *record; + + if (carrier == NULL || carrier->carrier_record == NULL || config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + result = net_nfc_util_get_handover_carrier_record(carrier, &record); + if (result == NET_NFC_OK) { + result = net_nfc_util_create_carrier_config_from_config_record(config, record); + } + + return result; +} + +static net_nfc_error_e _create_collision_resolution_record( + ndef_record_s **record) +{ + uint32_t state; + uint16_t random_num; + data_s typeName = { (uint8_t *)CH_CR_RECORD_TYPE, + CH_CR_RECORD_TYPE_LEN }; + data_s payload = { (uint8_t *)&random_num, sizeof(random_num) }; + + if (record == NULL) + return NET_NFC_NULL_PARAMETER; + + state = (uint32_t)time(NULL); + random_num = htons((unsigned short)rand_r(&state)); + + return net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, + &typeName, NULL, &payload, record); +} + +net_nfc_error_e net_nfc_util_create_handover_error_record( + ndef_record_s **record, uint8_t reason, uint32_t data) +{ + data_s type = { (uint8_t *)CH_ERR_RECORD_TYPE, CH_ERR_RECORD_TYPE_LEN }; + 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; + + memcpy(payload.buffer, &data, size); + + net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, + &payload, record); + + _net_nfc_util_free_mem(payload.buffer); + + return NET_NFC_OK; +} + + +net_nfc_error_e net_nfc_util_create_handover_carrier( + net_nfc_ch_carrier_s **carrier, + net_nfc_conn_handover_carrier_state_e cps) +{ + net_nfc_ch_carrier_s *temp; + + if (carrier == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + temp = g_new0(net_nfc_ch_carrier_s, 1); + + temp->cps = cps; + + *carrier = temp; + + return NET_NFC_OK; +} + +static void _duplicate_carrier_cb(gpointer data, gpointer user_data) +{ + ndef_record_s *record = (ndef_record_s *)data; + net_nfc_ch_carrier_s *temp = (net_nfc_ch_carrier_s *)user_data; + + if (record != NULL) { + ndef_record_s *temp_record; + + net_nfc_util_create_record(record->TNF, + &record->type_s, + &record->id_s, + &record->payload_s, + &temp_record); + + temp->aux_records = g_list_append(temp->aux_records, + temp_record); + } +} + +net_nfc_error_e net_nfc_util_duplicate_handover_carrier( + net_nfc_ch_carrier_s **dest, + net_nfc_ch_carrier_s *src) +{ + net_nfc_ch_carrier_s *temp; + + if (dest == NULL || src == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + temp = g_new0(net_nfc_ch_carrier_s, 1); + + temp->type = src->type; + temp->cps = src->cps; + + if (src->carrier_record != NULL) { + net_nfc_util_create_record(src->carrier_record->TNF, + &src->carrier_record->type_s, + &src->carrier_record->id_s, + &src->carrier_record->payload_s, + &temp->carrier_record); + } + + g_list_foreach(src->aux_records, _duplicate_carrier_cb, temp); + + *dest = temp; + + return NET_NFC_OK; +} + + +static void _ch_carrier_free_cb(gpointer data) +{ + ndef_record_s *record = (ndef_record_s *)data; + + net_nfc_util_free_record(record); +} + +net_nfc_error_e net_nfc_util_free_handover_carrier( + net_nfc_ch_carrier_s *carrier) +{ + if (carrier == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + g_list_free_full(carrier->aux_records, _ch_carrier_free_cb); + + net_nfc_util_free_record(carrier->carrier_record); + + g_free(carrier); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_set_handover_carrier_cps( + net_nfc_ch_carrier_s *carrier, + net_nfc_conn_handover_carrier_state_e cps) +{ + if (carrier == NULL) + return NET_NFC_NULL_PARAMETER; + + carrier->cps = cps; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_handover_carrier_cps( + net_nfc_ch_carrier_s *carrier, + net_nfc_conn_handover_carrier_state_e *cps) +{ + if (carrier == NULL || cps == NULL) + return NET_NFC_NULL_PARAMETER; + + *cps = carrier->cps; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_set_handover_carrier_type( + net_nfc_ch_carrier_s *carrier, + net_nfc_conn_handover_carrier_type_e type) +{ + if (carrier == NULL) + return NET_NFC_NULL_PARAMETER; + + carrier->type = type; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_handover_carrier_type( + net_nfc_ch_carrier_s *carrier, + net_nfc_conn_handover_carrier_type_e *type) +{ + if (carrier == NULL || type == NULL) + return NET_NFC_NULL_PARAMETER; + + *type = carrier->type; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_append_handover_carrier_record( + net_nfc_ch_carrier_s *carrier, ndef_record_s *record) +{ + if (carrier == NULL || record == NULL) + return NET_NFC_NULL_PARAMETER; + + net_nfc_util_remove_handover_carrier_record(carrier); + + return net_nfc_util_create_record(record->TNF, &record->type_s, NULL, + &record->payload_s, &carrier->carrier_record); +} + +net_nfc_error_e net_nfc_util_get_handover_carrier_record( + net_nfc_ch_carrier_s *carrier, ndef_record_s **record) +{ + if (carrier == NULL || record == NULL) + return NET_NFC_NULL_PARAMETER; + + if (carrier->carrier_record != NULL) { + *record = carrier->carrier_record; + } + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_remove_handover_carrier_record( + net_nfc_ch_carrier_s *carrier) +{ + if (carrier == NULL) + return NET_NFC_NULL_PARAMETER; + + if (carrier->carrier_record != NULL) { + net_nfc_util_free_record(carrier->carrier_record); + carrier->carrier_record = NULL; + } + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_append_handover_auxiliary_record( + net_nfc_ch_carrier_s *carrier, ndef_record_s *record) +{ + net_nfc_error_e result; + ndef_record_s *temp = NULL; + + if (carrier == NULL || record == NULL) + return NET_NFC_NULL_PARAMETER; + + result = net_nfc_util_create_record(record->TNF, &record->type_s, NULL, + &record->payload_s, &temp); + if (result == NET_NFC_OK) { + carrier->aux_records = g_list_append(carrier->aux_records, + temp); + } + + return result; +} + +net_nfc_error_e net_nfc_util_get_handover_auxiliary_record_count( + net_nfc_ch_carrier_s *carrier, uint32_t *count) +{ + if (carrier == NULL || count == NULL) + return NET_NFC_NULL_PARAMETER; + + *count = g_list_length(carrier->aux_records); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_handover_auxiliary_record( + net_nfc_ch_carrier_s *carrier, int index, ndef_record_s **record) +{ + net_nfc_error_e result; + GList *item; + + if (carrier == NULL || record == NULL) + return NET_NFC_NULL_PARAMETER; + + if (index < 0 || index >= g_list_length(carrier->aux_records)) + return NET_NFC_OUT_OF_BOUND; + + item = g_list_nth(carrier->aux_records, index); + if (item != NULL) { + *record = (ndef_record_s *)item->data; + result = NET_NFC_OK; + } else { + result = NET_NFC_OUT_OF_BOUND; + } + + return result; +} + +net_nfc_error_e net_nfc_util_remove_handover_auxiliary_record( + net_nfc_ch_carrier_s *carrier, ndef_record_s *record) +{ + net_nfc_error_e result; + GList *list; + + if (carrier == NULL || record == NULL) + return NET_NFC_NULL_PARAMETER; + + list = g_list_find(carrier->aux_records, record); + if (list != NULL) { + net_nfc_util_free_record((ndef_record_s *)list->data); + carrier->aux_records = g_list_delete_link(carrier->aux_records, + list); + + result = NET_NFC_OK; + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + return result; +} + +net_nfc_error_e net_nfc_util_create_handover_message( + net_nfc_ch_message_s **message) +{ + net_nfc_ch_message_s *temp; + + if (message == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + temp = g_new0(net_nfc_ch_message_s, 1); + + temp->version = CH_VERSION; + + *message = temp; + + return NET_NFC_OK; +} + +static void _ch_message_free_cb(gpointer data) +{ + net_nfc_ch_carrier_s *carrier = (net_nfc_ch_carrier_s *)data; + + net_nfc_util_free_handover_carrier(carrier); +} + +net_nfc_error_e net_nfc_util_free_handover_message( + net_nfc_ch_message_s *message) +{ + if (message == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + DEBUG_MSG("free [%p]", message); + + g_list_free_full(message->carriers, _ch_message_free_cb); + message->carriers = NULL; + + g_free(message); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_set_handover_message_type( + net_nfc_ch_message_s *message, net_nfc_ch_type_e type) +{ + if (message == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (type >= NET_NFC_CH_TYPE_MAX) { + return NET_NFC_OUT_OF_BOUND; + } + + message->type = type; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_handover_message_type( + net_nfc_ch_message_s *message, net_nfc_ch_type_e *type) +{ + if (message == NULL || type == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + *type = message->type; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_append_handover_carrier( + net_nfc_ch_message_s *message, net_nfc_ch_carrier_s *carrier) +{ + if (message == NULL || carrier == NULL) + return NET_NFC_NULL_PARAMETER; + + message->carriers = g_list_append(message->carriers, carrier); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_handover_carrier_count( + net_nfc_ch_message_s *message, uint32_t *count) +{ + if (message == NULL || count == NULL) + return NET_NFC_NULL_PARAMETER; + + *count = g_list_length(message->carriers); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_handover_carrier( + net_nfc_ch_message_s *message, int index, + net_nfc_ch_carrier_s **carrier) +{ + net_nfc_error_e result; + GList *list; + + if (message == NULL || carrier == NULL) + return NET_NFC_NULL_PARAMETER; + + if (index < 0 || index >= g_list_length(message->carriers)) + return NET_NFC_INVALID_PARAM; + + list = g_list_nth(message->carriers, index); + if (list != NULL) { + *carrier = list->data; + result = NET_NFC_OK; + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + return result; +} + +static gint _compare_cb(gconstpointer a, gconstpointer b) +{ + net_nfc_ch_carrier_s *carrier = (net_nfc_ch_carrier_s *)a; + net_nfc_conn_handover_carrier_type_e type = + (net_nfc_conn_handover_carrier_type_e)b; + + if (carrier->type == type) + return 0; + else + return 1; +} + +net_nfc_error_e net_nfc_util_get_handover_carrier_by_type( + net_nfc_ch_message_s *message, + net_nfc_conn_handover_carrier_type_e type, + net_nfc_ch_carrier_s **carrier) +{ + net_nfc_error_e result; + GList *list; + + if (message == NULL || carrier == NULL) + return NET_NFC_NULL_PARAMETER; + + list = g_list_find_custom(message->carriers, (gconstpointer)type, + _compare_cb); + if (list != NULL) { + *carrier = list->data; + + result = NET_NFC_OK; + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + return result; +} + +typedef struct _ch_payload_t +{ + uint8_t version; + uint8_t message[0]; +} +__attribute__((packed)) ch_payload_t; + +typedef struct _ch_ac_ref_t +{ + uint8_t ref_len; + uint8_t ref[0]; +} +__attribute__((packed)) ch_ac_ref_t; + +typedef struct _ch_ac_header_t +{ + uint8_t cps : 3; + uint8_t rfu : 5; + uint8_t data[0]; +} +__attribute__((packed)) ch_ac_header_t; + +typedef struct _ch_ac_aux_header_t +{ + uint8_t count; + uint8_t data[0]; +} +__attribute__((packed)) ch_ac_aux_header_t; + +static void _change_id_field_and_add_record(uint8_t *buffer, uint32_t length, + ndef_record_s *record, ndef_message_s *message) +{ + data_s id = { buffer, length }; + ndef_record_s *temp = NULL; + + net_nfc_util_create_record(record->TNF, + &record->type_s, + &id, &record->payload_s, &temp); + + net_nfc_util_append_record(message, temp); +} + +static void _ch_message_export_cb(gpointer data, gpointer user_data) +{ + gpointer *params = (gpointer *)user_data; + net_nfc_ch_carrier_s *carrier = (net_nfc_ch_carrier_s *)data; + ndef_message_s *inner_msg; + ndef_message_s *main_msg; + int count; + data_s type = { (uint8_t *)CH_AC_RECORD_TYPE, CH_AC_RECORD_TYPE_LEN }; + data_s payload; + ndef_record_s *record = NULL; + char *id; + + if (carrier->carrier_record == NULL) + return; + + id = (char *)params[0]; + inner_msg = (ndef_message_s *)params[1]; + main_msg = (ndef_message_s *)params[2]; + + /* count total record */ + count = 1/* carrier record */ + g_list_length(carrier->aux_records); + + /* create ac record */ + net_nfc_util_init_data(&payload, + sizeof(ch_ac_header_t) + sizeof(ch_ac_aux_header_t) + + count * (sizeof(ch_ac_ref_t) + 4/* max length is 4 */)); + + ch_ac_header_t *header = (ch_ac_header_t *)payload.buffer; + + header->cps = carrier->cps; + + payload.length = sizeof(ch_ac_header_t); + + /* carrier record */ + ch_ac_ref_t *ref = (ch_ac_ref_t *)header->data; + + ref->ref[0] = *id++; + ref->ref_len = 1; + + _change_id_field_and_add_record(ref->ref, ref->ref_len, + carrier->carrier_record, main_msg); + + payload.length += sizeof(ch_ac_ref_t) + ref->ref_len; + + /* aux record */ + ch_ac_aux_header_t *aux = (ch_ac_aux_header_t *)(ref->ref + + ref->ref_len); + + aux->count = g_list_length(carrier->aux_records); + + payload.length += sizeof(ch_ac_aux_header_t); + + GList *list = g_list_first(carrier->aux_records); + ref = (ch_ac_ref_t *)aux->data; + + while (list != NULL) { + ref->ref[0] = *id++; + ref->ref_len = 1; + + _change_id_field_and_add_record(ref->ref, ref->ref_len, + (ndef_record_s *)list->data, main_msg); + + payload.length += sizeof(ch_ac_ref_t) + ref->ref_len; + ref = (ch_ac_ref_t *)(ref->ref + ref->ref_len); + + list = g_list_next(list); + } + + /* append ac record */ + net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, + &type, NULL, &payload, &record); + + net_nfc_util_append_record(inner_msg, record); + + net_nfc_util_clear_data(&payload); +} + +static void _get_handover_type_field(net_nfc_ch_type_e type, data_s *result) +{ + switch (type) { + case NET_NFC_CH_TYPE_REQUEST : + result->buffer = (uint8_t *)CH_REQ_RECORD_TYPE; + result->length = CH_REQ_RECORD_TYPE_LEN; + break; + + case NET_NFC_CH_TYPE_SELECT : + result->buffer = (uint8_t *)CH_SEL_RECORD_TYPE; + result->length = CH_SEL_RECORD_TYPE_LEN; + break; + + case NET_NFC_CH_TYPE_MEDIATION : + result->buffer = (uint8_t *)CH_MED_RECORD_TYPE; + result->length = CH_MED_RECORD_TYPE_LEN; + break; + + case NET_NFC_CH_TYPE_INITIAITE : + result->buffer = (uint8_t *)CH_INI_RECORD_TYPE; + result->length = CH_INI_RECORD_TYPE_LEN; + break; + + default : + break; + } +} + +net_nfc_error_e net_nfc_util_export_handover_to_ndef_message( + net_nfc_ch_message_s *message, ndef_message_s **result) +{ + net_nfc_error_e error; + gpointer params[3]; + ndef_message_s *inner_msg = NULL; + ndef_message_s *main_msg = NULL; + data_s payload; + uint32_t len; + char id = 'A'; + + if (message == NULL || result == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + error = net_nfc_util_create_ndef_message(&inner_msg); + if (error != NET_NFC_OK) + { + return error; + } + + error = net_nfc_util_create_ndef_message(&main_msg); + if (error != NET_NFC_OK) + { + net_nfc_util_free_ndef_message(inner_msg); + + return error; + } + + params[0] = &id; + params[1] = inner_msg; + params[2] = main_msg; + + g_list_foreach(message->carriers, _ch_message_export_cb, params); + + if (message->type == NET_NFC_CH_TYPE_REQUEST) { + ndef_record_s *cr = NULL; + + /* append collision resolution record */ + _create_collision_resolution_record(&cr); + + net_nfc_util_append_record_by_index(inner_msg, 0, cr); + } + + /* convert message to raw data */ + len = net_nfc_util_get_ndef_message_length(inner_msg); + + if (net_nfc_util_init_data(&payload, sizeof(ch_payload_t) + len) == + true) { + data_s data; + ch_payload_t *header; + + header = (ch_payload_t *)payload.buffer; + + data.buffer = header->message; + data.length = len; + + error = net_nfc_util_convert_ndef_message_to_rawdata(inner_msg, + &data); + if (error == NET_NFC_OK) { + ndef_record_s *hr = NULL; + data_s type; + + /* set version */ + header->version = CH_VERSION; + + _get_handover_type_field(message->type, &type); + + /* create Hr record */ + error = net_nfc_util_create_record( + NET_NFC_RECORD_WELL_KNOWN_TYPE, + &type, NULL, &payload, &hr); + if (error == NET_NFC_OK) { + /* append first record */ + net_nfc_util_append_record_by_index(main_msg, 0, + hr); + + *result = main_msg; + } else { + DEBUG_ERR_MSG("net_nfc_util_create_record failed, [%d]", error); + } + + net_nfc_util_free_ndef_message(inner_msg); + } else { + DEBUG_ERR_MSG("net_nfc_util_convert_ndef_message_to_rawdata failed, [%d]", error); + } + + net_nfc_util_clear_data(&payload); + } else { + DEBUG_ERR_MSG("net_nfc_util_alloc_data failed"); + } + + return error; +} + +static ndef_message_s *_raw_data_to_ndef_message(data_s *data) +{ + net_nfc_error_e result; + ndef_message_s *msg = NULL; + + result = net_nfc_util_create_ndef_message(&msg); + if (result == NET_NFC_OK) { + result = net_nfc_util_convert_rawdata_to_ndef_message(data, + msg); + if (result != NET_NFC_OK) { + net_nfc_util_free_ndef_message(msg); + msg = NULL; + } + } + + return msg; +} + +static ndef_record_s *_find_record_by_id(uint8_t *id, uint8_t id_len, + ndef_record_s *records) +{ + ndef_record_s *record = NULL; + + while (records != NULL) { + if (records->id_s.length == id_len && + memcmp(id, records->id_s.buffer, id_len) == 0) { + record = records; + + break; + } + records = records->next; + } + + return record; +} + +static void _fill_aux_rec(net_nfc_ch_carrier_s *carrier, + ch_ac_aux_header_t *header, ndef_record_s *content) +{ + if (header == NULL) + return; + + /* copy auxiliary record */ + if (header->count > 0) { + int i; + ndef_record_s *record; + ndef_record_s *temp; + ch_ac_ref_t *ref; + + ref = (ch_ac_ref_t *)header->data; + + for (i = 0; i < header->count; i++) { + record = _find_record_by_id(ref->ref, ref->ref_len, + content); + if (record != NULL) { + net_nfc_util_create_record(record->TNF, + &record->type_s, + NULL, &record->payload_s, + &temp); + + carrier->aux_records = g_list_append( + carrier->aux_records, temp); + } + + ref = (ch_ac_ref_t *)(ref->ref + ref->ref_len); + } + } +} + +static net_nfc_conn_handover_carrier_type_e _get_carrier_type_from_record( + ndef_record_s *record) +{ + net_nfc_conn_handover_carrier_type_e result; + + if (net_nfc_util_handover_bt_check_carrier_record(record)) + { + result = NET_NFC_CONN_HANDOVER_CARRIER_BT; + } + else if (net_nfc_util_handover_wps_check_carrier_record(record)) + { + result = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS; + } + else + { + result = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + } + + return result; +} + +static net_nfc_error_e _fill_handover_carrier_record( + net_nfc_ch_carrier_s *carrier, + ch_ac_ref_t *ref, ndef_record_s *content) +{ + net_nfc_error_e result; + ndef_record_s *record; + + if (carrier == NULL) + return NET_NFC_NULL_PARAMETER; + + /* copy carrier record */ + record = _find_record_by_id(ref->ref, ref->ref_len, content); + if (record != NULL) { + DEBUG_MSG("carrier found [%p]", ref->ref); + + carrier->type = _get_carrier_type_from_record(record); + + result = net_nfc_util_create_record(record->TNF, + &record->type_s, NULL, + &record->payload_s, + &carrier->carrier_record); + + _fill_aux_rec(carrier, + (ch_ac_aux_header_t *)(ref->ref + ref->ref_len), + content); + + result = NET_NFC_OK; + } else { + DEBUG_ERR_MSG("carrier record not found, [%s]", ref->ref); + + result = NET_NFC_NO_DATA_FOUND; + } + + return result; +} + +static net_nfc_error_e _fill_handover_message(net_nfc_ch_message_s *msg, + ndef_record_s *header, ndef_record_s *content) +{ + net_nfc_error_e result = NET_NFC_OK; + ndef_record_s *current = header; + + DEBUG_MSG("header [%p], content [%p]", header, content); + + while (current != NULL && + CHECK_TYPE(current->type_s, CH_AC_RECORD_TYPE) == true) { + net_nfc_ch_carrier_s *carrier; + ch_ac_header_t *ac_header; + net_nfc_conn_handover_carrier_state_e cps; + + ac_header = (ch_ac_header_t *)current->payload_s.buffer; + + cps = ac_header->cps; + + result = net_nfc_util_create_handover_carrier(&carrier, cps); + if (result == NET_NFC_OK) { + ch_ac_ref_t *ref; + + /* copy carrier record */ + ref = (ch_ac_ref_t *)ac_header->data; + + result = _fill_handover_carrier_record(carrier, ref, + content); + if (result == NET_NFC_OK) { + net_nfc_util_append_handover_carrier(msg, + carrier); + } else { + DEBUG_ERR_MSG("_fill_handover_carrier_record failed, [%d]", result); + + net_nfc_util_free_handover_carrier(carrier); + } + } else { + DEBUG_ERR_MSG("net_nfc_util_create_handover_carrier failed, [%d]", result); + } + + current = current->next; + } + + return result; +} + +static net_nfc_ch_type_e _get_handover_type_from_type_data(data_s *result) +{ + net_nfc_ch_type_e type; + + if (CHECK_TYPE((*result), CH_REQ_RECORD_TYPE) == true) { + type = NET_NFC_CH_TYPE_REQUEST; + } else if (CHECK_TYPE((*result), CH_SEL_RECORD_TYPE) == true) { + type = NET_NFC_CH_TYPE_SELECT; + } else if (CHECK_TYPE((*result), CH_MED_RECORD_TYPE) == true) { + type = NET_NFC_CH_TYPE_MEDIATION; + } else if (CHECK_TYPE((*result), CH_INI_RECORD_TYPE) == true) { + type = NET_NFC_CH_TYPE_INITIAITE; + } else { + type = NET_NFC_CH_TYPE_UNKNOWN; + } + + return type; +} + +net_nfc_error_e net_nfc_util_import_handover_from_ndef_message( + ndef_message_s *msg, net_nfc_ch_message_s **result) +{ + net_nfc_error_e error; + ndef_record_s *hr = NULL; + net_nfc_ch_type_e type; + + if (msg == NULL || result == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + /* first record */ + error = net_nfc_util_get_record_by_index(msg, 0, &hr); + if (error != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_util_get_record_by_index failed, [%d]", error); + + return error; + } + + if (hr->TNF != NET_NFC_RECORD_WELL_KNOWN_TYPE) { + return NET_NFC_INVALID_FORMAT; + } + + type = _get_handover_type_from_type_data(&hr->type_s); + if (type == NET_NFC_CH_TYPE_UNKNOWN) { + return NET_NFC_INVALID_FORMAT; + } + + ndef_message_s *inner; + data_s data; + ch_payload_t *header; + + /* check type */ + header = (ch_payload_t *)hr->payload_s.buffer; + + /* check version */ + + /* get records */ + data.buffer = header->message; + data.length = hr->payload_s.length - sizeof(ch_payload_t); + + DEBUG_MSG("data [%p][%d]", data.buffer, data.length); + + inner = _raw_data_to_ndef_message(&data); + if (inner != NULL) { + net_nfc_ch_message_s *temp; + + error = net_nfc_util_create_handover_message(&temp); + if (error == NET_NFC_OK) { + ndef_record_s *record = NULL; + + temp->version = header->version; + temp->type = _get_handover_type_from_type_data( + &hr->type_s); + + record = inner->records; + + if (temp->type == NET_NFC_CH_TYPE_REQUEST) { + /* get cr */ + if (CHECK_TYPE(record->type_s, CH_CR_RECORD_TYPE) == true) { + temp->cr = htons(*(uint16_t *)record->payload_s.buffer); + + record = record->next; + } + } + + _fill_handover_message(temp, record, msg->records); + + *result = temp; + } else { + DEBUG_ERR_MSG("net_nfc_util_create_handover_message failed, [%d]", error); + } + + net_nfc_util_free_ndef_message(inner); + } else { + DEBUG_ERR_MSG("_raw_data_to_ndef_message failed"); + + error = NET_NFC_ALLOC_FAIL; + } + + return error; +} + +net_nfc_error_e net_nfc_util_get_handover_random_number( + net_nfc_ch_message_s *message, uint16_t *random_number) +{ + if (message == NULL || random_number == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (message->type != NET_NFC_CH_TYPE_REQUEST) { + return NET_NFC_INVALID_PARAM; + } + + *random_number = message->cr; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_selector_power_status( + net_nfc_ch_message_s *message, + net_nfc_conn_handover_carrier_state_e *cps) +{ + net_nfc_error_e error; + int count; + + if (message == NULL || cps == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + count = g_list_length(message->carriers); + + if (count > 1) { + int i; + GList *list; + net_nfc_ch_carrier_s *carrier; + + *cps = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE; + + for (i = 0; i < count; i++) { + list = g_list_nth(message->carriers, i); + carrier = list->data; + if (carrier->cps == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE || + carrier->cps == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING) { + + *cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE; + break; + } + } + + error = NET_NFC_OK; + } else if (count == 1) { + *cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE; + + error = NET_NFC_OK; + } else { + error = NET_NFC_NO_DATA_FOUND; + } + + return error; +} diff --git a/src/commonlib/net_nfc_util_handover_bt.c b/src/commonlib/net_nfc_util_handover_bt.c new file mode 100644 index 0000000..b64cd5b --- /dev/null +++ b/src/commonlib/net_nfc_util_handover_bt.c @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_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" + +#define CH_BT_MIME "application/vnd.bluetooth.ep.oob" +#define CH_BT_MIME_LEN 32 + +bool net_nfc_util_handover_bt_check_carrier_record(ndef_record_s *record) +{ + bool result; + + g_assert(record != NULL); + + if ((record->type_s.length == CH_CAR_RECORD_TYPE_LEN) && + (memcmp(CH_CAR_RECORD_TYPE, record->type_s.buffer, + CH_CAR_RECORD_TYPE_LEN) == 0)) { + + /* FIXME */ + if ((record->type_s.length == CH_BT_MIME_LEN) && + (memcmp(CH_BT_MIME, record->type_s.buffer, + CH_BT_MIME_LEN) == 0)) { + result = true; + } else { + result = false; + } + } else if ((record->type_s.length == CH_BT_MIME_LEN) && + (memcmp(CH_BT_MIME, record->type_s.buffer, + CH_BT_MIME_LEN) == 0)) { + result = true; + } else { + result = false; + } + + return result; +} + +typedef struct _oob_header_t +{ + uint16_t length; + uint8_t address[6]; + uint8_t data[0]; +} +oob_header_t; + +typedef struct _eir_header_t +{ + uint8_t l; + uint8_t t; + uint8_t v[0]; +} +__attribute__((packed)) eir_header_t; + +static void __calc_total_length_cb(GNode *node, gpointer data) +{ + net_nfc_carrier_property_s *info = node->data; + uint32_t *length = (uint32_t *)data; + + if (info == NULL) + return; + + if (info->attribute == NET_NFC_BT_ATTRIBUTE_ADDRESS) + return; + + *length += sizeof(eir_header_t); + + if (info->is_group) { + uint32_t temp_len = 0; + + g_node_children_foreach(node, G_TRAVERSE_ALL, + __calc_total_length_cb, &temp_len); + + info->length = temp_len; + + *length += info->length; + } + else + { + *length += info->length; + } +} + +static uint32_t _calc_total_length(net_nfc_carrier_config_s *config) +{ + uint32_t result = sizeof(oob_header_t); + + g_node_children_foreach(config->data, G_TRAVERSE_ALL, + __calc_total_length_cb, &result); + + config->length = result; + + return result; +} + +static void _serialize_cb(GNode *node, gpointer data) +{ + net_nfc_carrier_property_s *prop = node->data; + data_s *payload = (data_s *)data; + eir_header_t *header; + + if (prop == NULL) + return; + + if (prop->attribute == NET_NFC_BT_ATTRIBUTE_ADDRESS) /* skip property */ + return; + + header = (eir_header_t *)(payload->buffer + payload->length); + + header->t = prop->attribute; + header->l = prop->length + sizeof(header->t); + + payload->length += sizeof(eir_header_t); + + memcpy(header->v, prop->data, prop->length); + + payload->length += (prop->length); +} + +net_nfc_error_e net_nfc_util_handover_bt_create_record_from_config( + ndef_record_s **record, net_nfc_carrier_config_s *config) +{ + net_nfc_error_e result; + uint32_t len; + uint8_t *buffer = NULL; + data_s type = { (uint8_t *)CH_BT_MIME, CH_BT_MIME_LEN }; + + if (record == NULL || config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + len = _calc_total_length(config); + + DEBUG_MSG("payload length [%d]", len); + + _net_nfc_util_alloc_mem(buffer, len); + if (buffer != NULL) { + oob_header_t *header = (oob_header_t *)buffer; + uint16_t addr_len = 0; + uint8_t *addr = NULL; + data_s payload; + + /* total length */ + header->length = len; + + /* address */ + net_nfc_util_get_carrier_config_property(config, + NET_NFC_BT_ATTRIBUTE_ADDRESS, + &addr_len, &addr); + + if (addr_len == sizeof(header->address)) { + memcpy(header->address, addr, addr_len); + } + + payload.buffer = buffer; + payload.length = sizeof(oob_header_t); /* offset */ + + /* eirs */ + g_node_children_foreach(config->data, G_TRAVERSE_ALL, + _serialize_cb, &payload); + + g_assert(len == payload.length); + + result = net_nfc_util_create_record(NET_NFC_RECORD_MIME_TYPE, + &type, NULL, &payload, record); + + _net_nfc_util_free_mem(buffer); + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} + +typedef void (*_parse_eir_cb)(uint8_t t, uint8_t l, + uint8_t *v, void *user_data); + +static void _parse_eir(uint8_t *buffer, uint32_t len, + _parse_eir_cb cb, void *user_data) +{ + eir_header_t *tlv; + uint32_t offset = 0; + uint8_t l; + + if (buffer == NULL || len == 0 || cb == NULL) + return; + + do + { + tlv = (eir_header_t *)(buffer + offset); + l = tlv->l - sizeof(tlv->t); /* length includes tag's size */ + cb(tlv->t, l, tlv->v, user_data); + offset += sizeof(eir_header_t) + l; + } + while (offset < len); +} + +static void _bt_eir_cb(uint8_t t, uint8_t l, + uint8_t *v, void *user_data) +{ + GNode *node = (GNode *)user_data; + net_nfc_carrier_property_s *elem; + + elem = g_new0(net_nfc_carrier_property_s, 1); + + elem->attribute = t; + elem->length = l; + elem->data = g_malloc0(l); + + if(elem->data != NULL) + { + memcpy(elem->data, v, l); + + g_node_append_data(node, elem); + } +} + +net_nfc_error_e net_nfc_util_handover_bt_create_config_from_record( + net_nfc_carrier_config_s **config, ndef_record_s *record) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_carrier_config_s *temp = NULL; + + if (record == NULL || config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + result = net_nfc_util_create_carrier_config(&temp, + NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS); + if (temp != NULL) { + oob_header_t *header = (oob_header_t *)record->payload_s.buffer; + + temp->length = header->length; + + net_nfc_util_add_carrier_config_property(temp, + NET_NFC_BT_ATTRIBUTE_ADDRESS, sizeof(header->address), + header->address); + + _parse_eir(header->data, temp->length - sizeof(oob_header_t), + _bt_eir_cb, temp->data); + + *config = temp; + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} diff --git a/src/commonlib/net_nfc_util_handover_wfd.c b/src/commonlib/net_nfc_util_handover_wfd.c new file mode 100644 index 0000000..bb5e275 --- /dev/null +++ b/src/commonlib/net_nfc_util_handover_wfd.c @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_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" + +bool net_nfc_util_handover_wfd_check_carrier_record(ndef_record_s *record) +{ + bool result; + + g_assert(record != NULL); + + if ((record->type_s.length == CH_CAR_RECORD_TYPE_LEN) && + (memcmp(CH_CAR_RECORD_TYPE, record->type_s.buffer, + CH_CAR_RECORD_TYPE_LEN) == 0)) { + + /* FIXME */ + if ((record->type_s.length == CH_WIFI_P2P_MIME_LEN) && + (memcmp(CH_WIFI_P2P_MIME, record->type_s.buffer, + CH_WIFI_P2P_MIME_LEN) == 0)) { + result = true; + } else { + result = false; + } + } else if ((record->type_s.length == CH_WIFI_P2P_MIME_LEN) && + (memcmp(CH_WIFI_P2P_MIME, record->type_s.buffer, + CH_WIFI_P2P_MIME_LEN) == 0)) { + result = true; + } else { + result = false; + } + + return result; +} + +typedef struct _ac_header_t +{ + uint16_t length; + uint8_t buffer[0]; +} +__attribute__((packed)) ac_header_t; + +typedef struct _tlv_header_t +{ + uint16_t t; + uint16_t l; + uint8_t v[0]; +} +__attribute__((packed)) tlv_header_t; + +typedef void (*_parse_tlv_cb)(uint16_t t, uint16_t l, + uint8_t *v, void *user_data); + +static void _parse_tlv(uint8_t *buffer, uint32_t len, + _parse_tlv_cb cb, void *user_data) +{ + tlv_header_t *tlv; + uint32_t offset = 0; + uint16_t l; + + if (buffer == NULL || len == 0 || cb == NULL) + return; + + do + { + tlv = (tlv_header_t *)(buffer + offset); + l = htons(tlv->l); + cb(htons(tlv->t), l, tlv->v, user_data); + offset += sizeof(tlv_header_t) + l; + } + while (offset < len); +} + +typedef struct _small_tlv_header_t +{ + uint8_t t; + uint16_t l; + uint8_t v[0]; +} +__attribute__((packed)) small_tlv_header_t; + +static void _parse_small_tlv(uint8_t *buffer, uint32_t len, + _parse_tlv_cb cb, void *user_data) +{ + small_tlv_header_t *tlv; + uint32_t offset = 0; + uint16_t l; + + if (buffer == NULL || len == 0 || cb == NULL) + return; + + do + { + tlv = (small_tlv_header_t *)(buffer + offset); + l = htons(tlv->l); + cb(tlv->t, l, tlv->v, user_data); + offset += sizeof(small_tlv_header_t) + l; + } + while (offset < len); +} + +static void _wifi_tlv_cb(uint16_t t, uint16_t l, + uint8_t *v, void *user_data) +{ + GNode *node = (GNode *)user_data; + net_nfc_carrier_property_s *elem; + + elem = g_new0(net_nfc_carrier_property_s, 1); + + elem->attribute = t; + elem->length = l; + + node = g_node_append_data(node, elem); + + if (t == NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL) { + elem->is_group = true; + elem->data = node; + + _parse_tlv(v, l, _wifi_tlv_cb, node); + } else { + DEBUG_MSG("t [0x%04X] l [%d] v [%p]", t, l, v); + + elem->data = g_malloc0(l); + if(elem->data != NULL) + { + memcpy(elem->data, v, l); + } + else + { + DEBUG_MSG("elem->data is NULL"); + } + } +} + +net_nfc_error_e net_nfc_util_handover_wfd_create_config_from_record( + net_nfc_carrier_config_s **config, ndef_record_s *record) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_carrier_config_s *temp = NULL; + + if (record == NULL || config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + result = net_nfc_util_create_carrier_config(&temp, + NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P); + if (result == NET_NFC_OK && temp != NULL) { + ac_header_t *header; + uint16_t length; + + /* total length */ + temp->length = record->payload_s.length; + + /* WSC properties */ + header = (ac_header_t *)record->payload_s.buffer; + length = htons(header->length); + + _parse_tlv(header->buffer, length, + _wifi_tlv_cb, temp->data); + + /* P2P properties */ + header = (ac_header_t *)(header->buffer + length); + length = htons(header->length); + + _parse_small_tlv(header->buffer, length, + _wifi_tlv_cb, temp->data); + + *config = temp; + } else { + DEBUG_ERR_MSG("net_nfc_util_create_carrier_config failed, [%d]", result); + } + + return result; +} + +static void __calc_total_wsc_prop_length_cb(GNode *node, gpointer data) +{ + net_nfc_carrier_property_s *info = node->data; + uint32_t *length = (uint32_t *)data; + + if (info == NULL) + return; + + if (info->attribute < 0x0100) { + return; + } + + *length += sizeof(tlv_header_t); + + if (info->is_group) { + uint32_t temp_len = 0; + + g_node_children_foreach(node, G_TRAVERSE_ALL, + __calc_total_wsc_prop_length_cb, &temp_len); + + info->length = temp_len; + + *length += info->length; + } + else + { + *length += info->length; + } +} + +static void __calc_total_p2p_prop_length_cb(GNode *node, gpointer data) +{ + net_nfc_carrier_property_s *info = node->data; + uint32_t *length = (uint32_t *)data; + + if (info == NULL) + return; + + if (info->attribute > 0x00FF) { + return; + } + + *length += sizeof(small_tlv_header_t); + *length += info->length; +} + +static uint32_t _calc_total_wsc_prop_length(net_nfc_carrier_config_s *config) +{ + uint32_t result = 0; + + /* WSC properties */ + result += sizeof(ac_header_t); + + g_node_children_foreach(config->data, G_TRAVERSE_ALL, + __calc_total_wsc_prop_length_cb, &result); + + config->length = result; + + return result; +} + +static uint32_t _calc_total_p2p_prop_length(net_nfc_carrier_config_s *config) +{ + uint32_t result = 0; + + /* P2P properties */ + result += sizeof(ac_header_t); + + g_node_children_foreach(config->data, G_TRAVERSE_ALL, + __calc_total_p2p_prop_length_cb, &result); + + config->length = result; + + return result; +} + +static void _serialize_wsc_prop_cb(GNode *node, gpointer data) +{ + net_nfc_carrier_property_s *prop = node->data; + data_s *payload = (data_s *)data; + tlv_header_t *header; + + header = (tlv_header_t *)(payload->buffer + payload->length); + + header->t = htons(prop->attribute); + header->l = htons(prop->length); + + payload->length += sizeof(tlv_header_t); + + if (prop->is_group == true) { + g_node_children_foreach(node, G_TRAVERSE_ALL, + _serialize_wsc_prop_cb, payload); + } else { + memcpy(header->v, prop->data, prop->length); + + payload->length += (prop->length); + } +} + +static void _serialize_p2p_prop_cb(GNode *node, gpointer data) +{ + net_nfc_carrier_property_s *prop = node->data; + data_s *payload = (data_s *)data; + small_tlv_header_t *header; + + header = (small_tlv_header_t *)(payload->buffer + payload->length); + + header->t = (uint8_t)prop->attribute; + header->l = htons(prop->length); + + payload->length += sizeof(small_tlv_header_t); + + memcpy(header->v, prop->data, prop->length); + + payload->length += (prop->length); +} + +net_nfc_error_e net_nfc_util_handover_wfd_create_record_from_config( + ndef_record_s **record, net_nfc_carrier_config_s *config) +{ + net_nfc_error_e result; + uint32_t wsc_len, p2p_len; + data_s payload = { 0, }; + data_s type = { (uint8_t *)CH_WIFI_P2P_MIME, CH_WIFI_P2P_MIME_LEN }; + + if (record == NULL || config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + wsc_len = _calc_total_wsc_prop_length(config); + p2p_len = _calc_total_p2p_prop_length(config); + + DEBUG_MSG("payload length = %d", wsc_len + p2p_len); + + if (net_nfc_util_init_data(&payload, wsc_len + p2p_len) == true) { + ac_header_t *header; + data_s temp; + + /* serialize WSC properties */ + header = (ac_header_t *)payload.buffer; + + header->length = htons(wsc_len); + + temp.buffer = header->buffer; + temp.length = wsc_len; + + g_node_children_foreach(config->data, G_TRAVERSE_ALL, + _serialize_wsc_prop_cb, &temp); + + g_assert(wsc_len == temp.length); + + /* serialize P2P properties */ + header = (ac_header_t *)(header->buffer + wsc_len); + + header->length = htons(p2p_len); + + temp.buffer = header->buffer; + temp.length = p2p_len; + + g_node_children_foreach(config->data, G_TRAVERSE_ALL, + _serialize_p2p_prop_cb, &temp); + + g_assert(p2p_len == temp.length); + + /* create record */ + result = net_nfc_util_create_record(NET_NFC_RECORD_MIME_TYPE, + &type, NULL, &payload, record); + + net_nfc_util_clear_data(&payload); + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} diff --git a/src/commonlib/net_nfc_util_handover_wps.c b/src/commonlib/net_nfc_util_handover_wps.c new file mode 100644 index 0000000..eb76cf1 --- /dev/null +++ b/src/commonlib/net_nfc_util_handover_wps.c @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_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" + +bool net_nfc_util_handover_wps_check_carrier_record(ndef_record_s *record) +{ + bool result; + + g_assert(record != NULL); + + if ((record->type_s.length == CH_CAR_RECORD_TYPE_LEN) && + (memcmp(CH_CAR_RECORD_TYPE, record->type_s.buffer, + CH_CAR_RECORD_TYPE_LEN) == 0)) { + + /* FIXME */ + if ((record->type_s.length == CH_WIFI_WPS_MIME_LEN) && + (memcmp(CH_WIFI_WPS_MIME, record->type_s.buffer, + CH_WIFI_WPS_MIME_LEN) == 0)) { + result = true; + } else { + result = false; + } + } else if ((record->type_s.length == CH_WIFI_WPS_MIME_LEN) && + (memcmp(CH_WIFI_WPS_MIME, record->type_s.buffer, + CH_WIFI_WPS_MIME_LEN) == 0)) { + result = true; + } else { + result = false; + } + + return result; +} + +typedef struct _tlv_header_t +{ + uint16_t t; + uint16_t l; + uint8_t v[0]; +} +__attribute__((packed)) tlv_header_t; + +typedef void (*_parse_tlv_cb)(uint16_t t, uint16_t l, + uint8_t *v, void *user_data); + +static void _parse_tlv(uint8_t *buffer, uint32_t len, + _parse_tlv_cb cb, void *user_data) +{ + tlv_header_t *tlv; + uint32_t offset = 0; + uint16_t l; + + if (buffer == NULL || len == 0 || cb == NULL) + return; + + do + { + tlv = (tlv_header_t *)(buffer + offset); + l = htons(tlv->l); + cb(htons(tlv->t), l, tlv->v, user_data); + offset += sizeof(tlv_header_t) + l; + } + while (offset < len); +} + +static void _wifi_tlv_cb(uint16_t t, uint16_t l, + uint8_t *v, void *user_data) +{ + GNode *node = (GNode *)user_data; + net_nfc_carrier_property_s *elem; + + elem = g_new0(net_nfc_carrier_property_s, 1); + + elem->attribute = t; + elem->length = l; + + node = g_node_append_data(node, elem); + + if (t == NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL) { + elem->is_group = true; + elem->data = node; + + _parse_tlv(v, l, _wifi_tlv_cb, node); + } else { + elem->data = g_malloc0(l); + if(elem->data != NULL) + memcpy(elem->data, v, l); + } +} + +net_nfc_error_e net_nfc_util_handover_wps_create_config_from_record( + net_nfc_carrier_config_s **config, ndef_record_s *record) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_carrier_config_s *temp = NULL; + + if (record == NULL || config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + result = net_nfc_util_create_carrier_config(&temp, + NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P); + if (temp != NULL) { + temp->length = record->payload_s.length; + _parse_tlv(record->payload_s.buffer, record->payload_s.length, + _wifi_tlv_cb, temp->data); + *config = temp; + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} + +static void __calc_total_length_cb(GNode *node, gpointer data) +{ + net_nfc_carrier_property_s *info = node->data; + uint32_t *length = (uint32_t *)data; + + if (info == NULL) + return; + + *length += sizeof(tlv_header_t); + + if (info->is_group) { + uint32_t temp_len = 0; + + g_node_children_foreach(node, G_TRAVERSE_ALL, + __calc_total_length_cb, &temp_len); + + info->length = temp_len; + + *length += info->length; + } + else + { + *length += info->length; + } +} + +static uint32_t _calc_total_length(net_nfc_carrier_config_s *config) +{ + uint32_t result = 0; + + g_node_children_foreach(config->data, G_TRAVERSE_ALL, + __calc_total_length_cb, &result); + + config->length = result; + + return result; +} + +static void _serialize_cb(GNode *node, gpointer data) +{ + net_nfc_carrier_property_s *prop = node->data; + data_s *payload = (data_s *)data; + tlv_header_t *header; + + header = (tlv_header_t *)(payload->buffer + payload->length); + + header->t = htons(prop->attribute); + header->l = htons(prop->length); + + payload->length += sizeof(tlv_header_t); + + if (prop->is_group == true) { + g_node_children_foreach(node, G_TRAVERSE_ALL, + _serialize_cb, payload); + } else { + memcpy(header->v, prop->data, prop->length); + + payload->length += (prop->length); + } +} + +net_nfc_error_e net_nfc_util_handover_wps_create_record_from_config( + ndef_record_s **record, net_nfc_carrier_config_s *config) +{ + net_nfc_error_e result; + uint32_t len; + data_s payload = { 0, }; + data_s type = { (uint8_t *)CH_WIFI_P2P_MIME, CH_WIFI_P2P_MIME_LEN }; + + if (record == NULL || config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + len = _calc_total_length(config); + + DEBUG_MSG("payload length = %d", len); + + if (net_nfc_util_init_data(&payload, len) == true) { + g_node_children_foreach(config->data, G_TRAVERSE_ALL, + _serialize_cb, &payload); + + g_assert(len == payload.length); + + result = net_nfc_util_create_record(NET_NFC_RECORD_MIME_TYPE, + &type, NULL, &payload, record); + + net_nfc_util_clear_data(&payload); + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} diff --git a/src/commonlib/net_nfc_util_hce.c b/src/commonlib/net_nfc_util_hce.c new file mode 100755 index 0000000..f8c9a26 --- /dev/null +++ b/src/commonlib/net_nfc_util_hce.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +// platform header + +// nfc-manager header +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_util_hce.h" + +typedef struct _apdu_header_t +{ + uint8_t cla; + uint8_t ins; + uint8_t p1; + uint8_t p2; + uint8_t data[0]; +} +__attribute__((packed)) apdu_header_t; + +net_nfc_apdu_data_t *net_nfc_util_hce_create_apdu_data() +{ + net_nfc_apdu_data_t *apdu_data; + + apdu_data = g_new0(net_nfc_apdu_data_t, 1); + + apdu_data->cla = NET_NFC_HCE_INVALID_VALUE; + apdu_data->ins = NET_NFC_HCE_INVALID_VALUE; + apdu_data->p1 = NET_NFC_HCE_INVALID_VALUE; + apdu_data->p2 = NET_NFC_HCE_INVALID_VALUE; + + apdu_data->lc = NET_NFC_HCE_INVALID_VALUE; + apdu_data->le = NET_NFC_HCE_INVALID_VALUE; + apdu_data->data = NULL; + + return apdu_data; +} + +void net_nfc_util_hce_free_apdu_data(net_nfc_apdu_data_t *apdu_data) +{ + if (apdu_data != NULL) { + if (apdu_data->data != NULL) { + g_free(apdu_data->data); + } + + g_free(apdu_data); + } +} + +net_nfc_error_e net_nfc_util_hce_extract_parameter(data_s *apdu, + net_nfc_apdu_data_t *apdu_data) +{ + net_nfc_error_e result; + apdu_header_t *header; + size_t l = sizeof(*header); + + if (apdu == NULL || apdu->buffer == NULL || apdu_data == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (apdu->length < l) { + DEBUG_ERR_MSG("wrong length"); + + return NET_NFC_INVALID_PARAM; + } + + header = (apdu_header_t *)apdu->buffer; + + apdu_data->cla = header->cla; + apdu_data->ins = header->ins; + apdu_data->p1 = header->p1; + apdu_data->p2 = header->p2; + + apdu_data->lc = NET_NFC_HCE_INVALID_VALUE; + apdu_data->le = NET_NFC_HCE_INVALID_VALUE; + apdu_data->data = NULL; + + DEBUG_SERVER_MSG("[%02X][%02X][%02X][%02X]", header->cla, header->ins, header->p1, header->p2); + + if (apdu->length > l) { + if (apdu->length == l + 1) { + apdu_data->le = header->data[0]; + + result = NET_NFC_OK; + } else if (header->data[0] > 0) { + l += header->data[0] + 1; + + if (l == apdu->length || l + 1 == apdu->length) { + apdu_data->lc = header->data[0]; + + apdu_data->data = g_malloc0(apdu_data->lc); + if(apdu_data->data == NULL) + { + DEBUG_ERR_MSG("malloc failed"); + result = NET_NFC_ALLOC_FAIL; + } + else + { + memcpy(apdu_data->data, header->data + 1, apdu_data->lc); + + if (l + 1 == apdu->length) + apdu_data->le = header->data[apdu_data->lc + 1]; + + result = NET_NFC_OK; + } + } else { + DEBUG_ERR_MSG("l == len || l + 1 == len, [%d/%d]", apdu->length, l); + + result = NET_NFC_INVALID_PARAM; + } + } else { + DEBUG_ERR_MSG("header->data[0] == %d", header->data[0]); + + result = NET_NFC_INVALID_PARAM; + } + } else if (apdu->length == l) { + result = NET_NFC_OK; + } else { + DEBUG_ERR_MSG("len > l, [%d/%d]", apdu->length, l); + + result = NET_NFC_INVALID_PARAM; + } + + return result; +} + +net_nfc_error_e net_nfc_util_hce_generate_apdu(net_nfc_apdu_data_t *apdu_data, + data_s **apdu) +{ + return NET_NFC_NOT_SUPPORTED; +} diff --git a/src/commonlib/net_nfc_util_ndef_message.c b/src/commonlib/net_nfc_util_ndef_message.c new file mode 100755 index 0000000..61c5889 --- /dev/null +++ b/src/commonlib/net_nfc_util_ndef_message.c @@ -0,0 +1,908 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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" + +typedef struct _ndef_header_t +{ + uint8_t tnf : 3; + uint8_t il : 1; + uint8_t sr : 1; + uint8_t cf : 1; + uint8_t me : 1; + uint8_t mb : 1; + uint8_t type_len; + uint8_t payload_len[0]; +} +__attribute__((packed)) ndef_header_t; + +#define GET_PAYLOAD_LEN(__x) ((__x->sr) ? (__x->payload_len[0]) : \ + ((__x->payload_len[0] << 24) | (__x->payload_len[1] << 16) | \ + (__x->payload_len[2] << 8) | (__x->payload_len[3]))) + +static net_nfc_error_e __net_nfc_repair_record_flags(ndef_message_s *ndef_message); + +net_nfc_error_e net_nfc_util_check_ndef_message_rawdata(data_s *rawdata) +{ + uint32_t offset = 0, records = 0; + uint8_t *buffer; + uint32_t length, id_len, payload_len; + ndef_header_t *header = NULL; + + if (rawdata == NULL || rawdata->buffer == NULL || rawdata->length == 0) + return NET_NFC_NULL_PARAMETER; + + buffer = rawdata->buffer; + length = rawdata->length; + + while (offset < length) { + /* header */ + header = (ndef_header_t *)(buffer + offset); + + offset += sizeof(*header); + + if (offset >= length) { + DEBUG_ERR_MSG("header field failed, records [%d], offset [%d], length [%d]", records, offset, length); + return NET_NFC_BUFFER_TOO_SMALL; + } + + /* MB check */ + if (records == 0 && header->mb == 0) { + DEBUG_ERR_MSG("message doesn't begin with mb flag, records [%d], offset [%d], length [%d]", records, offset, length); + return NET_NFC_INVALID_FORMAT; + } + + if (header->sr == 1) { + offset++; + } else { + offset += 4; + } + + if (offset > length) { + DEBUG_ERR_MSG("payload length field failed, records [%d], offset [%d], length [%d]", records, offset, length); + return NET_NFC_BUFFER_TOO_SMALL; + } + + payload_len = GET_PAYLOAD_LEN(header); + + /* id */ + id_len = 0; + if (header->il == true) { + id_len = buffer[offset++]; + + if (offset >= length) { + DEBUG_ERR_MSG("id length field failed, records [%d], offset [%d], length [%d]", records, offset, length); + return NET_NFC_BUFFER_TOO_SMALL; + } + } + + /* calc data len */ + offset += header->type_len + id_len + payload_len; + if (offset > length) { + DEBUG_ERR_MSG("data fields failed, records [%d], offset [%d], length [%d]", records, offset, length); + return NET_NFC_BUFFER_TOO_SMALL; + } + + records++; + + if (header->me == 1) { + break; + } + } + + if (header != NULL && header->me == 0) { + DEBUG_ERR_MSG("me field is not set, records [%d], offset [%d], length [%d]", records, offset, length); + return NET_NFC_NDEF_BUF_END_WITHOUT_ME; + } + + if (offset < length) { + DEBUG_ERR_MSG("remain more buffer, records [%d], offset [%d], length [%d]", records, offset, length); + return NET_NFC_OUT_OF_BOUND; + } + + return NET_NFC_OK; +} + +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; +} + +void net_nfc_util_foreach_ndef_records(ndef_message_s *msg, + net_nfc_foreach_ndef_records_cb func, void *user_data) +{ + ndef_record_s *record; + + if (msg == NULL || func == NULL) + return; + + record = msg->records; + + while (record != NULL) { + func(record, user_data); + + record = record->next; + } + +} diff --git a/src/commonlib/net_nfc_util_ndef_record.c b/src/commonlib/net_nfc_util_ndef_record.c new file mode 100755 index 0000000..137c426 --- /dev/null +++ b/src/commonlib/net_nfc_util_ndef_record.c @@ -0,0 +1,386 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; + + net_nfc_util_clear_data(&record->type_s); + net_nfc_util_clear_data(&record->id_s); + net_nfc_util_clear_data(&record->payload_s); + + _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 (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 != NULL && typeName->length > 0) || + (payload != NULL && payload->length > 0) || + (id != NULL && id->length > 0)) { + return NET_NFC_INVALID_PARAM; + } + } + else + { + if (typeName == NULL || typeName->buffer == NULL || + typeName->length == 0) { + return NET_NFC_INVALID_PARAM; + } + } + + _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; + + if (typeName != NULL && typeName->length > 0) + { + if (net_nfc_util_init_data(&record_temp->type_s, typeName->length) == false) + { + _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; + } + + record_temp->SR = 1; + + // set payload + if (payload != NULL && payload->length > 0) + { + if (net_nfc_util_init_data(&record_temp->payload_s, payload->length) == false) + { + net_nfc_util_clear_data(&record_temp->type_s); + _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); + + if (payload->length > 255) + { + record_temp->SR = 0; + } + } + else + { + record_temp->payload_s.buffer = NULL; + record_temp->payload_s.length = 0; + } + + // set id and id length and IL field + if (id != NULL && id->buffer != NULL && id->length > 0) + { + if (net_nfc_util_init_data(&record_temp->id_s, id->length) == false) + { + net_nfc_util_clear_data(&record_temp->payload_s); + net_nfc_util_clear_data(&record_temp->type_s); + _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; + } + + if (net_nfc_util_init_data(&payload_data, payload_data.length) == false) + { + 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_clear_data(&payload_data); + + 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; + + if (net_nfc_util_init_data(&payload_data, payload_data.length) == false) + { + 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_clear_data(&payload_data); + + 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_clear_data(&record->id_s); + } + + if (net_nfc_util_init_data(&record->id_s, length) == false) + { + 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; +} diff --git a/src/commonlib/net_nfc_util_openssl.c b/src/commonlib/net_nfc_util_openssl.c new file mode 100755 index 0000000..a346927 --- /dev/null +++ b/src/commonlib/net_nfc_util_openssl.c @@ -0,0 +1,894 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include + +#include "net_nfc_typedef_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); + if(x509 == NULL) + return 0; + + 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()); + if(b64 == NULL) + return false; + + 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()); + if(b64 == NULL) + return false; + + 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 && length > 0) + { + *out_len = length; + memcpy(result, temp, *out_len); + ret = true; + } + else + { + DEBUG_ERR_MSG("not enough result buffer"); + } + + _net_nfc_util_free_mem(temp); + } + else + { + DEBUG_ERR_MSG("alloc failed"); + } + + return ret; +} + +bool net_nfc_util_openssl_digest(const char *algorithm, const uint8_t *buffer, const uint32_t buf_len, uint8_t *result, uint32_t *out_len) +{ + const EVP_MD *md; + unsigned char *temp; + bool ret = false; + + if (algorithm == NULL || buffer == NULL || buf_len == 0) + { + return ret; + } + + OpenSSL_add_all_digests(); + + if ((md = EVP_get_digestbyname(algorithm)) != NULL) + { + _net_nfc_util_alloc_mem(temp, EVP_MAX_MD_SIZE); + if (temp != NULL) + { + EVP_MD_CTX mdCtx; + unsigned int resultLen = 0; + + memset(temp, 0, EVP_MAX_MD_SIZE); + + EVP_DigestInit(&mdCtx, md); + if (EVP_DigestUpdate(&mdCtx, buffer, buf_len) != 0) + { + DEBUG_ERR_MSG("EVP_DigestUpdate failed"); + } + EVP_DigestFinal(&mdCtx, temp, &resultLen); + + if (*out_len >= resultLen) + { + *out_len = resultLen; + memcpy(result, temp, *out_len); + ret = true; + } + else + { + DEBUG_ERR_MSG("not enough result buffer"); + } + + _net_nfc_util_free_mem(temp); + } + else + { + DEBUG_ERR_MSG("alloc failed"); + } + } + else + { + DEBUG_ERR_MSG("EVP_get_digestbyname(\"%s\") returns NULL", algorithm); + } + + return ret; +} diff --git a/src/commonlib/net_nfc_util_sign_record.c b/src/commonlib/net_nfc_util_sign_record.c new file mode 100644 index 0000000..97a5b0c --- /dev/null +++ b/src/commonlib/net_nfc_util_sign_record.c @@ -0,0 +1,421 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include "net_nfc_debug_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" + +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 SIGNATURE_RECORD_TYPE "Sig" + +#define IS_SIGN_RECORD(__x) \ + (((__x)->TNF == NET_NFC_RECORD_WELL_KNOWN_TYPE) && \ + ((__x)->type_s.length == 3) && \ + (memcmp((__x)->type_s.buffer, SIGNATURE_RECORD_TYPE, 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("certificate 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, signature, sign_len) == 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(); + if(context == NULL) + { + _net_nfc_util_free_mem(buffer); + return NET_NFC_ALLOC_FAIL; + } + + /* 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); + + _net_nfc_util_free_mem(data_buffer); + + /* 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; + + if (net_nfc_util_init_data(&payload, payload.length) == false) { + _net_nfc_util_free_mem(cert_buffer); + result = NET_NFC_ALLOC_FAIL; + + return result; + } + + 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 *)SIGNATURE_RECORD_TYPE, 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); + + result = NET_NFC_OK; + + net_nfc_util_clear_data(&payload); + _net_nfc_util_free_mem(cert_buffer); + + return result; +} + +net_nfc_error_e net_nfc_util_sign_ndef_message(ndef_message_s *msg, char *cert_file, char *password) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + + if (msg->recordCount > 0) + { + net_nfc_util_sign_records(msg, 0, msg->recordCount - 1, cert_file, password); + + result = NET_NFC_OK; + } + + return result; +} diff --git a/src/commonlib/nfc-common-lib.pc.in b/src/commonlib/nfc-common-lib.pc.in new file mode 100755 index 0000000..30c2054 --- /dev/null +++ b/src/commonlib/nfc-common-lib.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix}/bin +libdir=@LIB_INSTALL_DIR@ +includedir=@INCLUDE_INSTALL_DIR@/nfc-common-lib + +Name: nfc-common-lib +Description: NFC Common Library +Version: 1.0 +Requires: +Libs: -L@LIB_INSTALL_DIR@ -lnfc-common-lib +Cflags: -I@INCLUDE_INSTALL_DIR@/nfc-common-lib diff --git a/src/manager/CMakeLists.txt b/src/manager/CMakeLists.txt old mode 100644 new mode 100755 index d712b6d..ae74339 --- a/src/manager/CMakeLists.txt +++ b/src/manager/CMakeLists.txt @@ -4,23 +4,28 @@ PROJECT(nfc-manager-daemon C) SET(NFC_MANAGER_DAEMON "nfc-manager-daemon") -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../commonlib/include) +include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/) +include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/addons/include) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ MANAGER_SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/addons MANAGER_SRCS) IF("${CMAKE_BUILD_TYPE}" STREQUAL "") SET(CMAKE_BUILD_TYPE "Release") ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") -IF(X11_SUPPORT) - SET(WIN_PKG "ecore-x") -ENDIF(X11_SUPPORT) -IF(WAYLAND_SUPPORT) - SET(WIN_PKG "${WIN_PKG} ecore-wayland") -ENDIF(WAYLAND_SUPPORT) +# for package file +SET(dependents "aul glib-2.0 gio-unix-2.0 vconf dlog tapi appsvc libcurl bluetooth-api capi-network-bluetooth openssl deviced feedback capi-media-wav-player mm-keysound syspopup-caller notification capi-network-wifi capi-system-info sqlite3 libprivilege-control") + +#IF (TIZEN_TELEPHONY_ENABLED) + #MESSAGE("-DENABLE_TELEPHONY") + #ADD_DEFINITIONS(-DENABLE_TELEPHONY) +#ENDIF (TIZEN_TELEPHONY_ENABLED) + INCLUDE(FindPkgConfig) -pkg_check_modules(manager_pkges REQUIRED aul glib-2.0 gobject-2.0 security-server dbus-glib-1 vconf dlog tapi appsvc libcurl bluetooth-api heynoti smartcard-service smartcard-service-common libssl pmapi svi capi-media-wav-player pkgmgr pkgmgr-info ${WIN_PKG}) +pkg_check_modules(manager_pkges REQUIRED ${dependents}) FOREACH(flag ${manager_pkges_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -47,38 +52,25 @@ IF("${ARCH}" MATCHES "^arm.*") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}") ENDIF() -ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") -#ADD_DEFINITIONS("-DSLP_DEBUG") -ADD_DEFINITIONS("-DCLIENT_IPC_THREAD") - -ADD_DEFINITIONS("-DNFC_FIRMWARE_UPDATE") -ADD_DEFINITIONS("-DNFC_DEBUG_USE_DLOG -D_GNU_SOURCE") -ADD_DEFINITIONS("-DUSE_UNIX_DOMAIN") -ADD_DEFINITIONS("-DUSE_IPC_EPOLL -DUSE_EPOLL_TIMEOUT") -ADD_DEFINITIONS("-DLLCP_MODE") -ADD_DEFINITIONS("-DNFC_APP_SUPPORTED") -ADD_DEFINITIONS("-DBROADCAST_MESSAGE") -ADD_DEFINITIONS("-DSAVE_TARGET_INFO_IN_CC") -#ADD_DEFINITIONS("-DSECURITY_SERVER") -#ADD_DEFINITIONS("-DG_MAIN_LOOP") -#ADD_DEFINITIONS("-DUSE_ECORE_MAIN_LOOP") -ADD_DEFINITIONS("-DUSE_GLIB_MAIN_LOOP") -ADD_DEFINITIONS("-DUSE_FULL_URI") -# add temporary -ADD_DEFINITIONS("-D_TIZEN_OPEN") +# for addons +ADD_DEFINITIONS("-DADDON_HCE_NDEF") +#ADD_DEFINITIONS("-DADDON_HCE_PPSE") +#ADD_DEFINITIONS("-DADDON_HCE_TMONEY") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") -FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool) -EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=nfc_service ${CMAKE_CURRENT_SOURCE_DIR}/nfc-service.xml --mode=glib-client --output=${CMAKE_CURRENT_SOURCE_DIR}/include/nfc-service-glue.h") -EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=nfc_service ${CMAKE_CURRENT_SOURCE_DIR}/nfc-service.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/nfc-service-binding.h") +ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") +ADD_DEFINITIONS("-DNFC_MANAGER_MODULEDIR=\"${MODULEDIR}\"") -ADD_EXECUTABLE(${NFC_MANAGER_DAEMON} ${MANAGER_SRCS}) +ADD_DEFINITIONS("-DUSE_FULL_URI") +#ADD_DEFINITIONS("-DESE_ALWAYS_ON") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") -TARGET_LINK_LIBRARIES(${NFC_MANAGER_DAEMON} ${manager_pkges_LDFLAGS} "-lpthread -lrt -pie -ldl -L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/commonlib/ -lnfc-common-lib -L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/clientlib/ -lnfc") +ADD_EXECUTABLE(${NFC_MANAGER_DAEMON} ${MANAGER_SRCS}) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.tizen.nfc_service.service DESTINATION share/dbus-1/services) -INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/sounds DESTINATION /usr/share/nfc-manager-daemon) +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/system-services) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/sounds DESTINATION share/nfc-manager-daemon) diff --git a/src/manager/addons/include/net_nfc_addon_hce.h b/src/manager/addons/include/net_nfc_addon_hce.h new file mode 100755 index 0000000..4a0845d --- /dev/null +++ b/src/manager/addons/include/net_nfc_addon_hce.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_ADDON_HCE_H__ +#define __NET_NFC_ADDON_HCE_H__ + +#include "net_nfc_typedef_internal.h" + +#include "net_nfc_util_hce.h" +#include "net_nfc_server_hce.h" +#include "net_nfc_server_addon.h" + +typedef struct _net_nfc_addon_hce_ops_t +{ + const char *name; + + net_nfc_addon_init init; + net_nfc_addon_pause pause; + net_nfc_addon_resume resume; + net_nfc_addon_deinit deinit; + + const char *aid; + net_nfc_server_hce_listener_cb listener; +} +net_nfc_addon_hce_ops_t; + +#endif // __NET_NFC_ADDON_HCE_H__ diff --git a/src/manager/addons/include/net_nfc_addon_hce_ndef.h b/src/manager/addons/include/net_nfc_addon_hce_ndef.h new file mode 100644 index 0000000..65a2a31 --- /dev/null +++ b/src/manager/addons/include/net_nfc_addon_hce_ndef.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_ADDON_HCE_NDEF_H__ +#define __NET_NFC_ADDON_HCE_NDEF_H__ + +#include "net_nfc_typedef_internal.h" + +void net_nfc_addon_hce_ndef_enable(void); +net_nfc_error_e net_nfc_addon_hce_ndef_set_data(data_s *data); +void net_nfc_addon_hce_ndef_disable(void); + +#endif // __NET_NFC_ADDON_HCE_NDEF_H__ diff --git a/src/manager/addons/include/net_nfc_addons.h b/src/manager/addons/include/net_nfc_addons.h new file mode 100755 index 0000000..073ad5e --- /dev/null +++ b/src/manager/addons/include/net_nfc_addons.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_ADDONS_H__ +#define __NET_NFC_ADDONS_H__ + +#include "net_nfc_typedef_internal.h" + +net_nfc_error_e net_nfc_addons_init(void); +net_nfc_error_e net_nfc_addons_pause(void); +net_nfc_error_e net_nfc_addons_resume(void); +net_nfc_error_e net_nfc_addons_deinit(void); + +#endif // __NET_NFC_ADDON_H__ diff --git a/src/manager/addons/net_nfc_addon_hce.c b/src/manager/addons/net_nfc_addon_hce.c new file mode 100755 index 0000000..4bf2b68 --- /dev/null +++ b/src/manager/addons/net_nfc_addon_hce.c @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_internal.h" +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_util_hce.h" +#include "net_nfc_addon_hce.h" +#include "net_nfc_server_route_table.h" + +#ifdef ADDON_HCE_NDEF +extern net_nfc_addon_hce_ops_t net_nfc_addon_hce_ndef_ops; +#endif +#ifdef ADDON_HCE_PPSE +extern net_nfc_addon_hce_ops_t net_nfc_addon_hce_ppse_ops; +#endif +#ifdef ADDON_HCE_TMONEY +extern net_nfc_addon_hce_ops_t net_nfc_addon_hce_tmoney_ops; +#endif + +net_nfc_addon_hce_ops_t *hce_addons[] = { +#ifdef ADDON_HCE_NDEF + &net_nfc_addon_hce_ndef_ops, +#endif +#ifdef ADDON_HCE_PPSE + &net_nfc_addon_hce_ppse_ops, +#endif +#ifdef ADDON_HCE_TMONEY + &net_nfc_addon_hce_tmoney_ops, +#endif + NULL, +}; + +size_t hce_addons_count = (sizeof(hce_addons) / sizeof(net_nfc_addon_hce_ops_t *)) - 1; + +static net_nfc_addon_hce_ops_t *selected_ops; + + +static void __process_command(net_nfc_target_handle_s *handle, data_s *data) +{ + net_nfc_apdu_data_t *apdu_data; + + apdu_data = net_nfc_util_hce_create_apdu_data(); + + if (net_nfc_util_hce_extract_parameter(data, apdu_data) == NET_NFC_OK) { + if (apdu_data->ins == NET_NFC_HCE_INS_SELECT) { + if (apdu_data->p1 == NET_NFC_HCE_P1_SELECT_BY_NAME) { + char aid[1024]; + int i; + data_s temp = { apdu_data->data, apdu_data->lc }; + + net_nfc_util_binary_to_hex_string(&temp, aid, sizeof(aid)); + + for (i = 0; i < hce_addons_count; i++) { + if (g_ascii_strcasecmp(hce_addons[i]->aid, aid) == 0) { + selected_ops = hce_addons[i]; + break; + } + } + + if (i == hce_addons_count) { + /** NOT FOUND??? */ + DEBUG_ERR_MSG("NOT FOUND???"); + } + } else { + + } + } + + if (selected_ops == NULL) { + DEBUG_ERR_MSG("NOT SELECTED"); + } else { + selected_ops->listener(handle, + NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA, + data, NULL); + } + } + + net_nfc_util_hce_free_apdu_data(apdu_data); +} + +static void __hce_listener(net_nfc_target_handle_s *handle, int event, + data_s *data, void *user_data) +{ + switch (event) { + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED"); + break; + + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA"); + __process_command(handle, data); + break; + + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_DEACTIVATED : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_DEACTIVATED"); + break; + + default : + break; + } +} + +static void _nfc_addon_hce_init(void) +{ + int i; + + DEBUG_ADDON_MSG(">>>>"); + + net_nfc_server_route_table_init(); + + net_nfc_server_hce_start_hce_handler("nfc-manager", NULL, + __hce_listener, NULL, NULL); + + for (i = 0; i < hce_addons_count; i++) { + hce_addons[i]->init(); + } +} + +static void _nfc_addon_hce_pause(void) +{ + int i; + + DEBUG_ADDON_MSG(">>>>"); + + for (i = 0; i < hce_addons_count; i++) { + hce_addons[i]->pause(); + } +} + +static void _nfc_addon_hce_resume(void) +{ + int i; + + DEBUG_ADDON_MSG(">>>>"); + + for (i = 0; i < hce_addons_count; i++) { + hce_addons[i]->resume(); + } +} + +static void _nfc_addon_hce_deinit(void) +{ + int i; + + DEBUG_ADDON_MSG(">>>>"); + + for (i = 0; i < hce_addons_count; i++) { + hce_addons[i]->deinit(); + } + + net_nfc_server_hce_stop_hce_handler("nfc-manager"); +} + +net_nfc_addon_ops_t net_nfc_addon_hce_ops = { + .name = "HCE EMUL", + .init = _nfc_addon_hce_init, + .pause = _nfc_addon_hce_pause, + .resume = _nfc_addon_hce_resume, + .deinit = _nfc_addon_hce_deinit, +}; diff --git a/src/manager/addons/net_nfc_addon_hce_ndef.c b/src/manager/addons/net_nfc_addon_hce_ndef.c new file mode 100755 index 0000000..1de6c95 --- /dev/null +++ b/src/manager/addons/net_nfc_addon_hce_ndef.c @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "vconf.h" +#include +#include + +#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_server_route_table.h" +#include "net_nfc_addon_hce.h" +#include "net_nfc_addon_hce_ndef.h" + + +#define MAPPING_VERSION 0x20 + +#define NDEF_FILE_CONTROL_TAG 0x04 +#define PROPRIETARY_FILE_CONTROL_TAG 0x05 + +#define MAX_NDEF_LEN 0x1000 +#define MAX_NDEF_DEF 0x10, 0x00 + +#define COND_ALL_ACCESS 0x00 +#define COND_NO_ACCESS 0xFF + +#define CC_FID 0xE1, 0x03 +#define NDEF_FID 0xE1, 0x05 + +#define ENDIAN_16(x) ((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00)) + +#define NDEF_AID "D2760000850101" /* 00A4040007D2760000850101 */ + +typedef struct _cc_data_t +{ + uint16_t cclen; + uint8_t version; + uint16_t mle; + uint16_t mlc; + struct + { + uint8_t tag; + uint8_t len; + uint16_t fid; + uint16_t mndef; + uint8_t rcond; + uint8_t wcond; + } + cc; + uint8_t tlv[0]; +} +__attribute__((packed)) cc_data_t; + +typedef struct _ndef_data_t +{ + uint16_t len; + uint8_t data[0]; +} +__attribute__((packed)) ndef_data_t; + +static uint8_t ndef_aid[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01 }; +static uint8_t cc_fid[] = { CC_FID }; +static uint8_t ndef_fid[] = { NDEF_FID }; + +static uint8_t cc_data[] = { + 0x00, 0x0F, /* cclen */ + MAPPING_VERSION, /* version */ + 0x00, 0x3B, /* max lc */ + 0x00, 0x34, /* max le */ + NDEF_FILE_CONTROL_TAG, /* tag */ + 0x06, /* len */ + NDEF_FID, /* ndef fid */ + MAX_NDEF_DEF, /* max ndef len */ + COND_ALL_ACCESS, /* read right */ + COND_NO_ACCESS, /* write right */ +}; + +static uint16_t ndef_len; +static ndef_data_t *ndef_data; + +static uint8_t *selected_aid; +static uint8_t *selected_fid; + +static bool enabled; + +static void __send_response(net_nfc_target_handle_s *handle, uint16_t sw, uint8_t *resp, size_t len) +{ + size_t total_len = sizeof(sw); + size_t offset = 0; + uint8_t *buffer; + + sw = ENDIAN_16(sw); + + if (resp != NULL && len > 0) { + total_len += len; + } + + buffer = g_malloc0(total_len); + + if (resp != NULL && len > 0) { + memcpy(buffer + offset, resp, len); + offset += len; + } + + memcpy(buffer + offset, &sw, sizeof(sw)); + + /* send */ + data_s temp = { buffer, total_len }; + + net_nfc_server_hce_send_apdu_response(handle, &temp); + + g_free(buffer); +} + +static void __process_command(net_nfc_target_handle_s *handle, data_s *cmd) +{ + net_nfc_apdu_data_t *apdu; + + apdu = net_nfc_util_hce_create_apdu_data(); + + if (net_nfc_util_hce_extract_parameter(cmd, apdu) != NET_NFC_OK) { + DEBUG_ERR_MSG("wrong length"); + __send_response(handle, NET_NFC_HCE_SW_WRONG_LENGTH, NULL, 0); + goto END; + } + + if (apdu->ins == NET_NFC_HCE_INS_SELECT) { + if (apdu->lc < 2 || apdu->data == NULL) { + DEBUG_ERR_MSG("wrong parameter"); + __send_response(handle, NET_NFC_HCE_SW_LC_INCONSIST_P1_TO_P2, NULL, 0); + goto END; + } + + if (apdu->p1 == NET_NFC_HCE_P1_SELECT_BY_NAME) { + if (memcmp(apdu->data, ndef_aid, + MIN(sizeof(ndef_aid), apdu->lc)) == 0) { + DEBUG_SERVER_MSG("select ndef applet"); + + /* bt on */ + /* fill bt address */ + + selected_aid = ndef_aid; + + __send_response(handle, NET_NFC_HCE_SW_SUCCESS, NULL, 0); + } else { + DEBUG_ERR_MSG("application not found"); + __send_response(handle, NET_NFC_HCE_SW_FILE_NOT_FOUND, NULL, 0); + } + } else if (apdu->p1 == NET_NFC_HCE_P1_SELECT_BY_FID) { + if (selected_aid == NULL) { + DEBUG_ERR_MSG("need to select ndef applet"); + __send_response(handle, NET_NFC_HCE_SW_FILE_NOT_FOUND, NULL, 0); + goto END; + } + + if (apdu->lc != 2) { + DEBUG_ERR_MSG("wrong parameter"); + __send_response(handle, NET_NFC_HCE_SW_INCORRECT_P1_TO_P2, NULL, 0); + goto END; + } + + if (memcmp(apdu->data, cc_fid, + MIN(sizeof(cc_fid), apdu->lc)) == 0) { + DEBUG_SERVER_MSG("select capability container"); + + selected_fid = cc_fid; + + __send_response(handle, NET_NFC_HCE_SW_SUCCESS, NULL, 0); + } else if (memcmp(apdu->data, ndef_fid, + MIN(sizeof(ndef_fid), apdu->lc)) == 0) { + DEBUG_SERVER_MSG("select ndef"); + + selected_fid = ndef_fid; + + __send_response(handle, NET_NFC_HCE_SW_SUCCESS, NULL, 0); + } else { + DEBUG_ERR_MSG("application not found"); + __send_response(handle, NET_NFC_HCE_SW_FILE_NOT_FOUND, NULL, 0); + } + } else { + + } + } else if (apdu->ins == NET_NFC_HCE_INS_READ_BINARY) { + if (apdu->lc != NET_NFC_HCE_INVALID_VALUE || + apdu->data != NULL || apdu->le == NET_NFC_HCE_INVALID_VALUE) { + DEBUG_ERR_MSG("wrong parameter, lc [%d], data [%p], le [%d]", apdu->lc, apdu->data, apdu->le); + __send_response(handle, NET_NFC_HCE_SW_LC_INCONSIST_P1_TO_P2, NULL, 0); + goto END; + } + + if (selected_fid == cc_fid) { + uint16_t offset; + + offset = apdu->p1 << 8 | apdu->p2; + if (offset < sizeof(cc_data)) { + /* send response */ + + __send_response(handle, NET_NFC_HCE_SW_SUCCESS, + cc_data + offset, + MIN(sizeof(cc_data) - offset, apdu->le)); + } else { + DEBUG_ERR_MSG("abnormal offset, [%d]", offset); + __send_response(handle, NET_NFC_HCE_SW_INCORRECT_P1_TO_P2, NULL, 0); + } + } else if (selected_fid == ndef_fid) { + uint16_t offset; + + offset = apdu->p1 << 8 | apdu->p2; + if (offset < ndef_data->len + sizeof(*ndef_data)) { + /* send response */ + + __send_response(handle, NET_NFC_HCE_SW_SUCCESS, + (uint8_t *)ndef_data + offset, + MIN(ndef_data->len + sizeof(*ndef_data) - offset, apdu->le)); + } else { + DEBUG_ERR_MSG("abnormal offset, [%d]", offset); + __send_response(handle, NET_NFC_HCE_SW_INCORRECT_P1_TO_P2, NULL, 0); + } + } else { + DEBUG_ERR_MSG("not supported"); + __send_response(handle, NET_NFC_HCE_SW_FUNC_NOT_SUPPORTED, NULL, 0); + } + } else if (apdu->ins == NET_NFC_HCE_INS_UPDATE_BINARY) { + DEBUG_ERR_MSG("not supported"); + __send_response(handle, NET_NFC_HCE_SW_INS_NOT_SUPPORTED, NULL, 0); + } else { + DEBUG_ERR_MSG("not supported"); + __send_response(handle, NET_NFC_HCE_SW_INS_NOT_SUPPORTED, NULL, 0); + } + +END : + if (apdu != NULL) { + net_nfc_util_hce_free_apdu_data(apdu); + } +} + +static void __nfc_addon_hce_ndef_listener(net_nfc_target_handle_s *handle, + int event, data_s *data, void *user_data) +{ + switch (event) { + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED"); + selected_fid = NULL; + selected_aid = NULL; + break; + + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA"); + __process_command(handle, data); + break; + + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_DEACTIVATED : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_DEACTIVATED"); + selected_fid = NULL; + selected_aid = NULL; + break; + + default : + break; + } +} + +static void __nfc_addon_hce_ndef_init(void) +{ + DEBUG_ADDON_MSG(">>>>"); + + enabled = false; + ndef_len = MAX_NDEF_LEN; + ndef_data = g_malloc0(ndef_len); +} + +static void __nfc_addon_hce_ndef_pause(void) +{ + DEBUG_ADDON_MSG(">>>>"); +} + +static void __nfc_addon_hce_ndef_resume(void) +{ + DEBUG_ADDON_MSG(">>>>"); +} + +static void __nfc_addon_hce_ndef_deinit(void) +{ + DEBUG_ADDON_MSG(">>>>"); + + net_nfc_addon_hce_ndef_disable(); + + g_free(ndef_data); +} + +net_nfc_addon_hce_ops_t net_nfc_addon_hce_ndef_ops = { + .name = "HCE NDEF EMUL", + .init = __nfc_addon_hce_ndef_init, + .pause = __nfc_addon_hce_ndef_pause, + .resume = __nfc_addon_hce_ndef_resume, + .deinit = __nfc_addon_hce_ndef_deinit, + + .aid = NDEF_AID, + .listener = __nfc_addon_hce_ndef_listener, +}; + +void net_nfc_addon_hce_ndef_enable(void) +{ + net_nfc_error_e result = NET_NFC_OK; + + if (enabled == false) { + if (net_nfc_server_route_table_find_aid("nfc-manager", + NDEF_AID) == NULL) { + result = net_nfc_server_route_table_add_aid(NULL, "nfc-manager", + NET_NFC_SE_TYPE_HCE, + NET_NFC_CARD_EMULATION_CATEGORY_OTHER, + NDEF_AID); + } + + if (result == NET_NFC_OK) { + enabled = true; + } else { + DEBUG_ERR_MSG("net_nfc_server_route_table_add_aid failed, [%d]", result); + } + } +} + +net_nfc_error_e net_nfc_addon_hce_ndef_set_data(data_s *data) +{ + if (data == NULL || data->buffer == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + if (data->length > (ndef_len - sizeof(*ndef_data))) { + return NET_NFC_INSUFFICIENT_STORAGE; + } + + ndef_data->len = ENDIAN_16((uint16_t)data->length); + memcpy(ndef_data->data, data->buffer, data->length); + + return NET_NFC_OK; +} + +void net_nfc_addon_hce_ndef_disable(void) +{ + if (enabled == true) { + if (net_nfc_server_route_table_find_aid("nfc-manager", + NDEF_AID) != NULL) { + net_nfc_server_route_table_del_aid(NULL, "nfc-manager", + NDEF_AID, false); + } + + enabled = false; + } +} diff --git a/src/manager/addons/net_nfc_addon_hce_ppse.c b/src/manager/addons/net_nfc_addon_hce_ppse.c new file mode 100755 index 0000000..a0bbc06 --- /dev/null +++ b/src/manager/addons/net_nfc_addon_hce_ppse.c @@ -0,0 +1,301 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_internal.h" +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_util_hce.h" +#include "net_nfc_server_route_table.h" +#include "net_nfc_addon_hce.h" + + +#define PPSE_INS_LOOPBACK 0xEE + +#define ENDIAN_16(x) ((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00)) + +#define PPSE_AID "325041592E5359532E4444463031" /* 00A404000E325041592E5359532E4444463031 */ + +/* "2PAY.SYS.DDF01" */ +static uint8_t ppse_aid[] = { '2', 'P', 'A', 'Y', '.', 'S', 'Y', 'S', '.', 'D', 'D', 'F', '0', '1' }; + +static bool selected; + +static size_t __put_tlv(uint8_t *out, size_t len, + uint16_t t, uint16_t l, uint8_t *v) +{ + size_t offset = 0; + + /* t */ + if (t & 0xFF00) { + out[offset++] = (t & 0xFF00) >> 8; + out[offset++] = t & 0x00FF; + } else { + out[offset++] = t & 0x00FF; + } + + /* l */ + if (l & 0xFF00) { + out[offset++] = (l & 0xFF00) >> 8; + out[offset++] = l & 0x00FF; + } else { + out[offset++] = l & 0x00FF; + } + + /* v */ + memcpy(out + offset, v, l); + offset += l; + + return offset; +} + +static size_t __fill_fci(uint8_t *tlv, size_t len, data_s *aid, data_s *label, + uint8_t priority) +{ + uint8_t result[1024] = { 0, }; + uint8_t temp[1024] = { 0, }; + size_t offset = 0, temp_len; + + /* aid */ + offset = __put_tlv(temp, sizeof(temp), 0x4F, aid->length, aid->buffer); + + /* label */ + offset += __put_tlv(temp + offset, sizeof(temp) - offset, 0x50, + label->length, label->buffer); + + /* priority */ + offset += __put_tlv(temp + offset, sizeof(temp) - offset, 0x82, + sizeof(priority), &priority); + + + /* FCI issuer descretionary data */ + temp_len = __put_tlv(result, sizeof(result), 0xBF0C, offset, temp); + + /* DF name */ + offset = __put_tlv(temp, sizeof(temp), 0x84, sizeof(ppse_aid), ppse_aid); + + /* FCI proprietary template */ + offset += __put_tlv(temp + offset, sizeof(result) - offset, 0xA5, + temp_len, result); + + + offset = __put_tlv(result, sizeof(result), 0x6F, offset, temp); + + memcpy(tlv, result, offset); + + return offset; +} + +static void __send_response(net_nfc_target_handle_s *handle, uint16_t sw, uint8_t *resp, size_t len) +{ + size_t total_len = sizeof(sw); + size_t offset = 0; + uint8_t *buffer; + + sw = ENDIAN_16(sw); + + if (resp != NULL && len > 0) { + total_len += len; + } + + buffer = g_malloc0(total_len); + + if (resp != NULL && len > 0) { + memcpy(buffer + offset, resp, len); + offset += len; + } + + memcpy(buffer + offset, &sw, sizeof(sw)); + + /* send */ + data_s temp = { buffer, total_len }; + + net_nfc_server_hce_send_apdu_response(handle, &temp); + + g_free(buffer); +} + +static void __process_command(net_nfc_target_handle_s *handle, data_s *cmd) +{ + net_nfc_apdu_data_t *apdu; + + apdu = net_nfc_util_hce_create_apdu_data(); + + if (net_nfc_util_hce_extract_parameter(cmd, apdu) != NET_NFC_OK) { + DEBUG_ERR_MSG("wrong length"); + __send_response(handle, NET_NFC_HCE_SW_WRONG_LENGTH, NULL, 0); + goto END; + } + + if (apdu->ins == NET_NFC_HCE_INS_SELECT) { + if (apdu->lc < 2 || apdu->data == NULL) { + DEBUG_ERR_MSG("wrong parameter"); + __send_response(handle, NET_NFC_HCE_SW_LC_INCONSIST_P1_TO_P2, NULL, 0); + goto END; + } + + if (apdu->p1 != NET_NFC_HCE_P1_SELECT_BY_NAME || + apdu->p2 != 0) { + DEBUG_ERR_MSG("incorrect parameter"); + __send_response(handle, NET_NFC_HCE_SW_INCORRECT_P1_TO_P2, NULL, 0); + goto END; + } + + if (memcmp(apdu->data, ppse_aid, MIN(sizeof(ppse_aid), apdu->lc)) == 0) { + uint8_t buffer[1024]; + size_t len; + uint8_t temp_aid[] = { 0x12, 0x34, 0x56, 0x78, 0x90 }; + data_s aid = { temp_aid, sizeof(temp_aid) }; + uint8_t temp_label[] = { 'T', 'E', 'S', 'T' }; + data_s label = { temp_label, sizeof(temp_label) }; + + DEBUG_SERVER_MSG("select ppse applet"); + + len = __fill_fci(buffer, sizeof(buffer), &aid, &label, 1); + + selected = true; + + __send_response(handle, NET_NFC_HCE_SW_SUCCESS, buffer, len); + } else { + DEBUG_ERR_MSG("application not found"); + __send_response(handle, NET_NFC_HCE_SW_FILE_NOT_FOUND, NULL, 0); + } + } else if (apdu->ins == PPSE_INS_LOOPBACK) { + if (selected == false) { + DEBUG_ERR_MSG("need to select applet"); + __send_response(handle, NET_NFC_HCE_SW_COMMAND_NOT_ALLOWED, NULL, 0); + goto END; + } + + if (apdu->cla == 0x80) { + DEBUG_ERR_MSG("wrong cla, cla [%02X]", apdu->cla); + __send_response(handle, NET_NFC_HCE_SW_CLASS_NOT_SUPPORTED, NULL, 0); + goto END; + } + + if (apdu->p1 != 0 || apdu->p2 != 0) { + DEBUG_ERR_MSG("incorrect parameter, p1 [%02X], p2 [%02X]", apdu->p1, apdu->p2); + __send_response(handle, NET_NFC_HCE_SW_INCORRECT_P1_TO_P2, NULL, 0); + goto END; + } + + if (apdu->lc == NET_NFC_HCE_INVALID_VALUE || + apdu->lc == 0 || apdu->data == NULL || + apdu->le == NET_NFC_HCE_INVALID_VALUE) { + DEBUG_ERR_MSG("wrong parameter, lc [%d], data [%p], le [%d]", apdu->lc, apdu->data, apdu->le); + __send_response(handle, NET_NFC_HCE_SW_LC_INCONSIST_P1_TO_P2, NULL, 0); + goto END; + } + + DEBUG_SERVER_MSG("ppse loopback"); + + if (apdu->le == 0) { + apdu->le = 255; + } + + __send_response(handle, NET_NFC_HCE_SW_SUCCESS, + apdu->data, + MIN(apdu->lc, apdu->le)); + } else { + DEBUG_ERR_MSG("not supported"); + __send_response(handle, NET_NFC_HCE_SW_INS_NOT_SUPPORTED, NULL, 0); + } + +END : + if (apdu != NULL) { + net_nfc_util_hce_free_apdu_data(apdu); + } +} + +static void __nfc_addon_hce_ppse_listener(net_nfc_target_handle_s *handle, + int event, data_s *data, void *user_data) +{ + switch (event) { + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED"); + selected = false; + break; + + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA"); + __process_command(handle, data); + break; + + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_DEACTIVATED : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_DEACTIVATED"); + selected = false; + break; + + default : + break; + } +} + +static void _nfc_plugin_hce_ppse_init(void) +{ + DEBUG_ADDON_MSG(">>>>"); + + if (net_nfc_server_route_table_find_aid("nfc-manager", + PPSE_AID) == NULL) { + net_nfc_error_e result; + + result = net_nfc_server_route_table_add_aid(NULL, "nfc-manager", + NET_NFC_SE_TYPE_HCE, + NET_NFC_CARD_EMULATION_CATEGORY_OTHER, + PPSE_AID); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_server_route_table_add_aid failed, [%d]", result); + } + } +} + +static void _nfc_plugin_hce_ppse_pause(void) +{ + DEBUG_ADDON_MSG(">>>>"); +} + +static void _nfc_plugin_hce_ppse_resume(void) +{ + DEBUG_ADDON_MSG(">>>>"); +} + +static void _nfc_plugin_hce_ppse_deinit(void) +{ + DEBUG_ADDON_MSG(">>>>"); + + if (net_nfc_server_route_table_find_aid("nfc-manager", + PPSE_AID) == NULL) { + net_nfc_error_e result; + + result = net_nfc_server_route_table_del_aid(NULL, "nfc-manager", PPSE_AID, false); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_server_route_table_del_aid failed, [%d]", result); + } + } +} + +net_nfc_addon_hce_ops_t net_nfc_addon_hce_ppse_ops = { + .name = "HCE PPSE EMUL", + .init = _nfc_plugin_hce_ppse_init, + .pause = _nfc_plugin_hce_ppse_pause, + .resume = _nfc_plugin_hce_ppse_resume, + .deinit = _nfc_plugin_hce_ppse_deinit, + + .aid = PPSE_AID, + .listener = __nfc_addon_hce_ppse_listener, +}; diff --git a/src/manager/addons/net_nfc_addon_hce_tmoney.c b/src/manager/addons/net_nfc_addon_hce_tmoney.c new file mode 100644 index 0000000..1b39b7d --- /dev/null +++ b/src/manager/addons/net_nfc_addon_hce_tmoney.c @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_internal.h" +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_util_hce.h" +#include "net_nfc_server_route_table.h" +#include "net_nfc_addon_hce.h" + + +#define ENDIAN_16(x) ((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00)) + +#define T_MONEY_AID "D4100000030001" /* 00A4040007D410000003000100 */ +#define T_MONEY_INS_READ (uint8_t)0xCA + +static const uint8_t tmoney_aid[] = { 0xD4, 0x10, 0x00, 0x00, 0x03, 0x00, 0x01 }; +static uint8_t tmoney_response[] = { + 0x6F, 0x00, +// 0x6F, 0x31, +// 0xB0, 0x2F, +// 0x00, 0x10, 0x01, 0x08, 0x10, 0x10, 0x00, 0x09, 0x84, 0x60, 0x82, 0x99, 0x01, 0x06, 0x70, 0x79, +// 0x48, 0x20, 0x13, 0x03, 0x30, 0x20, 0x18, 0x03, 0x29, 0x01, 0x00, 0x00, 0x07, 0xA1, 0x20, 0x40, +// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +static uint8_t tmoney_uid[] = { 'T', 'i', 'z', 'e', 'n', '1', '2', '3' }; + +static bool selected; +static bool enabled; + +static void __send_response(net_nfc_target_handle_s *handle, uint16_t sw, uint8_t *resp, size_t len) +{ + size_t total_len = sizeof(sw); + size_t offset = 0; + uint8_t *buffer; + + sw = ENDIAN_16(sw); + + if (resp != NULL && len > 0) { + total_len += len; + } + + buffer = g_malloc0(total_len); + + if (resp != NULL && len > 0) { + memcpy(buffer + offset, resp, len); + offset += len; + } + + memcpy(buffer + offset, &sw, sizeof(sw)); + + /* send */ + data_s temp = { buffer, total_len }; + + net_nfc_server_hce_send_apdu_response(handle, &temp); + + g_free(buffer); +} + +static void __process_command(net_nfc_target_handle_s *handle, data_s *cmd) +{ + net_nfc_apdu_data_t *apdu; + + apdu = net_nfc_util_hce_create_apdu_data(); + + if (net_nfc_util_hce_extract_parameter(cmd, apdu) != NET_NFC_OK) { + DEBUG_ERR_MSG("wrong length"); + __send_response(handle, NET_NFC_HCE_SW_WRONG_LENGTH, NULL, 0); + goto END; + } + + if (apdu->ins == NET_NFC_HCE_INS_SELECT) { + if (apdu->lc < 2 || apdu->data == NULL) { + DEBUG_ERR_MSG("wrong parameter"); + __send_response(handle, NET_NFC_HCE_SW_LC_INCONSIST_P1_TO_P2, NULL, 0); + goto END; + } + + if (apdu->p1 != NET_NFC_HCE_P1_SELECT_BY_NAME || + apdu->p2 != 0) { + DEBUG_ERR_MSG("incorrect parameter"); + __send_response(handle, NET_NFC_HCE_SW_INCORRECT_P1_TO_P2, NULL, 0); + goto END; + } + + if (memcmp(apdu->data, tmoney_aid, MIN(sizeof(tmoney_aid), apdu->lc)) == 0) { + DEBUG_SERVER_MSG("select tmoney applet"); + + selected = true; + + __send_response(handle, NET_NFC_HCE_SW_SUCCESS, tmoney_response, sizeof(tmoney_response)); + } else { + DEBUG_ERR_MSG("application not found"); + __send_response(handle, NET_NFC_HCE_SW_FILE_NOT_FOUND, NULL, 0); + } + } else if (apdu->ins == T_MONEY_INS_READ) { + if (selected == false) { + DEBUG_ERR_MSG("need to select applet"); + __send_response(handle, NET_NFC_HCE_SW_COMMAND_NOT_ALLOWED, NULL, 0); + goto END; + } + + if (apdu->p1 != 1 || apdu->p2 != 1) { + DEBUG_ERR_MSG("incorrect parameter, p1 [%02X], p2 [%02X]", apdu->p1, apdu->p2); + __send_response(handle, NET_NFC_HCE_SW_INCORRECT_P1_TO_P2, NULL, 0); + goto END; + } + + if (apdu->le == NET_NFC_HCE_INVALID_VALUE) { + DEBUG_ERR_MSG("wrong parameter, lc [%d], data [%p], le [%d]", apdu->lc, apdu->data, apdu->le); + __send_response(handle, NET_NFC_HCE_SW_LC_INCONSIST_P1_TO_P2, NULL, 0); + goto END; + } + + DEBUG_SERVER_MSG("tmoney read"); + + __send_response(handle, NET_NFC_HCE_SW_SUCCESS, + tmoney_uid, + sizeof(tmoney_uid)); + } else { + DEBUG_ERR_MSG("not supported"); + __send_response(handle, NET_NFC_HCE_SW_INS_NOT_SUPPORTED, NULL, 0); + } + +END : + if (apdu != NULL) { + net_nfc_util_hce_free_apdu_data(apdu); + } +} + +static void __nfc_addon_hce_tmoney_listener(net_nfc_target_handle_s *handle, + int event, data_s *data, void *user_data) +{ + switch (event) { + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED"); + selected = false; + break; + + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA"); + __process_command(handle, data); + break; + + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_DEACTIVATED : + INFO_MSG("NET_NFC_MESSAGE_ROUTING_HOST_EMU_DEACTIVATED"); + selected = false; + break; + + default : + break; + } +} + +static void _plugin_hce_tmoney_enable(void) +{ + net_nfc_error_e result = NET_NFC_OK; + + if (enabled == false) { + if (net_nfc_server_route_table_find_aid("nfc-manager", + T_MONEY_AID) == NULL) { + result = net_nfc_server_route_table_add_aid(NULL, "nfc-manager", + NET_NFC_SE_TYPE_HCE, + NET_NFC_CARD_EMULATION_CATEGORY_OTHER, + T_MONEY_AID); + } + + if (result == NET_NFC_OK) { + enabled = true; + } else { + DEBUG_ERR_MSG("net_nfc_server_route_table_add_aid failed, [%d]", result); + } + } +} + +static void _plugin_hce_tmoney_disable(void) +{ + if (enabled == true) { + if (net_nfc_server_route_table_find_aid("nfc-manager", + T_MONEY_AID) != NULL) { + net_nfc_server_route_table_del_aid(NULL, "nfc-manager", + T_MONEY_AID, false); + } + + enabled = false; + } +} +static void _nfc_plugin_hce_tmoney_init(void) +{ + DEBUG_ADDON_MSG(">>>>"); + + _plugin_hce_tmoney_enable(); +} + +static void _nfc_plugin_hce_tmoney_pause(void) +{ + DEBUG_ADDON_MSG(">>>>"); +} + +static void _nfc_plugin_hce_tmoney_resume(void) +{ + DEBUG_ADDON_MSG(">>>>"); +} + +static void _nfc_plugin_hce_tmoney_deinit(void) +{ + DEBUG_ADDON_MSG(">>>>"); + + _plugin_hce_tmoney_disable(); +} + +net_nfc_addon_hce_ops_t net_nfc_addon_hce_tmoney_ops = { + .name = "HCE T-MONEY EMUL", + .init = _nfc_plugin_hce_tmoney_init, + .pause = _nfc_plugin_hce_tmoney_pause, + .resume = _nfc_plugin_hce_tmoney_resume, + .deinit = _nfc_plugin_hce_tmoney_deinit, + + .aid = T_MONEY_AID, + .listener = __nfc_addon_hce_tmoney_listener, +}; diff --git a/src/manager/addons/net_nfc_addons.c b/src/manager/addons/net_nfc_addons.c new file mode 100755 index 0000000..3e0ae24 --- /dev/null +++ b/src/manager/addons/net_nfc_addons.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_internal.h" +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_util_hce.h" +#include "net_nfc_server_addon.h" + +extern net_nfc_addon_ops_t net_nfc_addon_hce_ops; + +net_nfc_addon_ops_t *addons[] = { + &net_nfc_addon_hce_ops, +}; +size_t addons_count = sizeof(addons) / sizeof(net_nfc_addon_ops_t *); + +net_nfc_error_e net_nfc_addons_init(void) +{ + int i; + + DEBUG_ADDON_MSG(">>>"); + + for (i = 0; i < addons_count; i++) { + addons[i]->init(); + } + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_addons_pause(void) +{ + int i; + + for (i = 0; i < addons_count; i++) { + addons[i]->pause(); + } + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_addons_resume(void) +{ + int i; + + for (i = 0; i < addons_count; i++) { + addons[i]->resume(); + } + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_addons_deinit(void) +{ + int i; + + DEBUG_ADDON_MSG(">>>"); + + for (i = addons_count - 1; i >= 0; i--) { + DEBUG_ADDON_MSG("deinit, index [%d]", i); + addons[i]->deinit(); + } + + return NET_NFC_OK; +} diff --git a/src/manager/include/net_nfc_app_util_internal.h b/src/manager/include/net_nfc_app_util_internal.h new file mode 100755 index 0000000..ce2a67f --- /dev/null +++ b/src/manager/include/net_nfc_app_util_internal.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 +#include "net_nfc_typedef_internal.h" + +#ifndef MESSAGE_STORAGE +#define MESSAGE_STORAGE "/opt/share/service/nfc-manager" +#endif + +#define LANG_PACKAGE "ug-setting-nfc-efl" +#define LANG_LOCALE "/usr/ug/res/locale" + +#define IDS_SIGNAL_1 "1" +#define IDS_SIGNAL_2 "2" +#define IDS_SIGNAL_3 "3" +#define IDS_SIGNAL_4 "4" + +// signal 1 +#define IDS_TAG_TYPE_NOT_SUPPORTED \ + gettext("IDS_NFC_TPOP_TAG_TYPE_NOT_SUPPORTED") +// signal 2 +#define IDS_NO_APPLICATIONS_CAN_PERFORM_THIS_ACTION \ + gettext("IDS_COM_BODY_NO_APPLICATIONS_CAN_PERFORM_THIS_ACTION") + +#define IDS_FAILED_TO_PAIR_WITH_PS \ + gettext("IDS_NFC_TPOP_FAILED_TO_PAIR_WITH_PS") + +#define IDS_FAILED_TO_CONNECT_TO_PS \ + gettext("IDS_NFC_TPOP_FAILED_TO_CONNECT_TO_PS") + +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(net_nfc_se_type_e se_type, 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(); +pid_t net_nfc_app_util_get_focus_app_pid(); +void net_nfc_app_util_show_notification(const char *signal, const char *param); + + +#endif //__NET_NFC_APP_UTIL_INTERNAL_H__ diff --git a/src/manager/include/net_nfc_app_util_private.h b/src/manager/include/net_nfc_app_util_private.h deleted file mode 100644 index 498b455..0000000 --- a/src/manager/include/net_nfc_app_util_private.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef NET_NFC_APP_UTIL_H -#define NET_NFC_APP_UTIL_H - -#include "net_nfc_typedef.h" -#include "net_nfc_typedef_private.h" -#include - -#ifndef MESSAGE_STORAGE -#define MESSAGE_STORAGE "/opt/share/service/nfc-manager" -#endif - -net_nfc_error_e net_nfc_app_util_store_ndef_message(data_s *data); -net_nfc_error_e net_nfc_app_util_process_ndef(data_s *data); -void net_nfc_app_util_aul_launch_app(char* package_name, bundle* kb); -void net_nfc_app_util_clean_storage(char* src_path); -bool net_nfc_app_util_is_dir(const char* path_name); -int net_nfc_app_util_appsvc_launch(const char *operation, const char *uri, const char *mime, const char *data); -int net_nfc_app_util_launch_se_transaction_app(net_nfc_secure_element_type_e se_type, - 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(); -pid_t net_nfc_app_util_get_focus_app_pid(); - -#endif diff --git a/src/manager/include/net_nfc_controller_internal.h b/src/manager/include/net_nfc_controller_internal.h new file mode 100755 index 0000000..64a3a9f --- /dev/null +++ b/src/manager/include/net_nfc_controller_internal.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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, hce_apdu_listener_cb hce_apdu_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); +bool net_nfc_controller_ese_test(net_nfc_error_e *result); +bool net_nfc_controller_test_set_se_tech_type(net_nfc_error_e *result, net_nfc_se_type_e type, uint32_t tech); + +/* hce api */ +bool net_nfc_controller_hce_response_apdu(net_nfc_target_handle_s *handle, data_s *response, net_nfc_error_e *result); + +bool net_nfc_controller_secure_element_route_aid(data_s *aid, net_nfc_se_type_e se_type, int power, net_nfc_error_e *result); +bool net_nfc_controller_secure_element_unroute_aid(data_s *aid, net_nfc_error_e *result); +bool net_nfc_controller_secure_element_commit_routing(net_nfc_error_e *result); +bool net_nfc_controller_secure_element_set_default_route( + net_nfc_se_type_e switch_on, + net_nfc_se_type_e switch_off, + net_nfc_se_type_e battery_off, net_nfc_error_e *result); +bool net_nfc_controller_secure_element_clear_aid_table(net_nfc_error_e *result); +bool net_nfc_controller_secure_element_get_aid_table_size(int *AIDTableSize, net_nfc_error_e *result); + +bool net_nfc_controller_secure_element_set_route_entry + (net_nfc_se_entry_type_e type, net_nfc_se_tech_protocol_type_e value, net_nfc_se_type_e route, int power, net_nfc_error_e *result); + +bool net_nfc_controller_secure_element_set_clear_routing_entry + (net_nfc_se_entry_type_e type, net_nfc_error_e *result); + +bool net_nfc_controller_set_screen_state + (net_nfc_screen_state_type_e screen_state, net_nfc_error_e *result); + + +#endif //__NET_NFC_CONTROLLER_INTERNAL_H__ diff --git a/src/manager/include/net_nfc_manager.h b/src/manager/include/net_nfc_manager.h new file mode 100755 index 0000000..f57cb71 --- /dev/null +++ b/src/manager/include/net_nfc_manager.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ diff --git a/src/manager/include/net_nfc_manager_util_internal.h b/src/manager/include/net_nfc_manager_util_internal.h new file mode 100755 index 0000000..c2f9f90 --- /dev/null +++ b/src/manager/include/net_nfc_manager_util_internal.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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/usr/share/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__ diff --git a/src/manager/include/net_nfc_server.h b/src/manager/include/net_nfc_server.h new file mode 100755 index 0000000..7f00ea8 --- /dev/null +++ b/src/manager/include/net_nfc_server.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ + +#include + +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__ diff --git a/src/manager/include/net_nfc_server_addon.h b/src/manager/include/net_nfc_server_addon.h new file mode 100755 index 0000000..c0497ef --- /dev/null +++ b/src/manager/include/net_nfc_server_addon.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_ADDON_H__ +#define __NET_NFC_SERVER_ADDON_H__ + +#include "net_nfc_typedef_internal.h" + +typedef void (*net_nfc_addon_init)(void); +typedef void (*net_nfc_addon_pause)(void); +typedef void (*net_nfc_addon_resume)(void); +typedef void (*net_nfc_addon_deinit)(void); + +typedef struct _net_nfc_addon_ops_t +{ + const char *name; + + net_nfc_addon_init init; + net_nfc_addon_pause pause; + net_nfc_addon_resume resume; + net_nfc_addon_deinit deinit; +} +net_nfc_addon_ops_t; + +#endif //__NET_NFC_SERVER_ADDON_H__ diff --git a/src/manager/include/net_nfc_server_common.h b/src/manager/include/net_nfc_server_common.h new file mode 100755 index 0000000..a2183fd --- /dev/null +++ b/src/manager/include/net_nfc_server_common.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#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_is_blocked(); + +gboolean net_nfc_server_controller_async_queue_push_force( + net_nfc_server_controller_func func, gpointer user_data); + +gboolean net_nfc_server_controller_async_queue_push( + net_nfc_server_controller_func func, gpointer user_data); + +gboolean net_nfc_server_controller_async_queue_push_and_block( + net_nfc_server_controller_func func, gpointer user_data); + +gboolean net_nfc_server_controller_async_queue_delayed_push_force( + guint msec, net_nfc_server_controller_func func, gpointer user_data); + +void net_nfc_server_restart_polling_loop(void); + +void net_nfc_server_force_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); + +void net_nfc_server_controller_run_dispatch_loop(); +void net_nfc_server_controller_quit_dispatch_loop(); + +#endif //__NET_NFC_SERVER_COMMON_H__ diff --git a/src/manager/include/net_nfc_server_context_internal.h b/src/manager/include/net_nfc_server_context_internal.h new file mode 100755 index 0000000..38966f8 --- /dev/null +++ b/src/manager/include/net_nfc_server_context_internal.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 +#include +#include + +#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; + bool isTransactionFgDispatch; +} net_nfc_client_context_info_t; + +typedef void (*net_nfc_server_gdbus_on_client_detached_cb)( + net_nfc_client_context_info_t *client); + +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(); + +void net_nfc_server_gdbus_register_on_client_detached_cb( + net_nfc_server_gdbus_on_client_detached_cb cb); + +void net_nfc_server_gdbus_unregister_on_client_detached_cb( + net_nfc_server_gdbus_on_client_detached_cb cb); + +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); +bool net_nfc_server_gdbus_get_client_transaction_fg_dispatch_state(pid_t pid); +bool net_nfc_app_util_check_transaction_fg_dispatch(); + +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(); + +net_nfc_error_e net_nfc_server_gdbus_set_transaction_fg_dispatch( + const char *id, + int fgDispatch); + +#endif //__NET_NFC_SERVER_CONTEXT_INTERNAL_H__ diff --git a/src/manager/include/net_nfc_server_handover.h b/src/manager/include/net_nfc_server_handover.h new file mode 100755 index 0000000..2966ce2 --- /dev/null +++ b/src/manager/include/net_nfc_server_handover.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 +#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; +}; + +net_nfc_error_e net_nfc_server_handover_emit_started_signal(); + +net_nfc_error_e net_nfc_server_handover_emit_finished_signal(); + +gboolean net_nfc_server_handover_init(GDBusConnection *connection); + +void net_nfc_server_handover_deinit(void); + + +#endif //__NET_NFC_SERVER_HANDOVER_H__ diff --git a/src/manager/include/net_nfc_server_handover_internal.h b/src/manager/include/net_nfc_server_handover_internal.h new file mode 100755 index 0000000..26aa244 --- /dev/null +++ b/src/manager/include/net_nfc_server_handover_internal.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_cb)( + net_nfc_error_e result, + net_nfc_ch_carrier_s *carrier, + void *user_param); + +typedef void (*net_nfc_server_handover_process_carrier_cb)( + net_nfc_error_e result, + net_nfc_conn_handover_carrier_type_e type, + data_s *data, + void *user_param); + +typedef struct _ch_hc_record_t +{ + uint8_t rfu : 5; + uint8_t ctf : 3; + uint8_t type_len; + uint8_t type[0]; +} +__attribute__((packed)) ch_hc_record_t; + + +/* alternative carrier functions */ +/* bluetooth */ +net_nfc_error_e net_nfc_server_handover_bt_get_carrier( + net_nfc_server_handover_get_carrier_cb cb, void *user_param); + +net_nfc_error_e net_nfc_server_handover_bt_prepare_pairing( + net_nfc_ch_carrier_s *carrier, + net_nfc_server_handover_process_carrier_cb cb, + void *user_param); + +net_nfc_error_e net_nfc_server_handover_bt_do_pairing( + net_nfc_ch_carrier_s *carrier, + net_nfc_server_handover_process_carrier_cb cb, + void *user_param); + +/* Wifi protected setup */ +net_nfc_error_e net_nfc_server_handover_wps_get_selector_carrier( + net_nfc_server_handover_get_carrier_cb cb, + void *user_param); + +net_nfc_error_e net_nfc_server_handover_wps_get_requester_carrier( + net_nfc_server_handover_get_carrier_cb cb, + void *user_param); + +net_nfc_error_e net_nfc_server_handover_wps_do_connect( + net_nfc_ch_carrier_s *carrier, + net_nfc_server_handover_process_carrier_cb cb, + void *user_param); + +#endif //__NET_NFC_SERVER_HANDOVER_INTERNAL_H__ diff --git a/src/manager/include/net_nfc_server_hce.h b/src/manager/include/net_nfc_server_hce.h new file mode 100755 index 0000000..80bccd1 --- /dev/null +++ b/src/manager/include/net_nfc_server_hce.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_HCE_H__ +#define __NET_NFC_SERVER_HCE_H__ + +#include + +#include "net_nfc_typedef_internal.h" + + +/******************************************************************************/ +typedef void (*net_nfc_server_hce_listener_cb)(net_nfc_target_handle_s *handle, + int event, data_s *data, void *user_data); + +typedef void (*net_nfc_server_hce_user_data_destroy_cb)(void *user_data); + + +/******************************************************************************/ +net_nfc_error_e net_nfc_server_hce_start_hce_handler(const char *package, + const char *id, net_nfc_server_hce_listener_cb listener, + net_nfc_server_hce_user_data_destroy_cb destroy_cb, void *user_data); + +net_nfc_error_e net_nfc_server_hce_stop_hce_handler(const char *package); + +net_nfc_error_e net_nfc_server_hce_send_apdu_response( + net_nfc_target_handle_s *handle, data_s *response); + +/******************************************************************************/ +/* internal */ +gboolean net_nfc_server_hce_init(GDBusConnection *connection); +void net_nfc_server_hce_deinit(void); + +void net_nfc_server_hce_apdu_received(void *info); + +#endif //__NET_NFC_SERVER_SE_H__ diff --git a/src/manager/include/net_nfc_server_llcp.h b/src/manager/include/net_nfc_server_llcp.h new file mode 100644 index 0000000..7a40434 --- /dev/null +++ b/src/manager/include/net_nfc_server_llcp.h @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#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(gpointer user_data); + +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); + +bool 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__ diff --git a/src/manager/include/net_nfc_server_manager.h b/src/manager/include/net_nfc_server_manager.h new file mode 100755 index 0000000..1f6fa22 --- /dev/null +++ b/src/manager/include/net_nfc_server_manager.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 +#include "net_nfc_server_vconf.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__ diff --git a/src/manager/include/net_nfc_server_ndef.h b/src/manager/include/net_nfc_server_ndef.h new file mode 100644 index 0000000..7b241b1 --- /dev/null +++ b/src/manager/include/net_nfc_server_ndef.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +gboolean net_nfc_server_ndef_init(GDBusConnection *connection); + +void net_nfc_server_ndef_deinit(void); + +#endif //__NET_NFC_SERVER_NDEF_H__ diff --git a/src/manager/include/net_nfc_server_p2p.h b/src/manager/include/net_nfc_server_p2p.h new file mode 100644 index 0000000..bed96f6 --- /dev/null +++ b/src/manager/include/net_nfc_server_p2p.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#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(gpointer user_data); + +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__ diff --git a/src/manager/include/net_nfc_server_process_handover.h b/src/manager/include/net_nfc_server_process_handover.h new file mode 100755 index 0000000..2d83605 --- /dev/null +++ b/src/manager/include/net_nfc_server_process_handover.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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(); + +#endif //__NET_NFC_SERVER_PROCESS_HANDOVER_H__ diff --git a/src/manager/include/net_nfc_server_process_npp.h b/src/manager/include/net_nfc_server_process_npp.h new file mode 100644 index 0000000..f68b53a --- /dev/null +++ b/src/manager/include/net_nfc_server_process_npp.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#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__ diff --git a/src/manager/include/net_nfc_server_process_snep.h b/src/manager/include/net_nfc_server_process_snep.h new file mode 100755 index 0000000..d9bd52c --- /dev/null +++ b/src/manager/include/net_nfc_server_process_snep.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 diff --git a/src/manager/include/net_nfc_server_route_table.h b/src/manager/include/net_nfc_server_route_table.h new file mode 100755 index 0000000..56ca3f3 --- /dev/null +++ b/src/manager/include/net_nfc_server_route_table.h @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_ROUTE_TABLE_H__ +#define __NET_NFC_SERVER_ROUTE_TABLE_H__ + +#include + +#include "net_nfc_typedef_internal.h" + +#define VCONFKEY_NFC_PAYMENT_HANDLERS "db/nfc/payment_handlers" +#define VCONFKEY_NFC_OTHER_HANDLERS "db/nfc/other_handlers" + +typedef struct _aid_info_t +{ + net_nfc_se_type_e se_type; + net_nfc_card_emulation_category_t category; + bool is_routed; + char *aid; + bool unlock; + int power; + bool manifest; +} +aid_info_t; + +typedef struct _route_table_handler_t +{ + char *package; + char *id; + bool activated[NET_NFC_CARD_EMULATION_CATEGORY_MAX]; + GPtrArray *aids[NET_NFC_CARD_EMULATION_CATEGORY_MAX]; +} +route_table_handler_t; + +typedef bool (*net_nfc_server_route_table_handler_iter_cb)( + const char *package, route_table_handler_t *handler, void *user_data); + +typedef bool (*net_nfc_server_route_table_aid_iter_cb)( + const char *package, route_table_handler_t *handler, + aid_info_t *aid, void *user_data); + +void net_nfc_server_route_table_init(); +void net_nfc_server_route_table_load_db(); +void net_nfc_server_route_table_deinit(); + +void net_nfc_server_route_table_iterate_handler( + net_nfc_server_route_table_handler_iter_cb cb, void *user_data); + +route_table_handler_t *net_nfc_server_route_table_find_handler( + const char *package); + +net_nfc_error_e net_nfc_server_route_table_add_handler(const char *id, + const char *package); + +net_nfc_error_e net_nfc_server_route_table_del_handler(const char *id, + const char *package, bool force); + +net_nfc_error_e net_nfc_server_route_table_set_handler_activation( + const char *package, net_nfc_card_emulation_category_t category); + + +route_table_handler_t *net_nfc_server_route_table_find_handler_by_id( + const char *id); + +net_nfc_error_e net_nfc_server_route_table_add_handler_by_id(const char *id); + +net_nfc_error_e net_nfc_server_route_table_del_handler_by_id(const char *id); + +net_nfc_error_e net_nfc_server_route_table_set_handler_by_id(const char *id); + +net_nfc_error_e net_nfc_server_route_table_set_handler_activation_by_id( + const char *id, net_nfc_card_emulation_category_t category); + + + +route_table_handler_t *net_nfc_server_route_table_find_handler_by_aid( + const char *aid); + +aid_info_t *net_nfc_server_route_table_find_aid(const char *package, + const char *aid); + +net_nfc_error_e net_nfc_server_route_table_add_aid(const char *id, + const char *package, net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + const char *aid); + +net_nfc_error_e net_nfc_server_route_table_del_aid(const char *id, const char *package, + const char *aid, bool force); + +net_nfc_error_e net_nfc_server_route_table_del_aids(const char *id, const char *package, + bool force); + +void net_nfc_server_route_table_iterate_aid(const char *package, + net_nfc_server_route_table_aid_iter_cb cb, void *user_data); + +aid_info_t *net_nfc_server_route_table_find_aid_by_id(const char *package, + const char *aid); + +net_nfc_error_e net_nfc_server_route_table_add_aid_by_id(const char *id, + net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + const char *aid); + +net_nfc_error_e net_nfc_server_route_table_del_aid_by_id(const char *id, + const char *aid, bool force); + +void net_nfc_server_route_table_iterate_aid_by_id(const char *id, + net_nfc_server_route_table_aid_iter_cb cb, void *user_data); + + +net_nfc_error_e net_nfc_server_route_table_insert_aid_into_db( + const char *package, net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + const char *aid, bool unlock, int power); + +net_nfc_error_e net_nfc_server_route_table_delete_aid_from_db( + const char *package, const char *aid); + +net_nfc_error_e net_nfc_server_route_table_delete_aids_from_db( + const char *package); + +void net_nfc_server_route_table_update_category_handler(const char *package, + net_nfc_card_emulation_category_t category); + +net_nfc_error_e net_nfc_server_route_table_do_update(void); + +#endif //__NET_NFC_SERVER_ROUTE_TABLE_H__ diff --git a/src/manager/include/net_nfc_server_se.h b/src/manager/include/net_nfc_server_se.h new file mode 100644 index 0000000..febe8a6 --- /dev/null +++ b/src/manager/include/net_nfc_server_se.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#include "net_nfc_typedef_internal.h" + + +/***************************************************************/ +void net_nfc_server_se_policy_apply(); + +net_nfc_se_type_e net_nfc_server_se_get_se_type(); + +net_nfc_error_e net_nfc_server_se_set_se_type(net_nfc_se_type_e type); + +net_nfc_card_emulation_mode_t net_nfc_server_se_get_se_state(); + +net_nfc_error_e net_nfc_server_se_set_se_state( + net_nfc_card_emulation_mode_t state); +#if 0 +net_nfc_error_e net_nfc_server_se_set_se_policy( + net_nfc_secure_element_policy_e policy); +#endif +net_nfc_error_e net_nfc_server_se_apply_se_current_policy(); + +net_nfc_error_e net_nfc_server_se_apply_se_policy( + net_nfc_secure_element_policy_e policy); + +net_nfc_error_e net_nfc_server_se_change_wallet_mode( + net_nfc_wallet_mode_e wallet_mode); + + + + +/***************************************************************/ + +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); + +void net_nfc_server_se_rf_field_on(void *info); + + +#endif //__NET_NFC_SERVER_SE_H__ diff --git a/src/manager/include/net_nfc_server_snep.h b/src/manager/include/net_nfc_server_snep.h new file mode 100644 index 0000000..c868fb7 --- /dev/null +++ b/src/manager/include/net_nfc_server_snep.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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__ diff --git a/src/manager/include/net_nfc_server_system_handler.h b/src/manager/include/net_nfc_server_system_handler.h new file mode 100644 index 0000000..a0c3963 --- /dev/null +++ b/src/manager/include/net_nfc_server_system_handler.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +gboolean net_nfc_server_system_handler_init(GDBusConnection *connection); + +void net_nfc_server_system_handler_deinit(void); + +#endif //__NET_NFC_SERVER_SYSTEM_HANDLER_H__ diff --git a/src/manager/include/net_nfc_server_tag.h b/src/manager/include/net_nfc_server_tag.h new file mode 100644 index 0000000..0c37a7a --- /dev/null +++ b/src/manager/include/net_nfc_server_tag.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +#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(net_nfc_current_target_info_s *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); + +bool net_nfc_server_tag_target_detected(void *info); + +#endif //__NET_NFC_SERVER_TAG_H__ diff --git a/src/manager/include/net_nfc_server_test.h b/src/manager/include/net_nfc_server_test.h new file mode 100644 index 0000000..bbffc8d --- /dev/null +++ b/src/manager/include/net_nfc_server_test.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +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 diff --git a/src/manager/include/net_nfc_server_transceive.h b/src/manager/include/net_nfc_server_transceive.h new file mode 100644 index 0000000..0c0d6b0 --- /dev/null +++ b/src/manager/include/net_nfc_server_transceive.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 + +gboolean net_nfc_server_transceive_init(GDBusConnection *connection); + +void net_nfc_server_transceive_deinit(void); + +#endif //__NET_NFC_SERVER_TRANSCEIVE_H__ diff --git a/src/manager/include/net_nfc_server_vconf.h b/src/manager/include/net_nfc_server_vconf.h new file mode 100755 index 0000000..0962f78 --- /dev/null +++ b/src/manager/include/net_nfc_server_vconf.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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); + +bool net_nfc_check_csc_vconf(void); + +bool net_nfc_check_start_polling_vconf(void); + +#endif //__NET_NFC_SERVER_VCONF_H__ diff --git a/src/manager/include/net_nfc_service_se_private.h b/src/manager/include/net_nfc_service_se_private.h deleted file mode 100755 index a448b0b..0000000 --- a/src/manager/include/net_nfc_service_se_private.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NET_NFC_SERVICE_SE_PRIVATE_H -#define NET_NFC_SERVICE_SE_PRIVATE_H - -#include "net_nfc_typedef_private.h" - -typedef struct _se_setting_t -{ - net_nfc_target_handle_s *current_ese_handle; - void *open_request_trans_param; - uint8_t type; - uint8_t return_type; - uint8_t mode; -} -net_nfc_se_setting_t; - -net_nfc_se_setting_t *net_nfc_service_se_get_se_setting(); -net_nfc_target_handle_s *net_nfc_service_se_get_current_ese_handle(); -void net_nfc_service_se_set_current_ese_handle(net_nfc_target_handle_s *handle); -uint8_t net_nfc_service_se_get_se_type(); -void net_nfc_service_se_set_se_type(uint8_t type); -uint8_t net_nfc_service_se_get_se_mode(); -void net_nfc_service_se_set_se_mode(uint8_t mode); - -net_nfc_error_e net_nfc_service_se_change_se(uint8_t type); - -void net_nfc_service_se_detected(net_nfc_request_msg_t *req_msg); -net_nfc_error_e net_nfc_service_se_close_ese(); - -/* TAPI SIM API */ - -bool net_nfc_service_tapi_init(void); -void net_nfc_service_tapi_deinit(void); -bool net_nfc_service_transfer_apdu(int client_fd, data_s *apdu, void *trans_param); -bool net_nfc_service_request_atr(int client_fd, void *trans_param); -bool net_nfc_service_se_transaction_receive(net_nfc_request_msg_t* msg); -void net_nfc_service_se_send_apdu(net_nfc_request_msg_t *msg); -void net_nfc_service_se_get_atr(net_nfc_request_msg_t *msg); -void net_nfc_service_se_close_se(net_nfc_request_msg_t *msg); -void net_nfc_service_se_open_se(net_nfc_request_msg_t *msg); -void net_nfc_service_se_set_se(net_nfc_request_msg_t *msg); -void net_nfc_service_se_get_se(net_nfc_request_msg_t *msg); -void net_nfc_service_se_cleanup(); -void net_nfc_service_se_change_card_emulation_mode(net_nfc_request_msg_t *req_msg); - -#endif diff --git a/src/manager/net_nfc_app_util.c b/src/manager/net_nfc_app_util.c new file mode 100755 index 0000000..959c865 --- /dev/null +++ b/src/manager/net_nfc_app_util.c @@ -0,0 +1,1125 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "appsvc.h" +#include "aul.h" +#include "vconf.h" + +#include "net_nfc_typedef.h" +#include "net_nfc_typedef_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 "net_nfc_util_handover.h" +#include "net_nfc_server_handover_internal.h" +#include "net_nfc_server_handover.h" +//#include "syspopup_caller.h" + +/* nfc_not_supported_pop_up */ +#include +#include + +#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"; + +typedef net_nfc_error_e (*process_message_cb)(ndef_message_s *msg); + +/* TEMP : process handover message */ +static void _process_carrier_record_cb(net_nfc_error_e result, + net_nfc_conn_handover_carrier_type_e type, + data_s *data, void *user_param) +{ + data_s *message = (data_s *)user_param; + + if (result == NET_NFC_OK) + { + INFO_MSG("process carrier record success"); + } + else + { + DEBUG_ERR_MSG("net_nfc_service_handover_bt_process_carrier_record failed, [%d]", result); + } + + net_nfc_server_handover_emit_finished_signal(result, type, data, message); + + net_nfc_util_free_data(message); +} + +static net_nfc_error_e __process_ch_message(net_nfc_ch_message_s *message, + data_s *data) +{ + net_nfc_error_e result; + uint32_t count; + int i; + + result = net_nfc_util_get_handover_carrier_count(message, &count); + if (result == NET_NFC_OK) + { + net_nfc_ch_carrier_s *carrier = NULL; + net_nfc_conn_handover_carrier_type_e type; + + for (i = 0; i < count; i++) + { + /* TODO : apply select order */ + result = net_nfc_util_get_handover_carrier(message, i, + &carrier); + + result = net_nfc_util_get_handover_carrier_type(carrier, + &type); + if (result == NET_NFC_OK) + { + DEBUG_SERVER_MSG("selected carrier type = [%d]", type); + break; + } + else + { + carrier = NULL; + } + } + + if (carrier != NULL) + { + data_s *temp; + + if (type == NET_NFC_CONN_HANDOVER_CARRIER_BT) + { + temp = net_nfc_util_duplicate_data(data); + + net_nfc_server_handover_emit_started_signal(NULL, temp); + + net_nfc_server_handover_bt_do_pairing( + carrier, + _process_carrier_record_cb, + temp); + } + else if (type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS) + { + temp = net_nfc_util_duplicate_data(data); + + net_nfc_server_handover_emit_started_signal(NULL, temp); + + net_nfc_server_handover_wps_do_connect( + carrier, + _process_carrier_record_cb, + temp); + } + else if (type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P)/*WIFI-DIRECT*/ + { + temp = net_nfc_util_duplicate_data(data); + + net_nfc_server_handover_emit_started_signal(NULL, temp); + + } + } + } + else + { + DEBUG_ERR_MSG("net_nfc_util_get_handover_carrier_count failed [%d]", result); + } + + return result; +} + +static net_nfc_error_e __process_handover_message(ndef_message_s *message) +{ + net_nfc_ch_message_s *msg = NULL; + net_nfc_error_e result; + + result = net_nfc_util_import_handover_from_ndef_message(message, &msg); + if (result == NET_NFC_INVALID_FORMAT) { + DEBUG_SERVER_MSG("not handover message, continue"); + + goto END; + } else if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_util_import_handover_from_ndef_message failed, [%d]", result); + result = NET_NFC_INVALID_FORMAT; + + goto END; + } + + if (msg->version != CH_VERSION) { + DEBUG_ERR_MSG("connection handover version is not matched"); + result = NET_NFC_INVALID_FORMAT; + + goto END; + } + + if (msg->type != NET_NFC_CH_TYPE_SELECT) { + DEBUG_ERR_MSG("This is not connection handover select message"); + result = NET_NFC_INVALID_FORMAT; + + goto END; + } + + data_s data = { NULL, 0 }; + size_t length = net_nfc_util_get_ndef_message_length(message); + + if (net_nfc_util_init_data(&data, length) == true) { + net_nfc_util_convert_ndef_message_to_rawdata(message, &data); + } + + result = __process_ch_message(msg, &data); + + net_nfc_util_clear_data(&data); + +END : + if (msg != NULL) { + net_nfc_util_free_handover_message(msg); + } + + return result; +} + +static net_nfc_error_e __process_normal_message(ndef_message_s *msg) +{ + net_nfc_error_e result; + char operation[2048] = { 0, }; + char mime[2048] = { 0, }; + char text[2048] = { 0, }; +#ifdef USE_FULL_URI + char uri[2048] = { 0, }; +#endif + int ret; + + /* check state of launch popup */ + if (net_nfc_app_util_check_launch_state() == TRUE) + { + DEBUG_SERVER_MSG("skip launch popup!!!"); + result = NET_NFC_OK; + goto END; + } + + 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"); + result = NET_NFC_UNKNOWN_ERROR; + goto END; + } + + 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"); + result = NET_NFC_UNKNOWN_ERROR; + goto END; + } +#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"); + result = NET_NFC_UNKNOWN_ERROR; + goto END; + } +#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"); + result = NET_NFC_UNKNOWN_ERROR; + goto END; + } + + ret = net_nfc_app_util_appsvc_launch(operation, uri, mime, text); + DEBUG_SERVER_MSG("net_nfc_app_util_appsvc_launch return %d", ret); +#if 1 + if ((ret == APPSVC_RET_ENOMATCH) || (ret == APPSVC_RET_EINVAL)) + { + net_nfc_app_util_show_notification(IDS_SIGNAL_2, NULL); + } +#endif + + result = NET_NFC_OK; + +END : + return result; +} + +static process_message_cb message_handlers[] = { + __process_handover_message, + __process_normal_message, + NULL +}; + +net_nfc_error_e net_nfc_app_util_process_ndef(data_s *data) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + ndef_message_s *msg = NULL; + int i = 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 */ + result = net_nfc_app_util_store_ndef_message(data); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_app_util_store_ndef_message failed [%d]", result); + 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 */ + result = net_nfc_util_convert_rawdata_to_ndef_message(data, msg); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_convert_rawdata_to_ndef_message failed [%d]", result); + goto ERROR; + } + + result = NET_NFC_INVALID_FORMAT; + + for (i = 0; message_handlers[i] != NULL; i++) { + result = message_handlers[i](msg); + if (result != NET_NFC_INVALID_FORMAT) { + break; + } + } + +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, }; + FILE *fp = NULL; + + if (data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + /* 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 _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 "); + + /* Original string is "nfc://secure/UICC/aid/" */ + /* string pass "nfc://secure/" */ + input += 13; + + if(strncmp(input, "SIM1", 4) == 0) + input += 4; + else if(strncmp(input, "eSE", 3) == 0) + input += 3; + + input += 5; + + 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(net_nfc_se_type_e se_type, 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, }; + data_s temp = { aid, aid_len }; + + net_nfc_util_binary_to_hex_string(&temp, temp_string, sizeof(temp_string)); + + switch(se_type) + { + case NET_NFC_SE_TYPE_UICC: + snprintf(aid_string, sizeof(aid_string), "nfc://secure/SIM1/aid/%s", temp_string); + break; + + case NET_NFC_SE_TYPE_ESE: + snprintf(aid_string, sizeof(aid_string), "nfc://secure/eSE/aid/%s", temp_string); + break; + default: + snprintf(aid_string, sizeof(aid_string), "nfc://secure/aid/%s", temp_string); + break; + } + + 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, }; + data_s temp = { param, param_len }; + + net_nfc_util_binary_to_hex_string(&temp, 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()); + if(b64 == NULL) + return NET_NFC_ALLOC_FAIL; + + 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()); + if(b64 == NULL) + return NET_NFC_ALLOC_FAIL; + + 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; +} + +pid_t net_nfc_app_util_get_focus_app_pid() +{ + pid_t pid; + +/* Todo : ecore_x_window_focus_get is failed + 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; +} + +bool net_nfc_app_util_check_transaction_fg_dispatch() +{ + pid_t focus_app_pid; + bool fg_dispatch = false; + + focus_app_pid = net_nfc_app_util_get_focus_app_pid(); + + fg_dispatch = net_nfc_server_gdbus_get_client_transaction_fg_dispatch_state(focus_app_pid); + + return fg_dispatch; +} + +void net_nfc_app_util_show_notification(const char *signal, const char *param) +{ + char *lang; + + if (signal == NULL) + return; + + lang = vconf_get_str(VCONFKEY_LANGSET); + if (lang != NULL) { + setenv("LANG", lang, 1); + setenv("LC_MESSAGES", lang, 1); + free(lang); + } + + setlocale(LC_ALL, ""); + bindtextdomain(LANG_PACKAGE, LANG_LOCALE); + textdomain(LANG_PACKAGE); + + if (strncmp(signal, IDS_SIGNAL_1, strlen(IDS_SIGNAL_1)) == 0) { + notification_status_message_post(IDS_TAG_TYPE_NOT_SUPPORTED); + } else if (strncmp(signal, IDS_SIGNAL_2, strlen(IDS_SIGNAL_2)) == 0) { + notification_status_message_post(IDS_NO_APPLICATIONS_CAN_PERFORM_THIS_ACTION); + } else if (strncmp(signal, IDS_SIGNAL_3, strlen(IDS_SIGNAL_3)) == 0) { + char msg[1024]; + const char *str = param; + const char *format; + + format = IDS_FAILED_TO_PAIR_WITH_PS; + + snprintf(msg, sizeof(msg), format, str); + + notification_status_message_post(msg); + } else if (strncmp(signal, IDS_SIGNAL_4, strlen(IDS_SIGNAL_4)) == 0) { + char msg[1024]; + const char *str = param; + const char *format; + + format = IDS_FAILED_TO_CONNECT_TO_PS; + + snprintf(msg, sizeof(msg), format, str); + + notification_status_message_post(msg); + } +} diff --git a/src/manager/net_nfc_controller.c b/src/manager/net_nfc_controller.c new file mode 100755 index 0000000..d44a0dc --- /dev/null +++ b/src/manager/net_nfc_controller.c @@ -0,0 +1,1422 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include /*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, + hce_apdu_listener_cb hce_apdu_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, hce_apdu_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 = display_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0); + if (ret_val < 0) { + DEBUG_ERR_MSG("display_lock_state failed, [%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 = display_unlock_state(LCD_NORMAL, PM_RESET_TIMER); + if (ret_val < 0) { + DEBUG_ERR_MSG("display_unlock_state failed, [%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 = display_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0); + + DEBUG_SERVER_MSG("net_nfc_controller_connect display_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 = display_unlock_state(LCD_NORMAL, PM_RESET_TIMER); + + DEBUG_ERR_MSG("net_nfc_controller_disconnect display_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; +} + +static 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; +} + +static 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; + bool ret; + + ret_val = display_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0); + + DEBUG_SERVER_MSG("net_nfc_controller_llcp_connect_by_url display_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; + + ret = g_interface.connect_llcp_by_url(handle, socket, service_access_name, result, param); + 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; + } +} + +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 = display_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0); + + DEBUG_SERVER_MSG("net_nfc_controller_llcp_connect display_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 = display_unlock_state(LCD_NORMAL, PM_RESET_TIMER); + + DEBUG_SERVER_MSG("net_nfc_controller_llcp_disconnect display_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); + } + + _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) { + if (net_nfc_util_init_data(¶m->data, max_len) == false) { + DEBUG_ERR_MSG("net_nfc_util_init_data 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) { + if (net_nfc_util_init_data(¶m->data, max_len) == false) { + DEBUG_ERR_MSG("net_nfc_util_init_data 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; + } +} + +bool net_nfc_controller_ese_test(net_nfc_error_e *result) +{ + if (g_interface.ese_test != NULL) + { + return g_interface.ese_test(result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("NFC ESE TEST interface is null"); + return false; + } +} + +bool net_nfc_controller_test_set_se_tech_type(net_nfc_error_e *result, net_nfc_se_type_e type, uint32_t tech) +{ + if (g_interface.test_set_se_tech_type != NULL) + { + return g_interface.test_set_se_tech_type(result, type, tech); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_ERR_MSG("interface is null"); + + return false; + } +} +#if 0 +bool net_nfc_controller_hce_listener(hce_active_listener_cb hce_active_listener, hce_deactive_listener_cb hce_deactive_listener, hce_apdu_listener_cb hce_apdu_listener, net_nfc_error_e *result) +{ + if (g_interface.register_hce_listener != NULL) + { + return g_interface.register_hce_listener(hce_active_listener, hce_deactive_listener, hce_apdu_listener, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +#endif +bool net_nfc_controller_hce_response_apdu(net_nfc_target_handle_s *handle, data_s *response, net_nfc_error_e *result) +{ + if (g_interface.hce_response_apdu != NULL) + { + return g_interface.hce_response_apdu(handle, 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_route_aid(data_s *aid, net_nfc_se_type_e se_type, int power, net_nfc_error_e *result) +{ + if (g_interface.route_aid != NULL) + { + return g_interface.route_aid(aid, se_type, power, result); + } + else + { + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_secure_element_unroute_aid(data_s *aid, net_nfc_error_e *result) +{ + if (g_interface.unroute_aid != NULL) + { + return g_interface.unroute_aid(aid, result); + } + else + { + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_secure_element_commit_routing(net_nfc_error_e *result) +{ + if (g_interface.commit_routing != NULL) + { + return g_interface.commit_routing(result); + } + else + { + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_secure_element_set_default_route( + net_nfc_se_type_e switch_on, + net_nfc_se_type_e switch_off, + net_nfc_se_type_e battery_off, net_nfc_error_e *result) +{ + if (g_interface.set_default_route != NULL) + { + return g_interface.set_default_route(switch_on, switch_off, battery_off, result); + } + else + { + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_secure_element_clear_aid_table(net_nfc_error_e *result) +{ + if (g_interface.clear_aid_table != NULL) + { + return g_interface.clear_aid_table(result); + } + else + { + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_secure_element_get_aid_table_size(int *AIDTableSize, net_nfc_error_e *result) +{ + if (g_interface.get_aid_tablesize != NULL) + { + return g_interface.get_aid_tablesize(AIDTableSize, result); + } + else + { + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_secure_element_set_route_entry + (net_nfc_se_entry_type_e type, net_nfc_se_tech_protocol_type_e value, net_nfc_se_type_e route, int power, net_nfc_error_e *result) +{ + if (g_interface.set_routing_entry != NULL) + { + return g_interface.set_routing_entry(type, value, route, power, result); + } + else + { + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_secure_element_set_clear_routing_entry + (net_nfc_se_entry_type_e type, net_nfc_error_e *result) +{ + if (g_interface.clear_routing_entry != NULL) + { + return g_interface.clear_routing_entry(type, result); + } + else + { + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_set_screen_state(net_nfc_screen_state_type_e screen_state, net_nfc_error_e *result) +{ + if (g_interface.set_screen_state!= NULL) + { + return g_interface.set_screen_state(screen_state , result); + } + else + { + *result = NET_NFC_UNKNOWN_ERROR; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} diff --git a/src/manager/net_nfc_manager.c b/src/manager/net_nfc_manager.c new file mode 100755 index 0000000..ef07d94 --- /dev/null +++ b/src/manager/net_nfc_manager.c @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "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; + +static bool net_nfc_check_mode_conditions(); + +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); + else if (net_nfc_check_mode_conditions()) + net_nfc_server_manager_set_active(FALSE); +#ifndef ESE_ALWAYS_ON + else if (use_daemon == TRUE) + { + DEBUG_ERR_MSG("net_nfc_server_controller_deinit"); + 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; + bool check_csc = 0; + + if (getuid() == 0) + { + int ret = perm_app_set_privilege("system", NULL, NULL); + if(ret != 0) + return 0; + } + + 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); + + check_csc = net_nfc_check_csc_vconf(); + if (check_csc) + return 0; + + 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_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; +} + +static bool net_nfc_check_mode_conditions() +{ +#ifdef ENABLE_TELEPHONY + gint flight_mode = 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"); + return FALSE; + } + + if (flight_mode == TRUE) + { + DEBUG_SERVER_MSG("Flight mode!! Do Not Kill Daemon!!"); + return TRUE; + } + else + { + DEBUG_SERVER_MSG("Not any mode!!"); + return FALSE; + } +#else +return FALSE; +#endif + + +} diff --git a/src/manager/net_nfc_manager_util.c b/src/manager/net_nfc_manager_util.c new file mode 100755 index 0000000..1efed4d --- /dev/null +++ b/src/manager/net_nfc_manager_util.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "vconf.h" +#include "feedback.h" +#include "wav_player.h" +#include + +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_manager_util_internal.h" + +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) + { + DEBUG_MSG("Play Vibration"); + + if (FEEDBACK_ERROR_NONE == feedback_initialize()) + { + if (FEEDBACK_ERROR_NONE == feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_SIP)) + { + DEBUG_MSG("feedback_play_type success"); + } + + feedback_deinitialize(); + } + } + + 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) + { + sound_manager_set_session_type(SOUND_SESSION_TYPE_NOTIFICATION); + if (MM_ERROR_NONE == wav_player_start(sound_path, SOUND_TYPE_NOTIFICATION, NULL, NULL, NULL)) +// if (MM_ERROR_NONE == mm_sound_play_keysound(sound_path, VOLUME_TYPE_NOTIFICATION)) + { + DEBUG_MSG("wav_player_start success"); + } + + _net_nfc_util_free_mem(sound_path); + } + else + { + DEBUG_ERR_MSG("Invalid Sound Path"); + } + } +} diff --git a/src/manager/net_nfc_server.c b/src/manager/net_nfc_server.c new file mode 100755 index 0000000..266b071 --- /dev/null +++ b/src/manager/net_nfc_server.c @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_debug_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" +#include "net_nfc_server_hce.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)) { + /* 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_controller_thread_init() == FALSE) + { + DEBUG_ERR_MSG("Can not init controller thread"); + return; + } + + _subscribe_name_owner_changed_event(); + + 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_hce_init(connection) == FALSE) + { + DEBUG_ERR_MSG("Can not init Test"); + return; + } +} + +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_controller_thread_deinit(); + + net_nfc_server_gdbus_deinit_client_context(); + + if (connection) + { + g_object_unref(connection); + connection = NULL; + } +} diff --git a/src/manager/net_nfc_server_common.c b/src/manager/net_nfc_server_common.c new file mode 100755 index 0000000..42d4041 --- /dev/null +++ b/src/manager/net_nfc_server_common.c @@ -0,0 +1,732 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_debug_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" +#include "net_nfc_server_hce.h" + + +typedef struct _ControllerFuncData ControllerFuncData; + +struct _ControllerFuncData +{ + net_nfc_server_controller_func func; + gpointer data; + gboolean blocking; +}; + +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_hce_apdu_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 void force_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 gboolean controller_dispath_running = FALSE; + +static guint32 server_state = NET_NFC_SERVER_IDLE; + +static gint controller_block; + +static gboolean check_nfc_disable = FALSE; + + + +static void controller_async_queue_free_func(gpointer user_data) +{ + ControllerFuncData *func_data = (ControllerFuncData *)user_data; + + if (func_data != NULL) { + if (func_data->blocking == true) { + controller_block--; + } + + g_free(user_data); + } +} + +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); + + controller_async_queue_free_func(func_data); + } + + g_thread_exit(NULL); + + return NULL; +} + +static void controller_thread_deinit_thread_func(gpointer user_data) +{ + controller_is_running = FALSE; +} + +static net_nfc_current_target_info_s *_create_target_info( + net_nfc_request_target_detected_t *msg) +{ + net_nfc_current_target_info_s *info; + + info = g_malloc0(sizeof(net_nfc_current_target_info_s) + + msg->target_info_values.length); + + if(info == NULL) + return NULL; + + info->handle = msg->handle; + info->devType = msg->devType; + + if (info->devType != NET_NFC_NFCIP1_INITIATOR && + info->devType != NET_NFC_NFCIP1_TARGET) + { + info->number_of_keys = msg->number_of_keys; + info->target_info_values.length = + msg->target_info_values.length; + + memcpy(&info->target_info_values, + &msg->target_info_values, + info->target_info_values.length + sizeof(int)); + } + + return info; +} + + +/* 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); + + INFO_MSG("check devType = [%d]", req->devType ); + + if (req->request_type == NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP) + { + net_nfc_server_restart_polling_loop(); + } + else + { + bool ret = true; + net_nfc_current_target_info_s *target_info; + + /* FIXME */ + target_info = _create_target_info(req); + if (target_info != NULL) { + if (req->devType != NET_NFC_UNKNOWN_TARGET) { + if (req->devType == NET_NFC_NFCIP1_TARGET || + req->devType == NET_NFC_NFCIP1_INITIATOR) { + /* llcp target detected */ + ret = net_nfc_server_llcp_target_detected(target_info); + } else { + /* tag target detected */ + ret = net_nfc_server_tag_target_detected(target_info); + } + } + + /* If target detected, sound should be played. */ + //net_nfc_manager_util_play_sound(NET_NFC_TASK_START); + } else { + DEBUG_ERR_MSG("_create_target_info failed"); + } + + if(ret == false) + _net_nfc_util_free_mem(target_info); + } + + /* 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; + + + INFO_MSG("SE Transaction = [%d]", req->request_type ); + + 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; + + case NET_NFC_MESSAGE_SE_FIELD_ON : + net_nfc_server_se_rf_field_on(req); + break; + + default : + break; + } +} + +/* FIXME : net_nfc_dispatcher_queue_push() need to be removed */ +static void _controller_llcp_event_cb(gpointer user_data) +{ + net_nfc_request_llcp_msg_t *req_msg = + (net_nfc_request_llcp_msg_t *)user_data; + + if (req_msg == NULL) + { + DEBUG_ERR_MSG("can not get llcp_event info"); + + return; + } + + switch (req_msg->request_type) + { + case NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED : + net_nfc_server_llcp_deactivated(NULL); + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_LISTEN : + { + net_nfc_request_listen_socket_t *msg = + (net_nfc_request_listen_socket_t *)user_data; + + net_nfc_controller_llcp_incoming_cb(msg->client_socket, + msg->result, NULL, (void *)req_msg->user_param); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR : + case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR : + net_nfc_controller_llcp_socket_error_cb( + req_msg->llcp_socket, + req_msg->result, + NULL, + (void *)req_msg->user_param); + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_SEND : + case NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO : + net_nfc_controller_llcp_sent_cb( + req_msg->llcp_socket, + req_msg->result, + NULL, + (void *)req_msg->user_param); + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE : + { + net_nfc_request_receive_socket_t *msg = + (net_nfc_request_receive_socket_t *)user_data; + data_s data = { msg->data.buffer, msg->data.length }; + + net_nfc_controller_llcp_received_cb(msg->client_socket, + msg->result, + &data, + (void *)req_msg->user_param); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM : + { + net_nfc_request_receive_from_socket_t *msg = + (net_nfc_request_receive_from_socket_t *)user_data; + data_s data = { msg->data.buffer, msg->data.length }; + + /* FIXME : pass sap */ + net_nfc_controller_llcp_received_cb(msg->client_socket, + msg->result, + &data, + (void *)req_msg->user_param); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT : + case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP : + net_nfc_controller_llcp_connected_cb( + req_msg->llcp_socket, + req_msg->result, + NULL, + (void *)req_msg->user_param); + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT : + net_nfc_controller_llcp_disconnected_cb( + req_msg->llcp_socket, + req_msg->result, + NULL, + (void *)req_msg->user_param); + break; + + default: + break; + } + + /* FIXME : should be removed when plugins would be fixed*/ + _net_nfc_util_free_mem(req_msg); +} + +/* 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_msg = info; + + if(user_context != NULL) + req_msg->user_param = user_context; + + if (net_nfc_server_controller_async_queue_push_force( + _controller_llcp_event_cb, req_msg) == FALSE) + { + DEBUG_ERR_MSG("Failed to push onto the queue"); + } +} + + +static void controller_hce_apdu_cb(void *info, + void *user_context) +{ + net_nfc_request_hce_apdu_t *req = (net_nfc_request_hce_apdu_t *)info; + + g_assert(info != NULL); + + net_nfc_server_hce_apdu_received(req); +} + + +static void controller_init_thread_func(gpointer user_data) +{ + net_nfc_error_e result; + + if (net_nfc_controller_init(&result) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_init failed, [%d]", result); + + /* ADD TEMPORARY ABORT FOR DEBUG */ + abort(); +// net_nfc_manager_quit(); + return; + } + + INFO_MSG("net_nfc_controller_init success, [%d]", result); + + if (net_nfc_controller_register_listener(controller_target_detected_cb, + controller_se_transaction_cb, + controller_llcp_event_cb, + controller_hce_apdu_cb, + &result) == false) + { + DEBUG_ERR_MSG("net_nfc_contorller_register_listener failed [%d]", + result); + + /* ADD TEMPORARY ABORT FOR DEBUG */ + abort(); + } + + INFO_MSG("net_nfc_contorller_register_listener success"); + + result = net_nfc_server_llcp_set_config(NULL); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_server_llcp_set config failed, [%d]", + result); + + /* ADD TEMPORARY ABORT FOR DEBUG */ + abort(); + } + + INFO_MSG("net_nfc_server_llcp_set_config success"); +} + +#ifndef ESE_ALWAYS_ON +static void controller_deinit_thread_func(gpointer user_data) +{ + net_nfc_server_free_target_info(); + + if (net_nfc_controller_deinit() == false) + { + DEBUG_ERR_MSG("net_nfc_controller_deinit failed"); + + /* ADD TEMPORARY ABORT FOR DEBUG */ + abort(); + return; + } + + INFO_MSG("net_nfc_controller_deinit success"); + + net_nfc_manager_quit(); +} +#endif + +static void restart_polling_loop_thread_func(gpointer user_data) +{ + gint state = 0; + gint lock_state = 0; + gint lock_screen_set = 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_IDLE_LOCK_STATE, &lock_state) != 0) + DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_IDLE_LOCK_STATE"); + + if (vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &lock_screen_set) != 0) + DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT"); + + if (vconf_get_int(VCONFKEY_PM_STATE, &pm_state) != 0) + DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_PM_STATE"); + + DEBUG_SERVER_MSG("lock_screen_set:%d ,pm_state:%d,lock_state:%d", + lock_screen_set , pm_state , lock_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) + { + check_nfc_disable = FALSE; + DEBUG_SERVER_MSG("polling enable"); + } + + return; + } + + if (pm_state == VCONFKEY_PM_STATE_LCDOFF) + { + if (check_nfc_disable == FALSE) + { + if (net_nfc_controller_configure_discovery( + NET_NFC_DISCOVERY_MODE_CONFIG, + NET_NFC_ALL_DISABLE, + &result) == true) + { + check_nfc_disable = TRUE; + DEBUG_SERVER_MSG("polling disabled"); + } + } + return; + } +} + +static void force_polling_loop_thread_func(gpointer user_data) +{ + net_nfc_error_e result; + + /* keep_SE_select_value */ + result = net_nfc_server_se_apply_se_current_policy(); + + if (net_nfc_controller_configure_discovery( + NET_NFC_DISCOVERY_MODE_START, + NET_NFC_ALL_ENABLE, + &result) == true) + { + /* vconf on */ + if (vconf_set_bool(VCONFKEY_NFC_STATE, TRUE) != 0) + { + DEBUG_ERR_MSG("vconf_set_bool is failed"); + + result = NET_NFC_OPERATION_FAIL; + } + check_nfc_disable = FALSE; + DEBUG_SERVER_MSG("force polling is success & set nfc state true"); + } + 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_force( + 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_force( + controller_init_thread_func, NULL) == FALSE) + { + DEBUG_ERR_MSG("Failed to push onto the queue"); + } +} + +inline static gboolean _timeout_cb(gpointer data) +{ + g_assert(data != NULL); + + g_async_queue_push(controller_async_queue, data); + + return false; +} + +inline static void _push_to_queue(guint msec, bool blocking, + net_nfc_server_controller_func func, + gpointer user_data) +{ + ControllerFuncData *func_data; + + func_data = g_new0(ControllerFuncData, 1); + func_data->func = func; + func_data->data = user_data; + func_data->blocking = blocking; + + if (__builtin_expect(msec == 0, true)) { + g_async_queue_push(controller_async_queue, func_data); + } else { + g_timeout_add(msec, _timeout_cb, func_data); + } +} + +#ifndef ESE_ALWAYS_ON +void net_nfc_server_controller_deinit(void) +{ + if (controller_async_queue == NULL) + { + DEBUG_ERR_MSG("controller_async_queue is not initialized"); + + return; + } + + /* block all other message because daemon will be shutting down */ + controller_block = 9999; + + _push_to_queue(0, false, controller_deinit_thread_func, NULL); +} +#endif + +gboolean net_nfc_server_controller_is_blocked() +{ + return (controller_block > 0); +} + +gboolean net_nfc_server_controller_async_queue_delayed_push_force( + guint msec, net_nfc_server_controller_func func, gpointer user_data) +{ + if (controller_async_queue == NULL) + { + DEBUG_ERR_MSG("controller_async_queue is not initialized"); + + return FALSE; + } + + _push_to_queue(msec, false, func, user_data); + + return TRUE; +} + +gboolean net_nfc_server_controller_async_queue_push_force( + net_nfc_server_controller_func func, gpointer user_data) +{ + return net_nfc_server_controller_async_queue_delayed_push_force(0, + func, user_data); +} + +gboolean net_nfc_server_controller_async_queue_push( + net_nfc_server_controller_func func, + gpointer user_data) +{ + if (net_nfc_server_controller_is_blocked() == true) { + return FALSE; + } + + return net_nfc_server_controller_async_queue_push_force(func, + user_data); +} + +gboolean net_nfc_server_controller_async_queue_push_and_block( + net_nfc_server_controller_func func, gpointer user_data) +{ + if (controller_async_queue == NULL) + { + DEBUG_ERR_MSG("controller_async_queue is not initialized"); + + return FALSE; + } + + if (net_nfc_server_controller_is_blocked() == true) { + return FALSE; + } + + /* block pushing message until complete previous blocking message */ + controller_block++; + + _push_to_queue(0, true, func, user_data); + + return TRUE; +} + +void net_nfc_server_controller_run_dispatch_loop() +{ + if (controller_async_queue == NULL) + { + return; + } + + WARN_MSG("START DISPATCH LOOP"); + + controller_dispath_running = TRUE; + while (controller_is_running && controller_dispath_running) + { + ControllerFuncData *func_data; + + func_data = g_async_queue_try_pop(controller_async_queue); + if (func_data != NULL) { + WARN_MSG("DISPATCHED!!!"); + if (func_data->func) + func_data->func(func_data->data); + + controller_async_queue_free_func(func_data); + } else { + g_usleep(10); + } + } + + WARN_MSG("STOP DISPATCH LOOP"); +} + +void net_nfc_server_controller_quit_dispatch_loop() +{ + controller_dispath_running = FALSE; +} + +void net_nfc_server_restart_polling_loop(void) +{ + if (net_nfc_server_controller_async_queue_push_force( + restart_polling_loop_thread_func, + NULL) == FALSE) + { + DEBUG_ERR_MSG("Failed to push onto the queue"); + } +} + +void net_nfc_server_force_polling_loop(void) +{ + if (net_nfc_server_controller_async_queue_push_force( + force_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; +} diff --git a/src/manager/net_nfc_server_context.c b/src/manager/net_nfc_server_context.c old mode 100644 new mode 100755 index 03be916..04d6679 --- a/src/manager/net_nfc_server_context.c +++ b/src/manager/net_nfc_server_context.c @@ -19,301 +19,475 @@ #include "vconf.h" -#include "net_nfc_debug_private.h" -#include "net_nfc_util_private.h" +#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_server_context_private.h" +#include "net_nfc_app_util_internal.h" +#include "net_nfc_util_gdbus_internal.h" +#include "net_nfc_server.h" +#include "net_nfc_server_context_internal.h" -static GList *g_client_contexts = NULL; -static pthread_mutex_t g_client_context_lock = PTHREAD_MUTEX_INITIALIZER; -static gint _client_context_compare_by_socket(gconstpointer a, gconstpointer b) -{ - gint result = -1; - net_nfc_client_info_t *info = (net_nfc_client_info_t *)a; +static GList *client_detached_cbs; - if (info->socket == (int)b) - result = 0; - else - result = 1; +static GHashTable *client_contexts; +static pthread_mutex_t context_lock = PTHREAD_MUTEX_INITIALIZER; - return result; +static void _cleanup_client_key(gpointer data) +{ + if (data != NULL) + { + g_free(data); + } } -static gint _client_context_compare_by_pgid(gconstpointer a, gconstpointer b) +static void _on_client_detached(gpointer data, gpointer user_data) { - gint result = -1; - net_nfc_client_info_t *info = (net_nfc_client_info_t *)a; + net_nfc_server_gdbus_on_client_detached_cb cb = data; - if (info->pgid == (pid_t)b) - result = 0; - else - result = 1; + DEBUG_MSG("invoke releasing callbacks"); - return result; + if (cb != NULL) { + cb((net_nfc_client_context_info_t *)user_data); + } } static void _cleanup_client_context(gpointer data) { - net_nfc_client_info_t *info = data; + net_nfc_client_context_info_t *info = data; - if (info != NULL) - { - if (info->channel != NULL) - { - g_io_channel_unref(info->channel); - } + if (info != NULL) { + g_list_foreach(client_detached_cbs, _on_client_detached, info); - /* need to check . is it necessary to remove g_source_id */ - if (info->src_id > 0) - { - g_source_remove(info->src_id); - } + g_free(info->id); + g_free(info); + } +} - if (info->socket > 0) - { - shutdown(info->socket, SHUT_RDWR); - close(info->socket); - } +void net_nfc_server_gdbus_init_client_context() +{ + pthread_mutex_lock(&context_lock); + + if (client_contexts == NULL) { + client_contexts = g_hash_table_new_full(g_str_hash, g_str_equal, + _cleanup_client_key, _cleanup_client_context); + } + + pthread_mutex_unlock(&context_lock); +} - DEBUG_SERVER_MSG("cleanup success : client [%d]", info->socket); +void net_nfc_server_gdbus_deinit_client_context() +{ + pthread_mutex_lock(&context_lock); - _net_nfc_util_free_mem(info); + if (client_contexts != NULL) { + g_hash_table_destroy(client_contexts); + client_contexts = NULL; } + + pthread_mutex_unlock(&context_lock); +} + +void net_nfc_server_gdbus_register_on_client_detached_cb( + net_nfc_server_gdbus_on_client_detached_cb cb) +{ + client_detached_cbs = g_list_append(client_detached_cbs, cb); } -void net_nfc_server_deinit_client_context() +void net_nfc_server_gdbus_unregister_on_client_detached_cb( + net_nfc_server_gdbus_on_client_detached_cb cb) { - pthread_mutex_lock(&g_client_context_lock); + client_detached_cbs = g_list_remove(client_detached_cbs, cb); +} + +/* TODO */ +bool net_nfc_server_gdbus_check_privilege(GDBusMethodInvocation *invocation, + GVariant *privilege, + const char *object, + const char *right) +{ + const char *id = g_dbus_method_invocation_get_sender(invocation); + + INFO_MSG("check the id of the gdbus sender = [%s]",id); - g_list_free_full(g_client_contexts, _cleanup_client_context); + net_nfc_server_gdbus_add_client_context(id, + NET_NFC_CLIENT_ACTIVE_STATE); - pthread_mutex_unlock(&g_client_context_lock); + return true; } -int net_nfc_server_get_client_count() +size_t net_nfc_server_gdbus_get_client_count_no_lock() { - int result = 0; + return g_hash_table_size(client_contexts); +} - pthread_mutex_lock(&g_client_context_lock); +size_t net_nfc_server_gdbus_get_client_count() +{ + size_t result; - result = g_list_length(g_client_contexts); + pthread_mutex_lock(&context_lock); - pthread_mutex_unlock(&g_client_context_lock); + result = net_nfc_server_gdbus_get_client_count_no_lock(); + + pthread_mutex_unlock(&context_lock); return result; } -net_nfc_client_info_t *net_nfc_server_get_client_context(int socket) +net_nfc_client_context_info_t *net_nfc_server_gdbus_get_client_context_no_lock( + const char *id) { - net_nfc_client_info_t *result = NULL; - GList *item = NULL; + net_nfc_client_context_info_t *result; - pthread_mutex_lock(&g_client_context_lock); + result = g_hash_table_lookup(client_contexts, id); - item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_by_socket); - if (item != NULL) - { - result = item->data; - } + return result; +} - pthread_mutex_unlock(&g_client_context_lock); +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_add_client_context(pid_t pid, int socket, GIOChannel *channel, uint32_t src_id, client_state_e state) +void net_nfc_server_gdbus_add_client_context(const char *id, + client_state_e state) { - DEBUG_SERVER_MSG("add client context"); + pthread_mutex_lock(&context_lock); - if (net_nfc_server_get_client_context(socket) == NULL) + if (net_nfc_server_gdbus_get_client_context_no_lock(id) == NULL) { - net_nfc_client_info_t *info = NULL; - - pthread_mutex_lock(&g_client_context_lock); + net_nfc_client_context_info_t *info = NULL; - _net_nfc_util_alloc_mem(info, sizeof(net_nfc_client_info_t)); + 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->socket = socket; - info->channel = channel; - info->src_id = src_id; info->state = state; info->launch_popup_state = NET_NFC_LAUNCH_APP_SELECT; + info->launch_popup_state_no_check = NET_NFC_LAUNCH_APP_SELECT; + info->isTransactionFgDispatch = false; - g_client_contexts = g_list_append(g_client_contexts, info); + g_hash_table_insert(client_contexts, + (gpointer)g_strdup(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(&g_client_context_lock); } else { - DEBUG_ERR_MSG("client exists already [%d]", socket); + INFO_MSG("we already have this client in our context!!"); } - DEBUG_SERVER_MSG("current client count = [%d]", g_list_length(g_client_contexts)); + pthread_mutex_unlock(&context_lock); } -void net_nfc_server_cleanup_client_context(int socket) +void net_nfc_server_gdbus_cleanup_client_context(const char *id) { - GList *item = NULL; + net_nfc_client_context_info_t *info; - DEBUG_SERVER_MSG("clean up client context"); + pthread_mutex_lock(&context_lock); - pthread_mutex_lock(&g_client_context_lock); - - item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_by_socket); - if (item != NULL) + info = net_nfc_server_gdbus_get_client_context_no_lock(id); + if (info != NULL) { - _cleanup_client_context(item->data); + DEBUG_SERVER_MSG("clean up client context, [%s, %d]", id, + info->pid); + + g_hash_table_remove(client_contexts, id); + + DEBUG_SERVER_MSG("current client count = [%d]", + net_nfc_server_gdbus_get_client_count_no_lock()); - g_client_contexts = g_list_delete_link(g_client_contexts, item); +// /* 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(&g_client_context_lock); + 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; - DEBUG_SERVER_MSG("current client count = [%d]", g_list_length(g_client_contexts)); + 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); } -void net_nfc_server_for_each_client_context(net_nfc_server_for_each_client_cb cb, void *user_param) +bool net_nfc_server_gdbus_check_client_is_running(const char *id) { - GList *item = NULL; + return (net_nfc_server_gdbus_get_client_context(id) != NULL); +} - pthread_mutex_lock(&g_client_context_lock); - item = g_list_first(g_client_contexts); - while (item != NULL) - { - if (cb != NULL) - { - cb(item->data, user_param); - } - item = g_list_next(item); +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(&g_client_context_lock); + + pthread_mutex_unlock(&context_lock); + + return state; } -#ifndef BROADCAST_MESSAGE -net_nfc_target_handle_s* net_nfc_server_get_current_client_target_handle(int socket_fd) +void net_nfc_server_gdbus_set_client_state(const char *id, client_state_e state) { - int i = 0; + net_nfc_client_context_info_t *info; - pthread_mutex_lock(&g_server_socket_lock); + pthread_mutex_lock(&context_lock); - net_nfc_target_handle_s* handle = NULL; + info = net_nfc_server_gdbus_get_client_context_no_lock(id); + if (info != NULL) { + info->state = state; + } - for(; i < NET_NFC_CLIENT_MAX; i++) - { - if(g_client_info[i].socket == socket_fd) - { - handle = g_client_info[i].target_handle; - break; + pthread_mutex_unlock(&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(&g_server_socket_lock); + pthread_mutex_unlock(&context_lock); +} - return handle; +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; } -bool net_nfc_server_set_current_client_target_handle(int socket_fd, net_nfc_target_handle_s* handle) +net_nfc_error_e net_nfc_server_gdbus_set_transaction_fg_dispatch( + const char *id, + int fgDispatch) { - int i = 0; + net_nfc_client_context_info_t *info; + pid_t focus_app_pid; + net_nfc_error_e result = NET_NFC_OK; + + focus_app_pid = net_nfc_app_util_get_focus_app_pid(); - pthread_mutex_lock(&g_server_socket_lock); + pthread_mutex_lock(&context_lock); - for(; i < NET_NFC_CLIENT_MAX; i++) + info = net_nfc_server_gdbus_get_client_context_no_lock(id); + + if(info != NULL) { - if(g_client_info[i].socket == socket_fd) + if(fgDispatch == true) + { + if(info->pgid == focus_app_pid) + { + info->isTransactionFgDispatch = fgDispatch; + } + else + { + result = NET_NFC_INVALID_STATE; + } + } + else { - g_client_info[i].target_handle = handle; - pthread_mutex_unlock(&g_server_socket_lock); - return true; + info->isTransactionFgDispatch = fgDispatch; } } + else + { + result = NET_NFC_INVALID_STATE; + } + + pthread_mutex_unlock(&context_lock); - pthread_mutex_unlock(&g_server_socket_lock); - return false; + return result; } -#endif -bool net_nfc_server_check_client_is_running(int socket) +net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_client_popup_state( + pid_t pid) { -#ifdef BROADCAST_MESSAGE - return (net_nfc_server_get_client_context(socket) != NULL); -#else - int client_fd = *((int *)client_context); + 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; - if(client_fd > 0) - return true; - else - return false; -#endif -} + pthread_mutex_lock(&context_lock); -client_state_e net_nfc_server_get_client_state(int socket) -{ - GList *item = NULL; - client_state_e state = NET_NFC_CLIENT_INACTIVE_STATE; + 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; + } - pthread_mutex_lock(&g_client_context_lock); + if (temp->pgid == pid) { + info = temp; + break; + } + } - item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_by_socket); - if (item != NULL) - { - state = ((net_nfc_client_info_t *)item->data)->state; + if (info != NULL) { + state = info->launch_popup_state; } - pthread_mutex_unlock(&g_client_context_lock); + pthread_mutex_unlock(&context_lock); return state; } -void net_nfc_server_set_client_state(int socket, client_state_e state) +bool net_nfc_server_gdbus_get_client_transaction_fg_dispatch_state( + pid_t pid) { - GList *item = NULL; + GHashTableIter iter; + char *id; + bool state = false; + net_nfc_client_context_info_t *info = NULL, *temp; - pthread_mutex_lock(&g_client_context_lock); + pthread_mutex_lock(&context_lock); - item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_by_socket); - if (item != NULL) - { - ((net_nfc_client_info_t *)item->data)->state = state; + g_hash_table_iter_init(&iter, client_contexts); + while (g_hash_table_iter_next(&iter, (gpointer *)&id, + (gpointer *)&temp) == true) { + + if (temp->pgid == pid) { + info = temp; + break; + } + } + + if (info != NULL) { + state = info->isTransactionFgDispatch; } - pthread_mutex_unlock(&g_client_context_lock); + pthread_mutex_unlock(&context_lock); + + return state; } -void net_nfc_server_set_launch_state(int socket, net_nfc_launch_popup_state_e popup_state) +void net_nfc_server_gdbus_increase_se_count(const char *id) { - net_nfc_client_info_t *context = net_nfc_server_get_client_context(socket); - pthread_mutex_lock(&g_client_context_lock); - if (context != NULL) - { - context->launch_popup_state = popup_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->ref_se++; } - pthread_mutex_unlock(&g_client_context_lock); + + pthread_mutex_unlock(&context_lock); } -net_nfc_launch_popup_state_e net_nfc_server_get_client_popup_state(pid_t pid) +void net_nfc_server_gdbus_decrease_se_count(const char *id) { - GList *item = NULL; - net_nfc_launch_popup_state_e state = NET_NFC_LAUNCH_APP_SELECT; + net_nfc_client_context_info_t *info; - pthread_mutex_lock(&g_client_context_lock); + pthread_mutex_lock(&context_lock); - item = g_list_find_custom(g_client_contexts, (gconstpointer)pid, _client_context_compare_by_pgid); - if (item != NULL) - { - state = ((net_nfc_client_info_t *)item->data)->launch_popup_state; + info = net_nfc_server_gdbus_get_client_context_no_lock(id); + if (info != NULL) { + info->ref_se--; } - pthread_mutex_unlock(&g_client_context_lock); + pthread_mutex_unlock(&context_lock); +} - return state; +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; } diff --git a/src/manager/net_nfc_server_dispatcher.c b/src/manager/net_nfc_server_dispatcher.c deleted file mode 100644 index f94052c..0000000 --- a/src/manager/net_nfc_server_dispatcher.c +++ /dev/null @@ -1,1132 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "vconf.h" -#include "security-server.h" - -#include "net_nfc_server_dispatcher_private.h" -#include "net_nfc_typedef_private.h" -#include "net_nfc_controller_private.h" -#include "net_nfc_server_ipc_private.h" -#include "net_nfc_debug_private.h" -#include "net_nfc_util_private.h" -#include "net_nfc_util_defines.h" -#include "net_nfc_controller_private.h" -#include "net_nfc_service_private.h" -#include "net_nfc_service_llcp_private.h" -#include "net_nfc_service_llcp_handover_private.h" -#include "net_nfc_service_tag_private.h" -#include "net_nfc_service_se_private.h" -#include "net_nfc_service_test_private.h" -#include "net_nfc_manager_util_private.h" -#include "net_nfc_server_context_private.h" - -static GQueue *g_dispatcher_queue; -static pthread_cond_t g_dispatcher_queue_cond = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t g_dispatcher_queue_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_t g_dispatcher_thread; - -static void *_net_nfc_dispatcher_thread_func(void *data); - -static bool _net_nfc_check_dispatcher_privilege(net_nfc_request_msg_t *msg); - -static net_nfc_request_msg_t *_net_nfc_dispatcher_queue_pop(); - -static net_nfc_request_msg_t *_net_nfc_dispatcher_queue_pop() -{ - net_nfc_request_msg_t *msg = NULL; - msg = g_queue_pop_head(g_dispatcher_queue); - return msg; -} - -void net_nfc_dispatcher_queue_push(net_nfc_request_msg_t *req_msg) -{ - pthread_mutex_lock(&g_dispatcher_queue_lock); - g_queue_push_tail(g_dispatcher_queue, req_msg); - pthread_cond_signal(&g_dispatcher_queue_cond); - pthread_mutex_unlock(&g_dispatcher_queue_lock); -} - -void net_nfc_dispatcher_cleanup_queue(void) -{ - net_nfc_request_msg_t *req_msg = NULL; - - pthread_mutex_lock(&g_dispatcher_queue_lock); - - DEBUG_SERVER_MSG("cleanup dispatcher Q start"); - - while ((req_msg = _net_nfc_dispatcher_queue_pop()) != NULL) - { - DEBUG_ERR_MSG("abandon request : %d", req_msg->request_type); - _net_nfc_util_free_mem(req_msg); - } - - DEBUG_SERVER_MSG("cleanup dispatcher Q end"); - - pthread_mutex_unlock(&g_dispatcher_queue_lock); -} - -void net_nfc_dispatcher_put_cleaner(void) -{ - net_nfc_request_msg_t *req_msg = NULL; - - _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t)); - if (req_msg != NULL) - { - DEBUG_SERVER_MSG("put cleaner request"); - - req_msg->length = sizeof(net_nfc_request_msg_t); - req_msg->request_type = NET_NFC_MESSAGE_SERVICE_CLEANER; - net_nfc_dispatcher_queue_push(req_msg); - } -} - -static void *_net_nfc_dispatcher_copy_message(void *msg) -{ - net_nfc_request_msg_t *origin = (net_nfc_request_msg_t *)msg; - net_nfc_request_msg_t *result = NULL; - - if (origin == NULL || origin->length == 0) - { - return result; - } - - _net_nfc_util_alloc_mem(result, origin->length); - if (result != NULL) - { - memcpy(result, origin, origin->length); - } - - return result; -} - -bool net_nfc_dispatcher_start_thread() -{ - net_nfc_request_msg_t *req_msg = NULL; - pthread_attr_t attr; - int result, state; - - DEBUG_SERVER_MSG("init queue"); - - g_dispatcher_queue = g_queue_new(); - - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - - result = vconf_get_bool(VCONFKEY_NFC_STATE, &state); - if (result != 0) - { - DEBUG_SERVER_MSG("VCONFKEY_NFC_STATE is not exist: %d ", result); - return false; - } - - DEBUG_SERVER_MSG("net_nfc_dispatcher_start_thread vconf state value [%d]", state); - - if (state == TRUE) - { - _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t)); - if (req_msg == NULL) - { - DEBUG_ERR_MSG("alloc failed"); - return false; - } - - req_msg->length = sizeof(net_nfc_request_msg_t); - req_msg->request_type = NET_NFC_MESSAGE_SERVICE_INIT; - - DEBUG_SERVER_MSG("put controller init request"); - net_nfc_dispatcher_queue_push(req_msg); - } - else - { - /*Don't need to initialize the stack!!*/ - } - - if (pthread_create(&g_dispatcher_thread, &attr, _net_nfc_dispatcher_thread_func, NULL) != 0) - { - net_nfc_dispatcher_cleanup_queue(); - DEBUG_ERR_MSG("pthread_create failed"); - return false; - } - - usleep(0); /* switch to new thread */ - return true; -} - -static void *_net_nfc_dispatcher_thread_func(void *data) -{ - net_nfc_request_msg_t *req_msg; - - DEBUG_SERVER_MSG("net_nfc_controller_thread is created "); - - while (1) - { - pthread_mutex_lock(&g_dispatcher_queue_lock); - if ((req_msg = _net_nfc_dispatcher_queue_pop()) == NULL) - { - pthread_cond_wait(&g_dispatcher_queue_cond, &g_dispatcher_queue_lock); - pthread_mutex_unlock(&g_dispatcher_queue_lock); - continue; - } - pthread_mutex_unlock(&g_dispatcher_queue_lock); - -// DEBUG_SERVER_MSG("net_nfc_controller get command = [%d]", req_msg->request_type); - -#if 1 - if (!_net_nfc_check_dispatcher_privilege(req_msg)) - { -// _net_nfc_util_free_mem(req_msg); -// continue; - } -#endif - - switch (req_msg->request_type) - { - case NET_NFC_MESSAGE_SERVICE_CLEANER : - { - net_nfc_service_se_cleanup(); - } - break; - - case NET_NFC_MESSAGE_SEND_APDU_SE : - { - net_nfc_service_se_send_apdu(req_msg); - } - break; - - case NET_NFC_MESSAGE_GET_ATR_SE : - { - net_nfc_service_se_get_atr(req_msg); - } - break; - - case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE : - { - net_nfc_service_se_close_se(req_msg); - } - break; - - case NET_NFC_MESSAGE_OPEN_INTERNAL_SE : - { - net_nfc_service_se_open_se(req_msg); - } - break; - - case NET_NFC_MESSAGE_SET_SE : - { - net_nfc_service_se_set_se(req_msg); - } - break; - - case NET_NFC_MESSAGE_GET_SE : - { - net_nfc_service_se_get_se(req_msg); - } - break; - - case NET_NFC_MESSAGE_CARD_EMULATION_CHANGE_SE : - { - net_nfc_service_se_change_card_emulation_mode(req_msg); - } - break; - - case NET_NFC_MESSAGE_P2P_SEND : - { - net_nfc_request_p2p_send_t *exchanger = (net_nfc_request_p2p_send_t *)req_msg; - - if (net_nfc_server_is_target_connected(exchanger->handle)) - { - if (net_nfc_service_send_exchanger_msg(exchanger) != NET_NFC_OK) - { - DEBUG_SERVER_MSG("net_nfc_service_send_exchanger_msg is failed"); - - /*send result to client*/ - net_nfc_response_p2p_send_t resp_msg = { 0, }; - - resp_msg.handle = exchanger->handle; - resp_msg.result = NET_NFC_P2P_SEND_FAIL; - resp_msg.trans_param = (void *)exchanger->user_param; - - if (net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, &resp_msg, sizeof(net_nfc_response_p2p_send_t), NULL) == true) - { - DEBUG_SERVER_MSG("send exchange failed message to client"); - } - } - } - else - { - net_nfc_response_p2p_send_t resp_msg = { 0, }; - - resp_msg.handle = exchanger->handle; - resp_msg.result = NET_NFC_TARGET_IS_MOVED_AWAY; - resp_msg.trans_param = (void *)exchanger->user_param; - - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, &resp_msg, sizeof(net_nfc_response_p2p_send_t), NULL); - } - } - break; - - case NET_NFC_MESSAGE_TRANSCEIVE : - { - net_nfc_request_transceive_t *detail = (net_nfc_request_transceive_t *)req_msg; - net_nfc_error_e result = NET_NFC_OK; - data_s *data = NULL; - - if (net_nfc_server_is_target_connected(detail->handle)) - { - net_nfc_transceive_info_s info; - - if (net_nfc_util_duplicate_data(&info.trans_data, &detail->info.trans_data) == true) - { - bool success; - - DEBUG_MSG("call transceive"); - if ((success = net_nfc_controller_transceive(detail->handle, &info, &data, &result)) == true) - { - if (data != NULL) - DEBUG_SERVER_MSG("trasceive data recieved [%d], Success = %d", data->length, success); - } - else - { - DEBUG_SERVER_MSG("trasceive is failed = [%d]", result); - } - net_nfc_util_free_data(&info.trans_data); - } - } - else - { - result = NET_NFC_TARGET_IS_MOVED_AWAY; - } - - if (net_nfc_server_check_client_is_running(req_msg->client_fd)) - { - net_nfc_response_transceive_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_transceive_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - resp.result = result; - - if (result == NET_NFC_OK && data != NULL) - { - resp.data.length = data->length; - - DEBUG_SERVER_MSG("send response trans msg"); - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_transceive_t), - data->buffer, data->length, NULL); - } - else - { - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_transceive_t), NULL); - } - } - - if (data != NULL) - { - net_nfc_util_free_data(data); - _net_nfc_util_free_mem(data); - } - } - break; - - case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF : - { - net_nfc_service_tag_make_readonly(req_msg); - } - break; - - case NET_NFC_MESSAGE_IS_TAG_CONNECTED : - { - net_nfc_service_is_tag_connected(req_msg); - } - break; - - case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO : - { - net_nfc_service_get_current_tag_info(req_msg); - } - break; - - case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE : - { - net_nfc_service_get_current_target_handle(req_msg); - } - break; - - case NET_NFC_GET_SERVER_STATE : - { - net_nfc_service_get_server_state(req_msg); - } - break; - - case NET_NFC_MESSAGE_READ_NDEF : - { - net_nfc_service_tag_read_ndef(req_msg); - } - break; - - case NET_NFC_MESSAGE_WRITE_NDEF : - { - net_nfc_service_tag_write_ndef(req_msg); - } - break; - - case NET_NFC_MESSAGE_FORMAT_NDEF : - { - net_nfc_service_tag_format_ndef(req_msg); - } - break; - - case NET_NFC_MESSAGE_SIM_TEST : - { - net_nfc_service_test_sim_test(req_msg); - } - break; - - case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION : - { - net_nfc_service_test_get_firmware_version(req_msg); - } - break; - - case NET_NFC_MESSAGE_PRBS_TEST : - { - net_nfc_service_test_prbs_test(req_msg); - } - break; - - case NET_NFC_MESSAGE_SET_EEDATA : - { - net_nfc_service_test_set_eedata(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_DEINIT : - { - net_nfc_service_deinit(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_INIT : - { - net_nfc_service_init(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED : - { -#ifndef BROADCAST_MESSAGE - net_nfc_service_standalone_mode_target_detected(req_msg); -#endif - } - break; - - case NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP : - { - net_nfc_service_restart_polling(req_msg); - } - break; - - case NET_NFC_MESSAGE_SE_START_TRANSACTION : - { - net_nfc_service_se_transaction_receive(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT : - { - net_nfc_service_llcp_process_accept(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED : - { - net_nfc_service_llcp_disconnect_target(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR : - { - net_nfc_service_llcp_process_socket_error(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR : - { - net_nfc_service_llcp_process_accepted_socket_error(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_SEND : - { - net_nfc_service_llcp_process_send_socket(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO : - { - net_nfc_service_llcp_process_send_to_socket(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE : - { - net_nfc_service_llcp_process_receive_socket(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM : - { - net_nfc_service_llcp_process_receive_from_socket(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT : - { - net_nfc_service_llcp_process_connect_socket(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP : - { - net_nfc_service_llcp_process_connect_sap_socket(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT : - { - net_nfc_service_llcp_process_disconnect_socket(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_SE : - { - net_nfc_service_se_set_se(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_TERMINATION : - { - net_nfc_service_termination(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED : - { - net_nfc_service_slave_mode_target_detected(req_msg); - } - break; - - case NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED : - { - net_nfc_service_se_detected(req_msg); - } - break; - - case NET_NFC_MESSAGE_LLCP_LISTEN : - { - net_nfc_request_listen_socket_t *detail = (net_nfc_request_listen_socket_t *)req_msg; - net_nfc_response_llcp_socket_error_t *error = NULL; - net_nfc_error_e result = NET_NFC_OK; - bool success = false; - - _net_nfc_util_alloc_mem(error, sizeof (net_nfc_response_llcp_socket_error_t)); - if (error == NULL) - { - DEBUG_SERVER_MSG("ERROR: allocation is failed"); - break; - } - - error->length = sizeof(net_nfc_response_llcp_socket_error_t); - error->client_socket = detail->client_socket; - error->handle = detail->handle; - - success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &result, error); - if (success == true) - { - error->oal_socket = detail->oal_socket; - success = net_nfc_controller_llcp_bind(detail->oal_socket, detail->sap, &result); - } - else - { - _net_nfc_util_free_mem(error); - } - - if (success == true) - { - DEBUG_SERVER_MSG("OAL socket in Listen :%d", detail->oal_socket); - success = net_nfc_controller_llcp_listen(detail->handle, detail->service_name.buffer, detail->oal_socket, &result, error); - } - - if (net_nfc_server_check_client_is_running(req_msg->client_fd)) - { - net_nfc_response_listen_socket_t resp = { 0 }; - - resp.length = sizeof(net_nfc_response_listen_socket_t); - resp.flags = detail->flags; - resp.result = result; - resp.oal_socket = detail->oal_socket; - resp.client_socket = detail->client_socket; - resp.trans_param = detail->trans_param; - - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_listen_socket_t), NULL); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_CONNECT : - { - net_nfc_request_connect_socket_t *detail = (net_nfc_request_connect_socket_t *)req_msg; - net_nfc_response_connect_socket_t *resp = NULL; - net_nfc_response_llcp_socket_error_t *error = NULL; - bool success = false; - - _net_nfc_util_alloc_mem(error, sizeof (net_nfc_response_llcp_socket_error_t)); - if (error == NULL) - { - DEBUG_SERVER_MSG("ERROR: invalid detail info or allocation is failed"); - break; - } - - _net_nfc_util_alloc_mem(resp, sizeof (net_nfc_response_connect_socket_t)); - if (resp == NULL) - { - DEBUG_SERVER_MSG("ERROR: invalid detail info or allocation is failed"); - _net_nfc_util_free_mem(error); - break; - } - - error->length = sizeof(net_nfc_response_llcp_socket_error_t); - error->client_socket = detail->client_socket; - error->handle = detail->handle; - - resp->length = sizeof(net_nfc_response_connect_socket_t); - resp->flags = detail->flags; - resp->result = NET_NFC_IPC_FAIL; - - success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &(resp->result), error); - if (success == true) - { - error->oal_socket = resp->oal_socket = detail->oal_socket; - DEBUG_SERVER_MSG("connect client socket [%d]", detail->client_socket); - resp->client_socket = detail->client_socket; - resp->trans_param = detail->trans_param; - - success = net_nfc_controller_llcp_connect_by_url(detail->handle, detail->oal_socket, detail->service_name.buffer, &(resp->result), resp); - if (success == false) - { - DEBUG_ERR_MSG("connect client socket is failed"); - - net_nfc_controller_llcp_socket_close(resp->oal_socket, &(resp->result)); - - if (net_nfc_server_check_client_is_running(req_msg->client_fd)) - { - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_connect_socket_t), NULL); - } - _net_nfc_util_free_mem(resp); - } - } - else - { - if (net_nfc_server_check_client_is_running(req_msg->client_fd)) - { - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_connect_socket_t), NULL); - } - - _net_nfc_util_free_mem(error); - _net_nfc_util_free_mem(resp); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_CONNECT_SAP : - { - net_nfc_request_connect_sap_socket_t *detail = (net_nfc_request_connect_sap_socket_t *)req_msg; - net_nfc_response_connect_sap_socket_t *resp = NULL; - bool success = false; - - _net_nfc_util_alloc_mem(resp, sizeof(net_nfc_response_connect_sap_socket_t)); - if (resp == NULL) - { - DEBUG_SERVER_MSG("ERROR: allocation is failed"); - break; - } - - resp->length = sizeof(net_nfc_response_connect_sap_socket_t); - resp->flags = detail->flags; - resp->result = NET_NFC_IPC_FAIL; - - success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &(resp->result), NULL); - if (success == true) - { - resp->oal_socket = detail->oal_socket; - resp->client_socket = detail->client_socket; - resp->trans_param = detail->trans_param; - - success = net_nfc_controller_llcp_connect(detail->handle, detail->oal_socket, detail->sap, &(resp->result), resp); - } - - if (success == false) - { - if (net_nfc_server_check_client_is_running(req_msg->client_fd)) - { - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_connect_sap_socket_t), NULL); - } - _net_nfc_util_free_mem(resp); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_SEND : - { - net_nfc_request_send_socket_t *detail = (net_nfc_request_send_socket_t *)req_msg; - data_s data = { NULL, 0 }; - - if (net_nfc_util_duplicate_data(&data, &detail->data) == true) - { - net_nfc_response_send_socket_t *resp = NULL; - - _net_nfc_util_alloc_mem(resp, sizeof (net_nfc_response_send_socket_t)); - if (resp != NULL) - { - resp->length = sizeof(net_nfc_response_send_socket_t); - resp->flags = detail->flags; - resp->result = NET_NFC_IPC_FAIL; - resp->client_socket = detail->client_socket; - resp->trans_param = detail->trans_param; - - if (net_nfc_controller_llcp_send(detail->handle, detail->oal_socket, &data, &(resp->result), resp) == false) - { - if (net_nfc_server_check_client_is_running(req_msg->client_fd)) - { - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_send_socket_t), NULL); - } - _net_nfc_util_free_mem(resp); - } - } - - net_nfc_util_free_data(&data); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_RECEIVE : - { - net_nfc_request_receive_socket_t *detail = (net_nfc_request_receive_socket_t *)req_msg; - net_nfc_response_receive_socket_t *resp = NULL; - - _net_nfc_util_alloc_mem(resp, sizeof (net_nfc_response_receive_socket_t)); - if (resp == NULL) - { - DEBUG_SERVER_MSG("ERROR: allocation is failed"); - break; - } - - resp->length = sizeof(net_nfc_response_receive_socket_t); - resp->flags = detail->flags; - resp->result = NET_NFC_IPC_FAIL; - resp->client_socket = detail->client_socket; - resp->trans_param = detail->trans_param; - resp->data.length = detail->req_length; - _net_nfc_util_alloc_mem(resp->data.buffer, detail->req_length); - if (resp->data.buffer == NULL) - { - DEBUG_SERVER_MSG("ERROR: allocation is failed"); - _net_nfc_util_free_mem(resp); - break; - } - - if (net_nfc_controller_llcp_recv(detail->handle, detail->oal_socket, &(resp->data), &(resp->result), resp) == false) - { - if (net_nfc_server_check_client_is_running(req_msg->client_fd)) - { - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_receive_socket_t), NULL); - } - _net_nfc_util_free_mem(resp->data.buffer); - _net_nfc_util_free_mem(resp); - } - } - break; - - case NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE : - { - net_nfc_request_close_socket_t *detail = (net_nfc_request_close_socket_t *)req_msg; - net_nfc_error_e result = NET_NFC_OK; - - DEBUG_SERVER_MSG("socket close :: NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE"); - net_nfc_controller_llcp_socket_close(detail->oal_socket, &result); - - if (net_nfc_server_check_client_is_running(req_msg->client_fd)) - { - net_nfc_response_close_socket_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_close_socket_t); - resp.flags = detail->flags; - resp.result = result; - resp.client_socket = detail->client_socket; - resp.trans_param = detail->trans_param; - - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_close_socket_t), NULL); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_DISCONNECT : /* change resp to local variable. if there is some problem, check this first. */ - { - net_nfc_request_disconnect_socket_t *detail = (net_nfc_request_disconnect_socket_t *)req_msg; - net_nfc_request_disconnect_socket_t *context = NULL; - net_nfc_error_e result = NET_NFC_OK; - - context = _net_nfc_dispatcher_copy_message(detail); - if (context == NULL) - { - DEBUG_ERR_MSG("alloc failed"); - break; - } - - if (net_nfc_controller_llcp_disconnect(detail->handle, detail->oal_socket, &result, &context) == false) - { - if (net_nfc_server_check_client_is_running(req_msg->client_fd)) - { - net_nfc_response_disconnect_socket_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_disconnect_socket_t); - resp.flags = detail->flags; - resp.result = result; - resp.client_socket = detail->client_socket; - resp.trans_param = detail->trans_param; - - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_disconnect_socket_t), NULL); - } - - _net_nfc_util_free_mem(context); - } - - } - break; - - case NET_NFC_MESSAGE_LLCP_ACCEPTED : - { - net_nfc_request_accept_socket_t *detail = (net_nfc_request_accept_socket_t *)req_msg; - net_nfc_error_e result = NET_NFC_OK; - - net_nfc_controller_llcp_accept(detail->incomming_socket, &result); - - if (net_nfc_server_check_client_is_running(req_msg->client_fd)) - { - net_nfc_response_accept_socket_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_accept_socket_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - resp.result = result; - resp.client_socket = detail->client_socket; - - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_accept_socket_t), NULL); - } - } - break; - - case NET_NFC_MESSAGE_LLCP_CONFIG : - { - net_nfc_request_config_llcp_t *detail = (net_nfc_request_config_llcp_t *)req_msg; - net_nfc_error_e result = NET_NFC_OK; - - net_nfc_controller_llcp_config(&(detail->config), &result); - - if (net_nfc_server_check_client_is_running(detail->client_fd)) - { - net_nfc_response_config_llcp_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_config_llcp_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - resp.result = result; - - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_config_llcp_t), NULL); - } - } - break; - - case NET_NFC_MESSAGE_CONNECTION_HANDOVER : - { - net_nfc_request_connection_handover_t *detail = (net_nfc_request_connection_handover_t *)req_msg; - net_nfc_error_e result = NET_NFC_OK; - - net_nfc_request_msg_t *param = NULL; - - if ((param = _net_nfc_dispatcher_copy_message(detail)) == NULL) - { - DEBUG_ERR_MSG("alloc failed"); - break; - } - - if ((result = net_nfc_service_llcp_handover_send_request_msg((net_nfc_request_connection_handover_t *)param)) != NET_NFC_OK) - { - if (net_nfc_server_check_client_is_running(req_msg->client_fd)) - { - net_nfc_response_connection_handover_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_connection_handover_t); - resp.flags = detail->flags; - resp.user_param = detail->user_param; - resp.result = result; - resp.event = NET_NFC_OPERATION_FAIL; - resp.type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; - - net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_connection_handover_t), NULL); - } - } - - _net_nfc_util_free_mem(param); - } - break; - - case NET_NFC_MESSAGE_SERVICE_WATCH_DOG : - { - net_nfc_service_watch_dog(req_msg); - continue; - } - break; - - default : - break; - } - - /*need to free req_msg*/ - _net_nfc_util_free_mem(req_msg); - } - - return (void *)NULL; -} - -/* return true to authentication success; false to fail to authenticate */ -bool _net_nfc_check_dispatcher_privilege(net_nfc_request_msg_t *request_msg) -{ - int client_fd_request = request_msg->client_fd; - int ret_value; - - switch(request_msg->request_type) - { -#if 0 - case NET_NFC_MESSAGE_SERVICE_ACTIVATE: - DEBUG_SERVER_MSG("checking NET_NFC_MESSAGE_SERVICE_ACTIVATE..."); - ret_value = security_server_check_privilege_by_sockfd(client_fd_request,"nfc-manager::admin","w"); - if (ret_value == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) - { - DEBUG_SERVER_MSG("checking failed, and then send response to client"); - - if (net_nfc_server_check_client_is_running(client_fd_request)){ - net_nfc_response_test_t resp = { 0, }; - resp.length = sizeof(net_nfc_response_test_t); - resp.flags = request_msg->flags; - resp.result = NET_NFC_SECURITY_FAIL; - resp.trans_param = (void *)request_msg->user_param; - net_nfc_send_response_msg(request_msg->client_fd, request_msg->request_type,(void *)&resp, sizeof(net_nfc_response_test_t), NULL); - - } - return false; - } - DEBUG_SERVER_MSG("checking success"); - break; - -#endif - case NET_NFC_MESSAGE_TRANSCEIVE: - DEBUG_SERVER_MSG("checking NET_NFC_MESSAGE_TRANSCEIVE..."); - ret_value = security_server_check_privilege_by_sockfd(client_fd_request,"nfc-manager::tag","w"); - - if (ret_value == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) - { - DEBUG_SERVER_MSG("checking failed, and then send response to client"); -#if 0 - - if (net_nfc_server_check_client_is_running(client_fd_request)) - { - net_nfc_request_transceive_t *detail = (net_nfc_request_transceive_t *)request_msg; - net_nfc_response_transceive_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_transceive_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - resp.result = NET_NFC_SECURITY_FAIL; - - net_nfc_send_response_msg(request_msg->client_fd, request_msg->request_type, (void *)&resp, sizeof(net_nfc_response_transceive_t), NULL); - - } - return false; -#endif - } - DEBUG_SERVER_MSG("checking success"); - break; - - case NET_NFC_MESSAGE_READ_NDEF: - - DEBUG_SERVER_MSG("checking NET_NFC_MESSAGE_READ_NDEF..."); - ret_value = security_server_check_privilege_by_sockfd(client_fd_request,"nfc-manager::tag","w"); - - if (ret_value == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) - { - DEBUG_SERVER_MSG("checking failed, and then send response to client"); -#if 0 - - if (net_nfc_server_check_client_is_running(client_fd_request)) - { - net_nfc_request_read_ndef_t *detail = (net_nfc_request_read_ndef_t *)request_msg; - net_nfc_response_write_ndef_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_read_ndef_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - resp.result = NET_NFC_SECURITY_FAIL; - - net_nfc_send_response_msg(request_msg->client_fd, request_msg->request_type, (void *)&resp, sizeof(net_nfc_response_write_ndef_t), NULL); - - } - return false; -#endif - } - DEBUG_SERVER_MSG("checking success"); - break; - - case NET_NFC_MESSAGE_WRITE_NDEF: - DEBUG_SERVER_MSG("checking NET_NFC_MESSAGE_WRITE_NDEF..."); - ret_value = security_server_check_privilege_by_sockfd(client_fd_request,"nfc-manager::tag","w"); - - if (ret_value == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) - { - DEBUG_SERVER_MSG("checking failed, and then send response to client"); -#if 0 - - if (net_nfc_server_check_client_is_running(client_fd_request)) - { - net_nfc_request_write_ndef_t *detail = (net_nfc_request_write_ndef_t *)request_msg; - net_nfc_response_write_ndef_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_write_ndef_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - resp.result = NET_NFC_SECURITY_FAIL; - - net_nfc_send_response_msg(request_msg->client_fd, request_msg->request_type, (void *)&resp, sizeof(net_nfc_response_write_ndef_t), NULL); - - } - return false; -#endif - } - DEBUG_SERVER_MSG("checking success"); - break; - - case NET_NFC_MESSAGE_P2P_SEND: - DEBUG_SERVER_MSG("checking NET_NFC_MESSAGE_P2P_SEND..."); - ret_value = security_server_check_privilege_by_sockfd(client_fd_request,"nfc-manager::p2p","w"); - - if (ret_value == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) - { - DEBUG_SERVER_MSG("checking failed, and then send response to client"); -#if 0 - - if (net_nfc_server_check_client_is_running(client_fd_request)) - { - net_nfc_request_p2p_send_t *exchanger = (net_nfc_request_p2p_send_t *)request_msg; - - net_nfc_response_p2p_send_t resp_msg = { 0, }; - - resp_msg.length = sizeof(resp_msg); - resp_msg.response_type = NET_NFC_MESSAGE_P2P_SEND; - resp_msg.handle = exchanger->handle; - resp_msg.result = NET_NFC_SECURITY_FAIL; - resp_msg.trans_param = (void *)exchanger->user_param; - - net_nfc_send_response_msg(request_msg->client_fd,NET_NFC_MESSAGE_P2P_SEND, &resp_msg,sizeof(resp_msg), NULL); - - } - return false; -#endif - } - DEBUG_SERVER_MSG("checking success"); - break; - -#if 0 - case NET_NFC_MESSAGE_SNEP_START_SERVER : - DEBUG_SERVER_MSG("checking NET_NFC_MESSAGE_SNEP_START_SERVER..."); - ret_value = security_server_check_privilege_by_sockfd(client_fd_request,"nfc-manager::p2p","rw"); - - if (ret_value == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) - { - DEBUG_SERVER_MSG("checking failed, and then send response to client"); - if (net_nfc_server_check_client_is_running(client_fd_request)) - { - net_nfc_request_listen_socket_t *msg = (net_nfc_request_listen_socket_t *)request_msg; - net_nfc_response_receive_socket_t resp = { 0 }; - resp.length = sizeof(resp); - resp.response_type = NET_NFC_MESSAGE_SNEP_START_SERVER; - resp.user_param = msg->user_param; - resp.result = NET_NFC_SECURITY_FAIL; - net_nfc_send_response_msg(request_msg->client_fd, request_msg->request_type, (void *)&resp, sizeof(net_nfc_response_receive_socket_t), NULL); - } - return false; - } - DEBUG_SERVER_MSG("checking success"); - break; - -#endif -#if 0 - case NET_NFC_MESSAGE_SNEP_START_CLIENT : - DEBUG_SERVER_MSG("checking NET_NFC_MESSAGE_SNEP_START_CLIENT..."); - - ret_value = security_server_check_privilege_by_sockfd(client_fd_request,"nfc-manager::p2p","rw"); - if (ret_value == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) - { - DEBUG_SERVER_MSG("checking failed, and then send response to client"); - if (net_nfc_server_check_client_is_running(client_fd_request)) - { - net_nfc_request_snep_client_t *msg =(net_nfc_request_snep_client_t *)request_msg; - net_nfc_response_receive_socket_t resp_msg = { 0, }; - resp_msg.length = sizeof(resp_msg); - resp_msg.response_type = NET_NFC_MESSAGE_SNEP_START_CLIENT; - resp_msg.user_param = msg->user_param; - resp_msg.result = NET_NFC_SECURITY_FAIL; - net_nfc_send_response_msg(request_msg->client_fd, request_msg->request_type, (void *)&resp_msg, sizeof(net_nfc_response_receive_socket_t), NULL); - } - return false; - } - DEBUG_SERVER_MSG("checking success"); - break; - -#endif -#if 0 - case NET_NFC_MESSAGE_SNEP_STOP_SERVICE : - ret_value = security_server_check_privilege_by_sockfd(client_fd_request,"nfc-manager::p2p","rw"); - if (ret_value == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) - { - return false; - - } - break; - -#endif - default : - return true; - } - - return true; -} diff --git a/src/manager/net_nfc_server_handover.c b/src/manager/net_nfc_server_handover.c new file mode 100755 index 0000000..940947a --- /dev/null +++ b/src/manager/net_nfc_server_handover.c @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_controller_internal.h" +#include "net_nfc_server_common.h" +#include "net_nfc_server_context_internal.h" +#include "net_nfc_server_handover.h" +#include "net_nfc_server_process_handover.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 = (HandoverRequestData *)user_data; + net_nfc_error_e result; + + g_assert(handover_data != NULL); + g_assert(handover_data->handoverobj != NULL); + g_assert(handover_data->invocation != NULL); + + result = net_nfc_server_handover_default_client_start( + GUINT_TO_POINTER(handover_data->handle), + (void *)handover_data); + if (result != NET_NFC_OK) + { + net_nfc_gdbus_handover_complete_request( + handover_data->handoverobj, + handover_data->invocation, + result, + NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, + net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + 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 = NULL; + gint 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::p2p", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(HandoverRequestData,1); + if(data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->handoverobj = g_object_ref(hdover); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->type = arg_type; + + if (net_nfc_server_controller_async_queue_push( + handover_request_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->handoverobj); + + g_free(data); + } + + net_nfc_gdbus_handover_complete_request( + hdover, + invocation, + result, + NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, + net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + return TRUE; +} + +net_nfc_error_e net_nfc_server_handover_emit_started_signal( + net_nfc_target_handle_s *handle, data_s *message) +{ + if (handover_skeleton == NULL) { + return NET_NFC_INVALID_STATE; + } + + net_nfc_gdbus_handover_emit_started(handover_skeleton, + net_nfc_util_gdbus_data_to_variant(message)); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_server_handover_emit_finished_signal( + net_nfc_error_e result, + net_nfc_conn_handover_carrier_type_e type, + data_s *address, data_s *message) +{ + if (handover_skeleton == NULL) { + return NET_NFC_INVALID_STATE; + } + + net_nfc_gdbus_handover_emit_finished(handover_skeleton, + result, + type, + net_nfc_util_gdbus_data_to_variant(address), + net_nfc_util_gdbus_data_to_variant(message)); + + return NET_NFC_OK; +} + +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; + } +} diff --git a/src/manager/net_nfc_server_handover_bt.c b/src/manager/net_nfc_server_handover_bt.c new file mode 100755 index 0000000..572badc --- /dev/null +++ b/src/manager/net_nfc_server_handover_bt.c @@ -0,0 +1,1285 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#ifdef USE_SYSTEM_INFO +#include "system_info.h" +#endif + +#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_handover.h" +#include "net_nfc_util_handover_internal.h" +#include "net_nfc_server_handover_internal.h" +#include "net_nfc_server_llcp.h" +#include "net_nfc_app_util_internal.h" + + +typedef struct _net_nfc_handover_bt_get_context_t +{ + bool already_on; + int step; + net_nfc_error_e result; + net_nfc_ch_carrier_s *carrier; + net_nfc_server_handover_get_carrier_cb cb; + void *user_param; +} +net_nfc_handover_bt_get_context_t; + +typedef struct _net_nfc_handover_bt_process_context_t +{ + bool already_on; + int step; + net_nfc_error_e result; + net_nfc_server_handover_process_carrier_cb cb; + net_nfc_ch_carrier_s *carrier; + data_s data; + char remote_address[20]; + bt_service_class_t service_mask; + void *user_param; +} +net_nfc_handover_bt_process_context_t; + +typedef struct { + unsigned char hash[16]; + unsigned char randomizer[16]; + unsigned int hash_len; + unsigned int randomizer_len; +} net_nfc_handover_bt_oob_data_t; + +static uint8_t __bt_cod[] = { 0x0c, 0x02, 0x5a }; /* 0x5a020c */ +#ifndef USE_SYSTEM_INFO +static const char *manufacturer = "Samsung Tizen"; +#endif + +static int _bt_get_carrier_record(net_nfc_handover_bt_get_context_t *context); +static int _bt_prepare_pairing(net_nfc_handover_bt_process_context_t *context); +static int _bt_do_pairing(net_nfc_handover_bt_process_context_t *context); + + +static net_nfc_error_e _bt_get_oob_data_from_config( + net_nfc_carrier_config_s *config, + net_nfc_handover_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(net_nfc_handover_bt_oob_data_t)); + + result = net_nfc_util_get_carrier_config_property(config, + NET_NFC_BT_ATTRIBUTE_OOB_HASH_C, + (uint16_t *)&hash.length, &hash.buffer); + if (result == NET_NFC_OK) + { + if (hash.length == 16) + { + INFO_MSG("hash found"); + + 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); + } + } + + result = net_nfc_util_get_carrier_config_property(config, + NET_NFC_BT_ATTRIBUTE_OOB_HASH_R, + (uint16_t *)&randomizer.length, &randomizer.buffer); + if (result == NET_NFC_OK) + { + if (randomizer.length == 16) + { + INFO_MSG("randomizer found"); + + 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 _bt_carrier_record_cb(int result, bt_adapter_state_e adapter_state, + 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 (adapter_state) + { + case BT_ADAPTER_ENABLED : + INFO_MSG("BT_ADAPTER_ENABLED"); + if (context->step == NET_NFC_LLCP_STEP_02) + { + _bt_get_carrier_record(context); + } + else + { + DEBUG_ERR_MSG("step is incorrect"); + } + break; + + case BT_ADAPTER_DISABLED : + INFO_MSG("BT_ADAPTER_DISABLED"); + break; + + default : + DEBUG_MSG("unhandled bt event [%d], [%d]", adapter_state, result); + break; + } + + LOGD("[%s] END", __func__); +} + +static void _append_oob_data(net_nfc_carrier_config_s *config) +{ + net_nfc_error_e result; + unsigned char *hash; + unsigned char *randomizer; + int hash_len; + int randomizer_len; + + /* get oob data, optional!!! */ + result = bt_adapter_get_local_oob_data(&hash, &randomizer, &hash_len, &randomizer_len); + if (result == BT_ERROR_NONE) + { + if (hash_len == 16 && randomizer_len == 16) + { + INFO_MSG("oob.hash_len [%d], oob.randomizer_len [%d]", hash_len, randomizer_len); + + NET_NFC_REVERSE_ORDER_16_BYTES(hash); + + result = net_nfc_util_add_carrier_config_property( + config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_C, + hash_len, hash); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result); + } + + NET_NFC_REVERSE_ORDER_16_BYTES(randomizer); + + result = net_nfc_util_add_carrier_config_property( + config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_R, + randomizer_len, randomizer); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result); + } + } + else + { + DEBUG_ERR_MSG("abnormal oob data, skip...."); + } + } + else + { + DEBUG_ERR_MSG("bt oob_read_local_data failed, skip.... [%d]", result); + } +} + +static net_nfc_error_e _bt_create_config_record(ndef_record_s **record) +{ + char* bt_addr = NULL; + char *bt_name = NULL; + net_nfc_carrier_config_s *config = NULL; + net_nfc_error_e result; + + if (record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *record = NULL; + + result = net_nfc_util_create_carrier_config(&config, + NET_NFC_CONN_HANDOVER_CARRIER_BT); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_create_carrier_config failed [%d]", result); + goto END; + } + + /* add blutooth address, mandatory */ + + result = bt_adapter_get_address(&bt_addr); + if (result != BT_ERROR_NONE) + { + DEBUG_ERR_MSG("bt_adapter_get_address failed [%d]", result); + result = NET_NFC_OPERATION_FAIL; + goto END; + } + + NET_NFC_REVERSE_ORDER_6_BYTES(bt_addr); + + result = net_nfc_util_add_carrier_config_property( + config, NET_NFC_BT_ATTRIBUTE_ADDRESS, + strlen(bt_addr), bt_addr); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result); + goto END; + } + + /* append cod */ + result = net_nfc_util_add_carrier_config_property( + config, NET_NFC_BT_ATTRIBUTE_OOB_COD, + sizeof(__bt_cod), __bt_cod); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result); + goto END; + } + + /* append oob */ + _append_oob_data(config); + + /* append device name */ + result = bt_adapter_get_name(&bt_name); + if (result != BT_ERROR_NONE) + { + DEBUG_ERR_MSG("bt_adapter_get_name failed [%d]", result); + result = NET_NFC_OPERATION_FAIL; + goto END; + } + + if(bt_name == NULL) + { + result = NET_NFC_OPERATION_FAIL; + goto END; + } + + if (strlen(bt_name) > 0) { + result = net_nfc_util_add_carrier_config_property( + config, NET_NFC_BT_ATTRIBUTE_NAME, + strlen(bt_name), (uint8_t *)bt_name); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result); + goto END; + } + } else { + INFO_MSG("device name is empty, skip appending device name"); + } + + /* append manufacturer */ +#ifdef USE_SYSTEM_INFO + char *manufacturer = NULL; + + result = system_info_get_value_string(SYSTEM_INFO_KEY_MANUFACTURER, &manufacturer); + if (result != SYSTEM_INFO_ERROR_NONE) { + DEBUG_ERR_MSG("system_info_get_value_string failed [%d]", result); + result = NET_NFC_OPERATION_FAIL; + goto END; + } +#endif + if (manufacturer != NULL && strlen(manufacturer) > 0) { + result = net_nfc_util_add_carrier_config_property( + config, NET_NFC_BT_ATTRIBUTE_MANUFACTURER, + strlen(manufacturer), (uint8_t *)manufacturer); +#ifdef USE_SYSTEM_INFO + g_free(manufacturer); +#endif + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result); + goto END; + } + } + + result = net_nfc_util_handover_bt_create_record_from_config(record, config); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_create_ndef_record_with_carrier_config failed [%d]", result); + } + +END : + if (bt_name != NULL) + free(bt_name); + + if (bt_addr != NULL) + free(bt_addr); + + if (config != NULL) { + net_nfc_util_free_carrier_config(config); + } + + return result; +} + +static int _bt_get_carrier_record(net_nfc_handover_bt_get_context_t *context) +{ + int ret; + 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]"); + + ret = bt_initialize(); + ret = bt_adapter_set_state_changed_cb(_bt_carrier_record_cb, context); + + if (ret >= BT_ERROR_NONE) + { + bt_adapter_state_e adapter_state; + context->step = NET_NFC_LLCP_STEP_02; + context->result = NET_NFC_OK; + + ret = bt_adapter_get_state(&adapter_state); + + if (ret == BT_ADAPTER_DISABLED) + { + bt_adapter_enable(); + } + else + { + DEBUG_MSG("BT is enabled already"); + context->already_on = true; + + /* do next step */ + g_idle_add((GSourceFunc)_bt_get_carrier_record, (gpointer)context); + } + } + else + { + DEBUG_ERR_MSG("bt register_callback failed"); + + context->step = NET_NFC_LLCP_STEP_RETURN; + context->result = NET_NFC_OPERATION_FAIL; + + g_idle_add((GSourceFunc)_bt_get_carrier_record, (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_02 : + { + ndef_record_s *record; + + DEBUG_MSG("STEP [2]"); + + context->step = NET_NFC_LLCP_STEP_RETURN; + + /* append config to ndef message */ + context->result = _bt_create_config_record( + &record); + if (context->result == NET_NFC_OK) { + net_nfc_util_append_handover_carrier_record( + context->carrier, record); + } else { + DEBUG_ERR_MSG("_bt_create_config_record failed, [%d]", context->result); + } + + /* complete and return to upper step */ + g_idle_add((GSourceFunc)_bt_get_carrier_record, + (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_RETURN : + { + net_nfc_ch_carrier_s *carrier = NULL; + + DEBUG_MSG("STEP return"); + + bt_deinitialize(); + + if (context->result == NET_NFC_OK) { + carrier = context->carrier; + } + + /* complete and return to upper step */ + context->cb(context->result, carrier, + context->user_param); + + if (carrier != NULL) { + net_nfc_util_free_handover_carrier(carrier); + } + + _net_nfc_util_free_mem(context); + } + break; + + default : + break; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} + +net_nfc_error_e net_nfc_server_handover_bt_get_carrier( + net_nfc_server_handover_get_carrier_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 */ + result = net_nfc_util_create_handover_carrier(&context->carrier, + NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE); + if (result == NET_NFC_OK) { + g_idle_add((GSourceFunc)_bt_get_carrier_record, + (gpointer)context); + } + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} + +static void _bt_prepare_pairing_cb(int result, bt_adapter_state_e adapter_state, + 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 (adapter_state) + { + case BT_ADAPTER_ENABLED : + INFO_MSG("BT_ADAPTER_ENABLED"); + if (context->step == NET_NFC_LLCP_STEP_02) + { + _bt_prepare_pairing(context); + } + else + { + DEBUG_ERR_MSG("step is incorrect"); + } + break; + + case BT_ADAPTER_DISABLED: + INFO_MSG("BT_ADAPTER_DISABLED"); + if (context->step == NET_NFC_LLCP_STEP_RETURN) + { + _bt_prepare_pairing(context); + } + else + { + DEBUG_ERR_MSG("step is incorrect"); + } + break; + + default : + DEBUG_SERVER_MSG("unhandled bt event [%d]," + "[0x%04x]", adapter_state, result); + break; + } + + LOGD("[%s] END", __func__); +} + +static int _bt_prepare_pairing(net_nfc_handover_bt_process_context_t *context) +{ + int ret; + + 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 : + INFO_MSG("STEP [1]"); + + ret = bt_initialize(); + ret = bt_adapter_set_state_changed_cb(_bt_prepare_pairing_cb, context); + + if (ret >= BT_ERROR_NONE) + { + bt_adapter_state_e adapter_state; + /* next step */ + context->step = NET_NFC_LLCP_STEP_02; + + ret = bt_adapter_get_state(&adapter_state); + + if (ret != BT_ADAPTER_DISABLED) + { + context->result = NET_NFC_OK; + + ret = bt_adapter_enable(); + if (ret != BT_ERROR_NONE) + { + DEBUG_ERR_MSG("bt_adapter_enable failed, [%d]", ret); + + context->step = NET_NFC_STATE_ERROR; + context->result = NET_NFC_OPERATION_FAIL; + } + } + else + { + /* do next step */ + INFO_MSG("BT is enabled already, go next step"); + + context->already_on = true; + context->result = NET_NFC_OK; + + g_idle_add((GSourceFunc)_bt_prepare_pairing, + (gpointer)context); + } + } + else + { + DEBUG_ERR_MSG("bt_adapter_set_state_changed_cb failed, [%d]", ret); + context->step = NET_NFC_STATE_ERROR; + context->result = NET_NFC_OPERATION_FAIL; + + g_idle_add((GSourceFunc)_bt_prepare_pairing, + (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_02 : + { + net_nfc_carrier_config_s *config; + data_s temp = { NULL, 0 }; + + INFO_MSG("STEP [2]"); + + net_nfc_util_create_carrier_config_from_config_record( + &config, context->carrier->carrier_record); + + net_nfc_util_get_carrier_config_property(config, + NET_NFC_BT_ATTRIBUTE_ADDRESS, + (uint16_t *)&temp.length, &temp.buffer); + if (temp.length == 6) + { + bt_device_info_s *device_info; + + NET_NFC_REVERSE_ORDER_6_BYTES(temp.buffer); + sprintf(context->remote_address, "%02X:%02X:%02X:%02X:%02X:%02X", + temp.buffer[0], + temp.buffer[1], + temp.buffer[2], + temp.buffer[3], + temp.buffer[4], + temp.buffer[5]); + + if (bt_adapter_get_bonded_device_info(context->remote_address, &device_info) == BT_ERROR_NONE) + { + INFO_MSG("already paired with [%s]", context->remote_address); + + /* return */ + context->step = NET_NFC_LLCP_STEP_RETURN; + context->result = NET_NFC_OK; + } + else + { + net_nfc_handover_bt_oob_data_t oob = { { 0 } , }; + + if (_bt_get_oob_data_from_config(config, &oob) == NET_NFC_OK) + { + /* set oob data */ + bt_adapter_set_remote_oob_data(context->remote_address, + oob.hash, oob.randomizer, oob.hash_len, oob.randomizer_len); + } + + /* pair and send response */ + context->step = NET_NFC_LLCP_STEP_RETURN; + context->result = NET_NFC_OK; + } + } + else + { + DEBUG_ERR_MSG("bluetooth address is invalid. [%d] bytes", temp.length); + + context->step = NET_NFC_STATE_ERROR; + context->result = NET_NFC_OPERATION_FAIL; + } + + net_nfc_util_free_carrier_config(config); + + g_idle_add((GSourceFunc)_bt_prepare_pairing, + (gpointer)context); + } + break; + + case NET_NFC_STATE_ERROR : + INFO_MSG("STEP ERROR"); + + context->step = NET_NFC_LLCP_STEP_RETURN; + if (context->already_on == false) + { + bt_adapter_disable(); + } + else + { + g_idle_add((GSourceFunc)_bt_prepare_pairing, + (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_RETURN : + { + data_s temp = { context->remote_address, sizeof(context->remote_address) }; + data_s *data = NULL; + + INFO_MSG("STEP return"); + + bt_deinitialize(); + + if (context->result == NET_NFC_OK) + { + data = &temp; + } + + context->cb(context->result, + NET_NFC_CONN_HANDOVER_CARRIER_BT, + data, context->user_param); + + /* release context */ + if (context->carrier != NULL) + { + net_nfc_util_free_handover_carrier( + context->carrier); + } + + net_nfc_util_clear_data(&context->data); + _net_nfc_util_free_mem(context); + } + break; + + default : + break; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} + +net_nfc_error_e net_nfc_server_handover_bt_prepare_pairing( + net_nfc_ch_carrier_s *carrier, + net_nfc_server_handover_process_carrier_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_duplicate_handover_carrier(&context->carrier, + carrier); + + g_idle_add((GSourceFunc)_bt_prepare_pairing, + (gpointer)context); + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} + +static void __bt_get_name(ndef_record_s *record, char *name, uint32_t length) +{ + net_nfc_carrier_config_s *config; + uint16_t len = 0; + uint8_t *buf = NULL; + + net_nfc_util_handover_bt_create_config_from_record( + &config, record); + + if (net_nfc_util_get_carrier_config_property(config, + NET_NFC_BT_ATTRIBUTE_NAME, + &len, &buf) == NET_NFC_OK) { + len = MIN(len, length - 1); + memcpy(name, buf, len); + name[len] = 0; + } else { + net_nfc_util_get_carrier_config_property(config, + NET_NFC_BT_ATTRIBUTE_ADDRESS, + &len, &buf); + + snprintf(name, length, + "%02X:%02X:%02X:%02X:%02X:%02X", + buf[0], buf[1], buf[2], + buf[3], buf[4], buf[5]); + } + + _net_nfc_util_free_mem(config); +} + +static void _bt_audio_connection_state_changed_cb(int result, bool connected, + const char *remote_address, bt_audio_profile_type_e type, void *user_data) +{ + net_nfc_handover_bt_process_context_t *context = + (net_nfc_handover_bt_process_context_t *)user_data; + + switch(type) { + case BT_AUDIO_PROFILE_TYPE_AG : + case BT_AUDIO_PROFILE_TYPE_HSP_HFP : + case BT_AUDIO_PROFILE_TYPE_A2DP : + if(connected == true) + { + if (result == BT_ERROR_NONE) { + INFO_MSG("connected device [%s]", context->remote_address); + context->result = NET_NFC_OK; + } else { + char name[512]; + + DEBUG_ERR_MSG("connecting failed, [%d]", result); + + __bt_get_name(context->carrier->carrier_record, name, sizeof(name)); + + net_nfc_app_util_show_notification(IDS_SIGNAL_4, name); + + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_STATE_ERROR; + } + } + else + { + if (result == BT_ERROR_NONE) { + INFO_MSG("disconnected device [%s]", context->remote_address); + context->result = NET_NFC_OK; + } else { + DEBUG_ERR_MSG("disconnecting failed, [%d]", result); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_STATE_ERROR; + } + } + + bt_audio_deinitialize(); + _bt_do_pairing(context); + break; + default : + DEBUG_ERR_MSG("bt op failed, [%d][%d]", type, result); + break; + } +} + +void _bt_hid_host_connection_state_changed_cb(int result, bool connected, + const char *remote_address, void *user_data) +{ + net_nfc_handover_bt_process_context_t *context = + (net_nfc_handover_bt_process_context_t *)user_data; + + if(connected == true) + { + if (result == BT_ERROR_NONE) { + INFO_MSG("connected device [%s]", context->remote_address); + + context->result = NET_NFC_OK; + } else { + char name[512]; + + DEBUG_ERR_MSG("connecting failed, [%d]", result); + + __bt_get_name(context->carrier->carrier_record, name, sizeof(name)); + + net_nfc_app_util_show_notification(IDS_SIGNAL_4, name); + + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_STATE_ERROR; + } + } + else + { + if (result == BT_ERROR_NONE) { + INFO_MSG("disconnected device [%s]", context->remote_address); + + context->result = NET_NFC_OK; + } else { + DEBUG_ERR_MSG("disconnecting failed, [%d]", result); + + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_STATE_ERROR; + } + } + + bt_hid_host_deinitialize(); + + _bt_do_pairing(context); +} + +void _bt_state_changed_cb(int result, bt_adapter_state_e adapter_state, + 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 (adapter_state) + { + case BT_ADAPTER_ENABLED : + INFO_MSG("BT_ADAPTER_ENABLED"); + if (context->step == NET_NFC_LLCP_STEP_02) + { + _bt_do_pairing(context); + } + else + { + DEBUG_ERR_MSG("step is incorrect"); + } + break; + + case BT_ADAPTER_DISABLED : + INFO_MSG("BT_ADAPTER_DISABLED"); + if (context->step == NET_NFC_LLCP_STEP_RETURN) + { + _bt_do_pairing(context); + } + else + { + DEBUG_ERR_MSG("step is incorrect"); + } + break; + default : + DEBUG_MSG("unhandled bt event [%d], [%d]", adapter_state, result); + break; + } +} + +void _bt_bond_created_cb(int result, bt_device_info_s *device_info, + 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; + } + + if (result >= BT_ERROR_NONE) { + bt_device_get_service_mask_from_uuid_list(device_info->service_uuid, + device_info->service_count, &(context->service_mask)); + context->result = NET_NFC_OK; + } else { + char name[512]; + + DEBUG_ERR_MSG("bond failed, [%d]", result); + + if(result != BT_ERROR_RESOURCE_BUSY){ + __bt_get_name(context->carrier->carrier_record, name, sizeof(name)); + + net_nfc_app_util_show_notification(IDS_SIGNAL_3, name); + } + + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_STATE_ERROR; + } + + _bt_do_pairing(context); + + LOGD("[%s] END", __func__); +} + +static int _bt_do_pairing(net_nfc_handover_bt_process_context_t *context) +{ + int ret; + bt_adapter_state_e *adapter_state; + + if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY) + { + DEBUG_ERR_MSG("context->result is error [%d]", context->result); + } + + switch (context->step) + { + case NET_NFC_LLCP_STEP_01 : + INFO_MSG("STEP [1]"); + + ret = bt_initialize(); + ret = bt_adapter_set_state_changed_cb(_bt_state_changed_cb, context); + ret = bt_device_set_bond_created_cb(_bt_bond_created_cb, context); + + if (ret >= BT_ERROR_NONE) + { + /* next step */ + context->step = NET_NFC_LLCP_STEP_02; + + ret = bt_adapter_get_state(&adapter_state); + + if (adapter_state != BT_ADAPTER_ENABLED) + { + context->result = NET_NFC_OK; + + ret = bt_adapter_enable(); + if (ret != BT_ERROR_NONE) + { + DEBUG_ERR_MSG("bt adapter enable failed, [%d]", ret); + + context->step = NET_NFC_STATE_ERROR; + context->result = NET_NFC_OPERATION_FAIL; + } + } + else + { + /* do next step */ + INFO_MSG("BT is enabled already, go next step"); + + context->already_on = true; + context->result = NET_NFC_OK; + + g_idle_add((GSourceFunc)_bt_do_pairing, (gpointer)context); + } + } + else + { + DEBUG_ERR_MSG("bt set register_callback failed, [%d]", ret); + + /* bluetooth handover is working already. skip new request */ + context->step = NET_NFC_LLCP_STEP_05; + context->result = NET_NFC_OPERATION_FAIL; + + g_idle_add((GSourceFunc)_bt_do_pairing, + (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_02 : + { + net_nfc_carrier_config_s *config; + data_s temp = { NULL, 0 }; + + INFO_MSG("STEP [2]"); + + net_nfc_util_handover_bt_create_config_from_record( + &config, context->carrier->carrier_record); + + net_nfc_util_get_carrier_config_property(config, + NET_NFC_BT_ATTRIBUTE_ADDRESS, + (uint16_t *)&temp.length, &temp.buffer); + if (temp.length == 6) + { + bt_device_info_s *device_info; + + NET_NFC_REVERSE_ORDER_6_BYTES(temp.buffer); + sprintf(context->remote_address, "%02X:%02X:%02X:%02X:%02X:%02X", + temp.buffer[0], + temp.buffer[1], + temp.buffer[2], + temp.buffer[3], + temp.buffer[4], + temp.buffer[5]); + + context->result = NET_NFC_OK; + + if (bt_adapter_get_bonded_device_info(context->remote_address, &device_info) == BT_ERROR_NONE) + { + INFO_MSG("already paired with [%s]", context->remote_address); + + context->step = NET_NFC_LLCP_STEP_04; + + ret = bt_device_get_service_mask_from_uuid_list(device_info->service_uuid, + device_info->service_count, &(context->service_mask)); +#ifdef DISCONNECT_DEVICE + gboolean connected = FALSE; + bt_device_is_profile_connected(context->remote_address, BT_PROFILE_HSP, &connected); + if (connected) + context->step = NET_NFC_LLCP_STEP_06; + + bt_device_is_profile_connected(context->remote_address, BT_PROFILE_A2DP, &connected); + if (connected) + context->step = NET_NFC_LLCP_STEP_06; + + bt_device_is_profile_connected(context->remote_address, BT_PROFILE_HID, &connected); + if (connected) + context->step = NET_NFC_LLCP_STEP_06; + + INFO_MSG("Check connected=[%d] " , connected ); +#endif + } + else + { + net_nfc_handover_bt_oob_data_t oob = { { 0 } , }; + + if (_bt_get_oob_data_from_config(config, &oob) == NET_NFC_OK) + { + /* set oob data */ + bt_adapter_set_remote_oob_data(context->remote_address, + oob.hash, oob.randomizer, oob.hash_len, oob.randomizer_len); + } + + /* pair and send response */ + context->step = NET_NFC_LLCP_STEP_03; + } + } + else + { + DEBUG_ERR_MSG("bluetooth address is invalid. [%d] bytes", temp.length); + + context->step = NET_NFC_STATE_ERROR; + context->result = NET_NFC_OPERATION_FAIL; + } + + net_nfc_util_free_carrier_config(config); + + g_idle_add((GSourceFunc)_bt_do_pairing, (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_03 : + INFO_MSG("STEP [3]"); + context->step = NET_NFC_LLCP_STEP_04; + + DEBUG_ERR_MSG("bt_device_create_bond : [%s]", context->remote_address); + + ret = bt_device_create_bond(context->remote_address); + if (ret != BT_ERROR_NONE && ret != BT_ERROR_RESOURCE_BUSY) + { + DEBUG_ERR_MSG("bt_device_create_bond failed, [%d]", ret); + + context->step = NET_NFC_STATE_ERROR; + context->result = NET_NFC_OPERATION_FAIL; + + g_idle_add((GSourceFunc)_bt_do_pairing, + (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_04 : + INFO_MSG("STEP [4]"); + + context->step = NET_NFC_LLCP_STEP_RETURN; + + if ((context->service_mask & BT_SC_HSP_SERVICE_MASK) && + (context->service_mask & BT_SC_A2DP_SERVICE_MASK)) + { + + bt_audio_initialize(); + bt_audio_set_connection_state_changed_cb(_bt_audio_connection_state_changed_cb, context); + bt_audio_connect(context->remote_address, BT_AUDIO_PROFILE_TYPE_ALL); + + } else if (context->service_mask & BT_SC_A2DP_SERVICE_MASK) { + + bt_audio_initialize(); + bt_audio_set_connection_state_changed_cb(_bt_audio_connection_state_changed_cb, context); + bt_audio_connect(context->remote_address, BT_AUDIO_PROFILE_TYPE_A2DP); + + } else if (context->service_mask & BT_SC_HSP_SERVICE_MASK) { + + bt_audio_initialize(); + bt_audio_set_connection_state_changed_cb(_bt_audio_connection_state_changed_cb, context); + bt_audio_connect(context->remote_address, BT_AUDIO_PROFILE_TYPE_HSP_HFP); + + } else if (context->service_mask & BT_SC_HID_SERVICE_MASK) { + bt_hid_host_initialize(_bt_hid_host_connection_state_changed_cb, context); + bt_hid_host_connect(context->remote_address); + + } else { + g_idle_add((GSourceFunc)_bt_do_pairing, (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_05 : + INFO_MSG("STEP [5]"); + + /* bluetooth handover is working already. skip new request */ + context->cb(context->result, + NET_NFC_CONN_HANDOVER_CARRIER_BT, + NULL, context->user_param); + + /* release context */ + if (context->carrier != NULL) + { + net_nfc_util_free_handover_carrier(context->carrier); + } + + net_nfc_util_clear_data(&context->data); + _net_nfc_util_free_mem(context); + break; +#ifdef DISCONNECT_DEVICE + case NET_NFC_LLCP_STEP_06 : + INFO_MSG("STEP [6]"); + + context->step = NET_NFC_LLCP_STEP_RETURN; + + + if ((context->service_mask & BT_SC_HSP_SERVICE_MASK) && + (context->service_mask & BT_SC_A2DP_SERVICE_MASK)) + { + + bt_audio_initialize(); + bt_audio_set_connection_state_changed_cb(_bt_audio_connection_state_changed_cb, context); + bt_audio_disconnect(context->remote_address, BT_AUDIO_PROFILE_TYPE_ALL); + + } else if (context->service_mask & BT_SC_A2DP_SERVICE_MASK) { + + bt_audio_initialize(); + bt_audio_set_connection_state_changed_cb(_bt_audio_connection_state_changed_cb, context); + bt_audio_disconnect(context->remote_address, BT_AUDIO_PROFILE_TYPE_A2DP); + + } else if (context->service_mask & BT_SC_HSP_SERVICE_MASK) { + + bt_audio_initialize(); + bt_audio_set_connection_state_changed_cb(_bt_audio_connection_state_changed_cb, context); + bt_audio_disconnect(context->remote_address, BT_AUDIO_PROFILE_TYPE_HSP_HFP); + + } else if (context->service_mask & BT_SC_HID_SERVICE_MASK) { + bt_hid_host_initialize(_bt_hid_host_connection_state_changed_cb, context); + bt_hid_host_disconnect(context->remote_address); + + } else { + g_idle_add((GSourceFunc)_bt_do_pairing, (gpointer)context); + } + break; +#endif + case NET_NFC_STATE_ERROR : + context->step = NET_NFC_LLCP_STEP_RETURN; + if (context->already_on == false) + { + bt_adapter_disable(); + } + else + { + g_idle_add((GSourceFunc)_bt_do_pairing, (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_RETURN : + { + data_s temp = { context->remote_address, sizeof(context->remote_address) }; + data_s *data = NULL; + + INFO_MSG("STEP return"); + + bt_deinitialize(); + + if (context->result == NET_NFC_OK) + { + data = &temp; + } + + context->cb(context->result, + NET_NFC_CONN_HANDOVER_CARRIER_BT, + data, context->user_param); + + /* release context */ + if (context->carrier != NULL) + { + net_nfc_util_free_handover_carrier( + context->carrier); + } + + net_nfc_util_clear_data(&context->data); + _net_nfc_util_free_mem(context); + } + break; + + default : + break; + } + + return 0; +} + +net_nfc_error_e net_nfc_server_handover_bt_do_pairing( + net_nfc_ch_carrier_s *carrier, + net_nfc_server_handover_process_carrier_cb cb, + void *user_param) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_handover_bt_process_context_t *context = NULL; + + INFO_MSG("Call this function for bt pairing."); + + _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_duplicate_handover_carrier(&context->carrier, carrier); + g_idle_add((GSourceFunc)_bt_do_pairing, (gpointer)context); + + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} diff --git a/src/manager/net_nfc_server_handover_wps.c b/src/manager/net_nfc_server_handover_wps.c new file mode 100755 index 0000000..e8597e8 --- /dev/null +++ b/src/manager/net_nfc_server_handover_wps.c @@ -0,0 +1,498 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "wifi.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_handover.h" +#include "net_nfc_server_handover_internal.h" +#include "net_nfc_server_llcp.h" + + +typedef struct _wps_process_context_t +{ + net_nfc_error_e result; + net_nfc_carrier_config_s *config; + net_nfc_server_handover_process_carrier_cb cb; + void *user_param; +} +wps_process_context_t; + +static char *_wps_get_string_property(net_nfc_carrier_config_s *config, + uint16_t attr) +{ + char *result = NULL; + uint16_t len = 0; + uint8_t *buffer = NULL; + net_nfc_error_e ret; + + ret = net_nfc_util_get_carrier_config_property(config, + attr, &len, &buffer); + if (ret == NET_NFC_OK) { + result = g_strndup((char *)buffer, len); + } + + return result; +} + +static uint16_t _wps_get_short_property(net_nfc_carrier_config_s *config, + uint16_t attr) +{ + uint16_t result = 0; + uint16_t len = 0; + uint8_t *buffer = NULL; + net_nfc_error_e ret; + + ret = net_nfc_util_get_carrier_config_property(config, + attr, &len, &buffer); + if (ret == NET_NFC_OK) { + result = htons(*(uint16_t *)buffer); + } + + return result; +} + +static char *_wps_get_mac_address(net_nfc_carrier_config_s *config) +{ + char *result = NULL; + uint16_t len = 0; + uint8_t *buffer = NULL; + net_nfc_error_e ret; + + ret = net_nfc_util_get_carrier_config_property(config, + NET_NFC_WIFI_ATTRIBUTE_MAC_ADDR, &len, &buffer); + if (ret == NET_NFC_OK) { + char temp[50]; + + snprintf(temp, sizeof(temp), "%02X:%02X:%02X:%02X:%02X:%02X", + buffer[0], buffer[1], buffer[2], + buffer[3], buffer[4], buffer[5]); + + result = g_strdup(temp); + } + + return result; +} + +static wifi_security_type_e _wps_get_security_type( + net_nfc_carrier_config_s *config) +{ + wifi_security_type_e result; + uint16_t ret; + + ret = _wps_get_short_property(config, + NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE); + + switch (ret) { + case 1 : /* open */ + result = WIFI_SECURITY_TYPE_NONE; + break; + + case 2 : /* WPA-Personal */ + result = WIFI_SECURITY_TYPE_WPA_PSK; + break; + + case 4 : /* Shared */ + result = WIFI_SECURITY_TYPE_WEP; + break; + + case 8 : /* WPA-Enterprise */ + result = WIFI_SECURITY_TYPE_EAP; + break; + + case 16 : /* WPA2-Enterprise */ + result = WIFI_SECURITY_TYPE_EAP; + break; + + case 32 : /* WPA2-Personal */ + result = WIFI_SECURITY_TYPE_WPA2_PSK; + break; + + default : + result = WIFI_SECURITY_TYPE_NONE; + break; + } + + return result; +} + +static wifi_encryption_type_e _wps_get_encryption_type( + net_nfc_carrier_config_s *config) +{ + wifi_encryption_type_e result; + uint16_t ret; + + ret = _wps_get_short_property(config, + NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE); + + switch (ret) { + case 1 : /* None */ + result = WIFI_ENCRYPTION_TYPE_NONE; + break; + + case 2 : /* WEP */ + result = WIFI_ENCRYPTION_TYPE_WEP; + break; + + case 4 : /* TKIP */ + result = WIFI_ENCRYPTION_TYPE_TKIP; + break; + + case 8 : /* AES */ + result = WIFI_ENCRYPTION_TYPE_AES; + break; + + case 12 : /* AES/TKIP */ + result = WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED; + break; + + default : + result = WIFI_SECURITY_TYPE_NONE; + break; + } + + return result; +} + +net_nfc_error_e net_nfc_server_handover_wps_get_selector_carrier( + net_nfc_server_handover_get_carrier_cb cb, + void *user_param) +{ + net_nfc_error_e result = NET_NFC_NOT_SUPPORTED; + + /* generating selector record is not supported */ + + if (cb != NULL) { + cb(NET_NFC_NOT_SUPPORTED, NULL, user_param); + } + + return result; +} + +net_nfc_error_e net_nfc_server_handover_wps_get_requester_carrier( + net_nfc_server_handover_get_carrier_cb cb, + void *user_param) +{ + net_nfc_error_e result; + net_nfc_ch_carrier_s *carrier = NULL; + ndef_record_s *record = NULL; + data_s type = { (uint8_t *)CH_CAR_RECORD_TYPE, CH_CAR_RECORD_TYPE_LEN }; + uint8_t buffer[sizeof(ch_hc_record_t) + CH_WIFI_WPS_MIME_LEN]; + data_s payload = { buffer, sizeof(buffer) }; + ch_hc_record_t *hc_buffer = (ch_hc_record_t *)buffer; + + hc_buffer->ctf = NET_NFC_RECORD_MIME_TYPE; + hc_buffer->type_len = CH_WIFI_WPS_MIME_LEN; + memcpy(hc_buffer->type, CH_WIFI_WPS_MIME, CH_WIFI_WPS_MIME_LEN); + + result = net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, + &type, NULL, &payload, &record); + + result = net_nfc_util_create_handover_carrier(&carrier, + NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE); + + result = net_nfc_util_append_handover_carrier_record(carrier, record); + + if (cb != NULL) { + cb(result, carrier, user_param); + } + + net_nfc_util_free_handover_carrier(carrier); + + net_nfc_util_free_record(record); + + return result; +} + +static bool _wifi_found_ap_cb(wifi_ap_h ap, void *user_data) +{ + gpointer *context = (gpointer *)user_data; + bool result; + char *ssid = NULL; + int ret; + + ret = wifi_ap_get_essid(ap, &ssid); + if (ret == WIFI_ERROR_NONE && ssid != NULL) { + DEBUG_MSG("ssid [%s]", ssid); + + if (g_strcmp0(ssid, (char *)context[0]) == 0) { + DEBUG_MSG("found!! ssid [%s]", ssid); + + context[1] = ap; + + result = false; + } else { + result = true; + } + + g_free(ssid); + } else { + DEBUG_ERR_MSG("wifi_ap_get_bssid failed, [%d]", ret); + + result = true; + } + + return result; +} + +static wifi_ap_h _wifi_search_ap(const char *ssid) +{ + gpointer context[2]; + + context[0] = (gpointer)ssid; + context[1] = NULL; + + wifi_foreach_found_aps(_wifi_found_ap_cb, &context); + + return (wifi_ap_h)context[1]; +} + +static bool _wifi_is_connected(wifi_ap_h ap) +{ + bool result; + wifi_connection_state_e state = WIFI_CONNECTION_STATE_DISCONNECTED; + int ret; + + ret = wifi_ap_get_connection_state(ap, &state); + if (ret == WIFI_ERROR_NONE) { + if (state == WIFI_CONNECTION_STATE_DISCONNECTED) + result = false; + else + result = true; + } else { + result = false; + } + + return result; +} + +static void _wps_finish_do_connect(int result, wps_process_context_t *context) +{ + if (context != NULL) { + if (context->cb != NULL) { + data_s *data = NULL; + data_s temp; + + if (result == NET_NFC_OK) { + char *mac; + + mac = _wps_get_mac_address(context->config); + if (mac != NULL) { + temp.buffer = (uint8_t *)mac; + temp.length = strlen(mac); + + data = &temp; + } + } + + context->cb(result, + NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS, + data, + context->user_param); + + if (data != NULL) { + net_nfc_util_clear_data(data); + } + } + + if (context->config != NULL) { + net_nfc_util_free_carrier_config(context->config); + } + + _net_nfc_util_free_mem(context); + } +} + +static void _wifi_connected_cb(wifi_error_e result, void *user_data) +{ + DEBUG_MSG("wifi_connect result [%d]", result); + + _wps_finish_do_connect(result, user_data); +} + +static int __connect(wifi_ap_h ap, wps_process_context_t *context) +{ + int result; + char *net_key; + + wifi_ap_set_security_type(ap, _wps_get_security_type(context->config)); + wifi_ap_set_encryption_type(ap, _wps_get_encryption_type(context->config)); + + net_key = _wps_get_string_property(context->config, + NET_NFC_WIFI_ATTRIBUTE_NET_KEY); + wifi_ap_set_passphrase(ap, net_key); + g_free(net_key); + + result = wifi_connect(ap, _wifi_connected_cb, context); + + return result; +} + +static void _connect(wps_process_context_t *context) +{ + wifi_ap_h ap = NULL; + int result; + char *ssid; + + ssid = _wps_get_string_property(context->config, + NET_NFC_WIFI_ATTRIBUTE_SSID); + if (ssid != NULL) { + ap = _wifi_search_ap(ssid); + if (ap == NULL) { + DEBUG_MSG("no ap found"); + + result = wifi_ap_create(ssid, &ap); + if (result == WIFI_ERROR_NONE) { + result = __connect(ap, context); + if (result != WIFI_ERROR_NONE) { + DEBUG_ERR_MSG("__connect failed, [%d]", result); + + wifi_ap_destroy(ap); + + _wps_finish_do_connect(result, context); + } + } else { + DEBUG_ERR_MSG("wifi_ap_create failed, [%d]", result); + + _wps_finish_do_connect(result, context); + } + } else if (_wifi_is_connected(ap) == false) { + DEBUG_MSG("found ap, but not connected"); + + result = __connect(ap, context); + if (result != WIFI_ERROR_NONE) { + DEBUG_ERR_MSG("wifi_connect failed, [%d]", result); + + _wps_finish_do_connect(result, context); + } + } else { + DEBUG_ERR_MSG("ap exists"); + + _wps_finish_do_connect(WIFI_ERROR_ALREADY_EXISTS, context); + } + + g_free(ssid); + } else { + DEBUG_ERR_MSG("_wps_get_string_property failed"); + + _wps_finish_do_connect(NET_NFC_ALLOC_FAIL, context); + } +} + +/* activation */ +static void _wifi_scan_finished_cb(wifi_error_e result, void *user_data) +{ + DEBUG_MSG("_wifi_scan_finished_cb"); + + if (result == WIFI_ERROR_NONE) { + _connect(user_data); + } else { + DEBUG_ERR_MSG("_wifi_scan_finished_cb failed, [%d]", result); + + _wps_finish_do_connect(result, user_data); + } +} + +static void _wifi_activated_cb(wifi_error_e result, void *user_data) +{ + DEBUG_MSG("_wifi_activated_cb"); + + if (result == WIFI_ERROR_NONE) { + int ret; + + ret = wifi_scan(_wifi_scan_finished_cb, user_data); + if (ret != WIFI_ERROR_NONE) { + DEBUG_ERR_MSG("wifi_scan failed, [%d]", ret); + } + } else { + DEBUG_ERR_MSG("wifi_activate failed, [%d]", result); + + _wps_finish_do_connect(result, user_data); + } +} + +static int _wifi_activate(wps_process_context_t *context) +{ + int result; + + result = wifi_initialize(); + if (result == WIFI_ERROR_NONE) { + bool activated = false; + + result = wifi_is_activated(&activated); + if (result == WIFI_ERROR_NONE) { + if (activated == false) { + DEBUG_MSG("wifi is off, try to activate"); + /* activate */ + result = wifi_activate(_wifi_activated_cb, context); + if (result != WIFI_ERROR_NONE) { + DEBUG_ERR_MSG("wifi_activate failed, [%d]", result); + } + } else { + _connect(context); + + result = WIFI_ERROR_NONE; + } + } else { + DEBUG_ERR_MSG("wifi_is_activated failed, [%d]", result); + } + } else { + DEBUG_ERR_MSG("wifi_initialize failed, [%d]", result); + } + + return result; +} + +net_nfc_error_e net_nfc_server_handover_wps_do_connect( + net_nfc_ch_carrier_s *carrier, + net_nfc_server_handover_process_carrier_cb cb, + void *user_param) +{ + net_nfc_error_e result; + wps_process_context_t *context = NULL; + + _net_nfc_util_alloc_mem(context, sizeof(*context)); + if (context != NULL) { + context->cb = cb; + context->user_param = user_param; + + result = net_nfc_util_create_carrier_config_from_config_record( + &context->config, carrier->carrier_record); + if (result == NET_NFC_OK) { + result = _wifi_activate(context); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("_wifi_activate failed, [%d]", result); + + net_nfc_util_free_carrier_config(context->config); + _net_nfc_util_free_mem(context); + } + } else { + DEBUG_ERR_MSG("net_nfc_util_create_carrier_config_from_config_record failed, [%d]", result); + + _net_nfc_util_free_mem(context); + } + } else { + DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed"); + + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} diff --git a/src/manager/net_nfc_server_hce.c b/src/manager/net_nfc_server_hce.c new file mode 100755 index 0000000..9a67911 --- /dev/null +++ b/src/manager/net_nfc_server_hce.c @@ -0,0 +1,1016 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_server.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_util_hce.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_manager.h" +#include "net_nfc_server_route_table.h" +#include "net_nfc_app_util_internal.h" +#include "net_nfc_server_hce.h" + +/*TODO : */ +#include "net_nfc_app_util_internal.h" + +#define OPERATION_APDU_RECEIVED "http://tizen.org/appcontrol/operation/nfc/card_emulation/apdu_received" +#define OPERATION_TRANSACTION_RECEIVED "http://tizen.org/appcontrol/operation/nfc/card_emulation/transaction_received" + +static NetNfcGDbusHce *hce_skeleton = NULL; +/*Routing Table base on AID*/ +static GHashTable *routing_table_aid; +static char *selected_aid; + +//static uint8_t android_hce_aid_buffer[] = { 0xA0, 0x00, 0x00, 0x04, 0x76, 0x41, 0x6E, 0x64, 0x72, 0x6F, 0x69, 0x64, 0x48, 0x43, 0x45 }; +//static data_s android_hce_aid = { android_hce_aid_buffer, sizeof(android_hce_aid_buffer) }; + +typedef struct _hce_listener_t +{ + char *id; + char *package; + net_nfc_server_hce_listener_cb listener; + net_nfc_server_hce_user_data_destroy_cb destroy_cb; + void *user_data; +} +hce_listener_t; + +/* server_side */ +typedef struct _SeDataHandle SeDataHandle; + +struct _SeDataHandle +{ + NetNfcGDbusHce *object; + GDBusMethodInvocation *invocation; + net_nfc_target_handle_s* handle; +}; + +typedef struct _ServerHceData ServerHceData; + +struct _ServerHceData +{ + net_nfc_target_handle_s *handle; + guint event; + data_s apdu; +}; + +typedef struct _HceDataApdu HceDataApdu; + +struct _HceDataApdu +{ + NetNfcGDbusHce *object; + GDBusMethodInvocation *invocation; + net_nfc_target_handle_s *handle; + GVariant *data; +}; + +typedef struct _hce_client_context_s +{ + GDBusConnection *connection; + char *id; +} +hce_client_context_s; + +typedef bool (*route_table_iter_cb)(hce_listener_t *data, void *user_data); + + +static void __on_key_destroy(gpointer data) +{ + if (data != NULL) { + g_free(data); + } +} + +static void __on_value_destroy(gpointer data) +{ + hce_listener_t *listener = (hce_listener_t *)data; + + if (data != NULL) { + if (listener->id != NULL) { + g_free(listener->id); + } + if (listener->package != NULL) { + g_free(listener->package); + } + + g_free(data); + } +} + +static void _routing_table_init() +{ + if (routing_table_aid == NULL) + routing_table_aid = g_hash_table_new_full(g_str_hash, + g_str_equal, __on_key_destroy, __on_value_destroy); +} + +inline static hce_listener_t *_routing_table_find_aid(const char *package) +{ + return (hce_listener_t *)g_hash_table_lookup(routing_table_aid, + (gconstpointer)package); +} + +static net_nfc_error_e _routing_table_add(const char *package, const char *id, + net_nfc_server_hce_listener_cb listener, + net_nfc_server_hce_user_data_destroy_cb destroy_cb, void *user_data) +{ + net_nfc_error_e result; + + if (_routing_table_find_aid(package) == NULL) { + hce_listener_t *data; + DEBUG_SERVER_MSG("new hce package, [%s]", package); + + data = g_new0(hce_listener_t, 1); + + data->package = g_strdup(package); + if (id != NULL) { + data->id = g_strdup(id); + } + data->listener = listener; + data->destroy_cb = destroy_cb; + data->user_data = user_data; + + g_hash_table_insert(routing_table_aid, + (gpointer)g_strdup(package), (gpointer)data); + + result = NET_NFC_OK; + } else { + DEBUG_ERR_MSG("already registered"); + + result = NET_NFC_ALREADY_REGISTERED; + } + + return result; +} + +static void _routing_table_del(const char *package) +{ + hce_listener_t *data; + + data = _routing_table_find_aid(package); + if (data != NULL) { + DEBUG_SERVER_MSG("remove hce package, [%s]", package); + + if (data->destroy_cb != NULL) { + data->destroy_cb(data->user_data); + } + + g_hash_table_remove(routing_table_aid, package); + } +} + +static void _routing_table_iterate(route_table_iter_cb cb, void *user_data) +{ + GHashTableIter iter; + gpointer key; + hce_listener_t *data; + + if (routing_table_aid == NULL) + return; + + g_hash_table_iter_init (&iter, routing_table_aid); + + while (g_hash_table_iter_next (&iter, &key, (gpointer)&data)) { + if (cb(data, user_data) == false) { + break; + } + } +} + +static bool _del_by_id_cb(hce_listener_t *data, void *user_data) +{ + const char *id = user_data; + bool result; + + if (data->id == NULL) { + if (id == NULL) { + DEBUG_MSG("remove context for nfc-manager"); + + result = false; + } else { + result = true; + } + } else { + if (id != NULL && g_ascii_strcasecmp(data->id, id) == 0) { + DEBUG_MSG("deleting package [%s:%s]", data->id, data->package); + + _routing_table_del(data->package); + + result = false; + } else { + result = true; + } + } + + return result; +} + +static void _routing_table_del_by_id(const char *id) +{ + _routing_table_iterate(_del_by_id_cb, (char *)id); +} + +//////////////////////////////////////////////////////////////////////////////// +net_nfc_error_e net_nfc_server_hce_start_hce_handler(const char *package, + const char *id, net_nfc_server_hce_listener_cb listener, + net_nfc_server_hce_user_data_destroy_cb destroy_cb, void *user_data) +{ + net_nfc_error_e result; + + if (package == NULL || listener == NULL) { + return NET_NFC_NULL_PARAMETER; + } + + result = _routing_table_add(package, id, listener, + destroy_cb, user_data); + if (result == NET_NFC_OK) { + result = net_nfc_server_route_table_add_handler(id, package); + } + + return result; +} + +net_nfc_error_e net_nfc_server_hce_stop_hce_handler(const char *package) +{ + if (package == NULL || strlen(package) == 0) { + return NET_NFC_NULL_PARAMETER; + } + + _routing_table_del(package); + + net_nfc_server_route_table_del_handler(NULL, package, false); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_server_hce_stop_hce_handler_by_id(const char *id) +{ + if (id == NULL || strlen(id) == 0) { + return NET_NFC_NULL_PARAMETER; + } + + _routing_table_del_by_id(id); + + net_nfc_server_route_table_del_handler_by_id(id); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_server_hce_send_apdu_response( + net_nfc_target_handle_s *handle, data_s *response) +{ + net_nfc_error_e result = NET_NFC_OK; + + if (response == NULL || response->buffer == NULL || + response->length == 0) { + return NET_NFC_NULL_PARAMETER; + } + + if (net_nfc_controller_hce_response_apdu( + handle, response, &result) == true) { + } else { + DEBUG_ERR_MSG("net_nfc_controller_hce_response_apdu failed, [%d]", result); + } + + return result; +} + +//////////////////////////////////////////////////////////////////////////////// + +static void _emit_event_received_signal(GDBusConnection *connection, + const char *id, int event, + net_nfc_target_handle_h handle, + data_s *data) +{ + GVariant *arg_data; + GError *error = NULL; + + arg_data = net_nfc_util_gdbus_data_to_variant(data); + + if (g_dbus_connection_emit_signal( + connection, + id, + "/org/tizen/NetNfcService/Hce", + "org.tizen.NetNfcService.Hce", + "EventReceived", + g_variant_new("(uu@a(y))", + GPOINTER_TO_UINT(handle), + event, + arg_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"); + } + } +} + +static void _hce_default_listener_cb(net_nfc_target_handle_s *handle, + int event, data_s *data, void *user_data) +{ + hce_client_context_s *context = (hce_client_context_s *)user_data; + + if (context == NULL) { + return; + } + + switch (event) { + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA : + if (context->id != NULL) { + /* app is running */ + _emit_event_received_signal(context->connection, + context->id, event, handle, data); + + } else { + /* launch app */ + DEBUG_SERVER_MSG("launch apdu app!!"); + } + break; + + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED : + case NET_NFC_MESSAGE_ROUTING_HOST_EMU_DEACTIVATED : + DEBUG_SERVER_MSG("HCE %s", event == NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED ? "ACTIVATE" : "DEACTIVATE"); + + if (context->id != NULL) { + /* app is running */ + _emit_event_received_signal(context->connection, + context->id, event, handle, data); + } + break; + + default : + break; + } +} + +static void _hce_user_data_destroy_cb(void *user_data) +{ + hce_client_context_s *context = user_data; + + if (context != NULL) { + g_object_unref(context->connection); + if (context->id != NULL) { + g_free(context->id); + } + + g_free(context); + } +} + +static void hce_start_hce_handler_thread_func(gpointer user_data) +{ + HceDataApdu *data = (HceDataApdu *)user_data; + net_nfc_error_e result; + const char *id; + char package[1024]; + pid_t pid; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + INFO_MSG(">>> hce_start_hce_handler_thread_func!!"); + + id = g_dbus_method_invocation_get_sender(data->invocation); + + pid = net_nfc_server_gdbus_get_pid(id); + + if (net_nfc_util_get_pkgid_by_pid(pid, package, sizeof(package)) == true) { + hce_client_context_s *context; + GDBusConnection *connection; + + connection = g_dbus_method_invocation_get_connection(data->invocation); + + context = g_new0(hce_client_context_s, 1); + context->connection = g_object_ref(connection); + context->id = g_strdup(id); + + result = net_nfc_server_hce_start_hce_handler(package, id, + _hce_default_listener_cb, _hce_user_data_destroy_cb, + context); + } else { + DEBUG_ERR_MSG("net_nfc_util_get_pkgid_by_pid failed, pid [%d]", pid); + + result = NET_NFC_OPERATION_FAIL; + } + + net_nfc_gdbus_hce_complete_start_hce_handler(data->object, + data->invocation, result); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + + +static gboolean hce_handle_start_hce_handler( + NetNfcGDbusHce *object, + GDBusMethodInvocation *invocation, + GVariant *smack_privilege) +{ + HceDataApdu *data = NULL; + gint result; + + INFO_MSG(">>> REQUEST from [%s]", + g_dbus_method_invocation_get_sender(invocation)); + + if (net_nfc_server_gdbus_check_privilege(invocation, + smack_privilege, + "nfc-manager", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(HceDataApdu, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + + if (net_nfc_server_controller_async_queue_push_force( + hce_start_hce_handler_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_hce_complete_start_hce_handler(object, invocation, + result); + + return TRUE; +} + +static void hce_stop_hce_handler_thread_func(gpointer user_data) +{ + HceDataApdu *data = (HceDataApdu *)user_data; + net_nfc_error_e result; + const char *id; + char package[1024]; + pid_t pid; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + INFO_MSG(">>> hce_stop_hce_handler_thread_func!!"); + + id = g_dbus_method_invocation_get_sender(data->invocation); + + pid = net_nfc_server_gdbus_get_pid(id); + + if (net_nfc_util_get_pkgid_by_pid(pid, package, sizeof(package)) == true) { + result = net_nfc_server_hce_stop_hce_handler(package); + } else { + DEBUG_ERR_MSG("net_nfc_util_get_pkgid_by_pid failed, pid [%d]", pid); + + result = NET_NFC_OPERATION_FAIL; + } + + net_nfc_gdbus_hce_complete_stop_hce_handler(data->object, + data->invocation, result); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + + +static gboolean hce_handle_stop_hce_handler( + NetNfcGDbusHce *object, + GDBusMethodInvocation *invocation, + GVariant *smack_privilege) +{ + HceDataApdu *data = NULL; + gint result; + + INFO_MSG(">>> REQUEST from [%s]", + g_dbus_method_invocation_get_sender(invocation)); + + if (net_nfc_server_gdbus_check_privilege(invocation, + smack_privilege, + "nfc-manager", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(HceDataApdu, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + + if (net_nfc_server_controller_async_queue_push_force( + hce_stop_hce_handler_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_hce_complete_stop_hce_handler(object, invocation, + result); + + return TRUE; +} + + +static void hce_response_apdu_thread_func(gpointer user_data) +{ + HceDataApdu *detail = (HceDataApdu *)user_data; + data_s apdu_data = { NULL, 0 }; + net_nfc_error_e result = NET_NFC_OK; + + g_assert(detail != NULL); + g_assert(detail->object != NULL); + g_assert(detail->invocation != NULL); + + INFO_MSG(">>> hce_response_apdu_thread_func!!"); + + net_nfc_util_gdbus_variant_to_data_s(detail->data, &apdu_data); + + result = net_nfc_server_hce_send_apdu_response(detail->handle, + &apdu_data); + + net_nfc_gdbus_hce_complete_response_apdu( + detail->object, + detail->invocation, + result); + + net_nfc_util_clear_data(&apdu_data); + + g_variant_unref(detail->data); + + g_object_unref(detail->invocation); + g_object_unref(detail->object); + + g_free(detail); +} + + +static gboolean hce_handle_response_apdu( + NetNfcGDbusHce *object, + GDBusMethodInvocation *invocation, + guint arg_handle, + GVariant *apdudata, + GVariant *smack_privilege) +{ + HceDataApdu *data = NULL; + gint result; + + INFO_MSG(">>> REQUEST from [%s]", + g_dbus_method_invocation_get_sender(invocation)); + + if (net_nfc_server_gdbus_check_privilege(invocation, + smack_privilege, + "nfc-manager", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(HceDataApdu, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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); + + if (net_nfc_server_controller_async_queue_push_force( + hce_response_apdu_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_variant_unref(data->data); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_hce_complete_response_apdu(object, invocation, + result); + + return TRUE; +} + + +typedef struct _apdu_header_t +{ + uint8_t cla; + uint8_t ins; + uint8_t p1; + uint8_t p2; + uint8_t data[0]; +} +__attribute__((packed)) apdu_header_t; + +static bool __extract_parameter(apdu_header_t *apdu, size_t len, uint16_t *lc, + uint16_t *le, uint8_t **data) +{ + size_t l = sizeof(*apdu); + bool result; + + *lc = -1; + *le = -1; + *data = NULL; + + DEBUG_SERVER_MSG("[%02X][%02X][%02X][%02X]", apdu->cla, apdu->ins, apdu->p1, apdu->p2); + + if (len > l) { + if (len == l + 1) { + *le = apdu->data[0]; + + result = true; + } else if (apdu->data[0] > 0) { + l += apdu->data[0] + 1; + + if (l == len || l + 1 == len) { + *lc = apdu->data[0]; + *data = apdu->data + 1; + + if (l + 1 == len) { + *le = apdu->data[*lc + 1]; + } + + result = true; + } else { + DEBUG_ERR_MSG("l == len || l + 1 == len, [%d/%d]", len, l); + + result = false; + } + } else { + DEBUG_ERR_MSG("apdu->data[0] == %d", apdu->data[0]); + + result = false; + } + } else if (len == l) { + result = true; + } else { + DEBUG_ERR_MSG("len > l, [%d/%d]", len, l); + + result = false; + } + + return result; +} + +static bool _route_table_iter_cb(hce_listener_t *data, void *user_data) +{ + ServerHceData *detail = (ServerHceData *)user_data; + + if (data != NULL && data->listener != NULL) { + data->listener(detail->handle, detail->event, NULL, + data->user_data); + } + + return true; +} + +static bool __pre_process_apdu(net_nfc_target_handle_s *handle, data_s *cmd) +{ + apdu_header_t *apdu = (apdu_header_t *)cmd->buffer; + uint16_t lc, le; + uint8_t *data; + bool result; + + if (__extract_parameter(apdu, cmd->length, &lc, &le, &data) == true) { + switch (apdu->ins) { + case 0x70 : + DEBUG_ERR_MSG("not supported, [%d]", cmd->length); + + /* send response */ + uint8_t temp[] = { 0x69, 0x00 }; + data_s resp = { temp, sizeof(temp) }; + + net_nfc_server_hce_send_apdu_response(handle, &resp); + + result = true; /* completed... skip passing to clients */ + break; + + case NET_NFC_HCE_INS_SELECT : + if (apdu->p1 == NET_NFC_HCE_P1_SELECT_BY_NAME) { + if (lc > 2) { + char aid[1024]; + route_table_handler_t *listener; + data_s temp = { data, lc }; + + net_nfc_util_binary_to_hex_string(&temp, aid, sizeof(aid)); + + listener = net_nfc_server_route_table_find_handler_by_aid(aid); + if (listener != NULL) { + g_free(selected_aid); + selected_aid = g_strdup(aid); + } else { + DEBUG_ERR_MSG("file not found, [%s]", aid); + + /* send response */ + uint8_t temp[] = { 0x6A, 0x82 }; + data_s resp = { temp, sizeof(temp) }; + + net_nfc_server_hce_send_apdu_response(handle, &resp); + + result = true; /* completed... skip passing to clients */ + break; + } + } else { + DEBUG_ERR_MSG("wrong aid length, [%d]", cmd->length); + + /* send response */ + uint8_t temp[] = { 0x6B, 0x00 }; + data_s resp = { temp, sizeof(temp) }; + + net_nfc_server_hce_send_apdu_response(handle, &resp); + + result = true; /* completed... skip passing to clients */ + break; + } + } + /* no break */ + default : + result = false; /* need to pass to client */ + break; + } + } else { + DEBUG_ERR_MSG("wrong apdu length, [%d]", cmd->length); + + /* send response */ + uint8_t temp[] = { 0x67, 0x00 }; + data_s resp = { temp, sizeof(temp) }; + + net_nfc_server_hce_send_apdu_response(handle, &resp); + + result = true; /* completed... skip passing to clients */ + } + + return result; +} + +static void hce_apdu_thread_func(gpointer user_data) +{ + ServerHceData *data = (ServerHceData *)user_data; + + g_assert(data != NULL); + + if (data->event == NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA) { + INFO_MSG("[HCE] Command arrived, handle [0x%x], len [%d]", (int)data->handle, data->apdu.length); + + if (__pre_process_apdu(data->handle, + &data->apdu) == false) { + /* finished */ + if (selected_aid != NULL) { + route_table_handler_t *handler; + + handler = net_nfc_server_route_table_find_handler_by_aid(selected_aid); + if (handler != NULL) { + hce_listener_t *listener; + + listener = _routing_table_find_aid(handler->package); + if(listener != NULL) + { + listener->listener(data->handle, + data->event, &data->apdu, + listener->user_data); + } + } else { + uint8_t temp[] = { 0x69, 0x00 }; + data_s resp = { temp, sizeof(temp) }; + + DEBUG_ERR_MSG("?????"); + + net_nfc_server_hce_send_apdu_response(data->handle, &resp); + } + } else { + uint8_t temp[] = { 0x69, 0x00 }; + data_s resp = { temp, sizeof(temp) }; + + DEBUG_ERR_MSG("no aid selected"); + + net_nfc_server_hce_send_apdu_response(data->handle, &resp); + } + } else { + DEBUG_SERVER_MSG("pre-processed data"); + } + } else { + INFO_MSG("[HCE] %s!!!!, handle [0x%x]", data->event == NET_NFC_MESSAGE_ROUTING_HOST_EMU_ACTIVATED ? "Activated" : "Deactivated", (int)data->handle); + + _routing_table_iterate(_route_table_iter_cb, data); + + g_free(selected_aid); + selected_aid = NULL; + } + + net_nfc_util_clear_data(&data->apdu); + + g_free(data); +} + +void net_nfc_server_hce_apdu_received(void *hce_event) +{ + net_nfc_request_hce_apdu_t *hce_apdu = + (net_nfc_request_hce_apdu_t *)hce_event; + net_nfc_target_handle_s *handle; + ServerHceData *data; + + handle = (net_nfc_target_handle_s *)hce_apdu->user_param; + + data = g_try_new0(ServerHceData, 1); + if (data != NULL) { + + data->event = hce_apdu->request_type; + data->handle = handle; + + if (data->event == NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA && + hce_apdu->apdu.buffer != NULL && + hce_apdu->apdu.length > 0) + { + /* APDU from CLF*/ + if (net_nfc_util_init_data(&data->apdu, + hce_apdu->apdu.length) == true) { + memcpy(data->apdu.buffer, hce_apdu->apdu.buffer, + hce_apdu->apdu.length); + } + } + + if (net_nfc_server_controller_async_queue_push_force( + hce_apdu_thread_func, data) == FALSE) { + DEBUG_ERR_MSG("can not push to controller thread"); + + net_nfc_util_clear_data(&data->apdu); + + g_free(data); + + if (hce_apdu->request_type == + NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA) { + uint8_t temp[] = { 0x69, 0x00 }; + data_s resp = { temp, sizeof(temp) }; + + net_nfc_server_hce_send_apdu_response(handle, &resp); + } + } + } else { + DEBUG_ERR_MSG("g_new0 failed"); + + if (hce_apdu->request_type == + NET_NFC_MESSAGE_ROUTING_HOST_EMU_DATA) { + uint8_t temp[] = { 0x69, 0x00 }; + data_s resp = { temp, sizeof(temp) }; + + net_nfc_server_hce_send_apdu_response(handle, &resp); + } + } + + net_nfc_util_clear_data(&hce_apdu->apdu); + + _net_nfc_util_free_mem(hce_event); +} + +static void _hce_on_client_detached_cb(net_nfc_client_context_info_t *info) +{ + _routing_table_del_by_id(info->id); +} + +gboolean net_nfc_server_hce_init(GDBusConnection *connection) +{ + GError *error = NULL; + gboolean result; + + if (hce_skeleton) + g_object_unref(hce_skeleton); + + hce_skeleton = net_nfc_gdbus_hce_skeleton_new(); + + g_signal_connect(hce_skeleton, + "handle-start-hce-handler", + G_CALLBACK(hce_handle_start_hce_handler), + NULL); + + g_signal_connect(hce_skeleton, + "handle-stop-hce-handler", + G_CALLBACK(hce_handle_stop_hce_handler), + NULL); + + g_signal_connect(hce_skeleton, + "handle-response-apdu", + G_CALLBACK(hce_handle_response_apdu), + NULL); + + result = g_dbus_interface_skeleton_export( + G_DBUS_INTERFACE_SKELETON(hce_skeleton), + connection, + "/org/tizen/NetNfcService/Hce", + &error); + + if (result == TRUE) { + /*TODO : Make the Routing Table for AID!*/ + /*TODO : Do i have to make other file for routing table?????*/ + _routing_table_init(); + + net_nfc_server_gdbus_register_on_client_detached_cb( + _hce_on_client_detached_cb); + } else { + DEBUG_ERR_MSG("can not skeleton_export %s", error->message); + + g_error_free(error); + + net_nfc_server_hce_deinit(); + } + + return result; +} + +void net_nfc_server_hce_deinit(void) +{ + if (hce_skeleton) + { + net_nfc_server_gdbus_unregister_on_client_detached_cb( + _hce_on_client_detached_cb); + + g_object_unref(hce_skeleton); + hce_skeleton = NULL; + } +} diff --git a/src/manager/net_nfc_server_ipc.c b/src/manager/net_nfc_server_ipc.c deleted file mode 100755 index 4216b83..0000000 --- a/src/manager/net_nfc_server_ipc.c +++ /dev/null @@ -1,856 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "vconf.h" -#include "security-server.h" - -#include "net_nfc_typedef_private.h" -#include "net_nfc_debug_private.h" -#include "net_nfc_util_defines.h" -#include "net_nfc_util_private.h" -#include "net_nfc_util_ipc.h" -#include "net_nfc_server_ipc_private.h" -#include "net_nfc_server_dispatcher_private.h" -#include "net_nfc_controller_private.h" -#include "net_nfc_manager_util_private.h" -#include "net_nfc_server_context_private.h" - -///////////////////////////// - -/* static variable */ -#ifdef SECURITY_SERVER -static char *cookies = NULL; -static int cookies_size = 0; -static gid_t gid = 0; -#endif - -static pthread_mutex_t g_server_socket_lock = PTHREAD_MUTEX_INITIALIZER; -static net_nfc_server_info_t g_server_info = { 0, }; - -///////////////// - -/*define static function*/ - -static gboolean net_nfc_server_ipc_callback_func(GIOChannel* channel, GIOCondition condition, gpointer data); -static bool net_nfc_server_read_client_request(int client_sock_fd, net_nfc_error_e* result); -static bool net_nfc_server_process_client_connect_request(); - -///////////////////////// - -bool net_nfc_server_set_server_state(uint32_t state) -{ - pthread_mutex_lock(&g_server_socket_lock); - - if (state == NET_NFC_SERVER_IDLE) - g_server_info.state &= NET_NFC_SERVER_IDLE; - else - g_server_info.state |= state; - - pthread_mutex_unlock(&g_server_socket_lock); - - return true; -} - -bool net_nfc_server_unset_server_state(uint32_t state) -{ - pthread_mutex_lock(&g_server_socket_lock); - - g_server_info.state &= ~state; - - pthread_mutex_unlock(&g_server_socket_lock); - - return true; -} - -uint32_t net_nfc_server_get_server_state() -{ - return g_server_info.state; -} - - - -bool net_nfc_server_ipc_initialize() -{ - int result = 0; - - pthread_mutex_lock(&g_server_socket_lock); - - /* initialize server context */ - g_server_info.server_src_id = 0; - g_server_info.server_channel = (GIOChannel *)NULL; - g_server_info.server_sock_fd = -1; - g_server_info.state = NET_NFC_SERVER_IDLE; - g_server_info.target_info = NULL; - /////////////////////////////// - -#ifdef USE_UNIX_DOMAIN - struct sockaddr_un saddrun_rv; - - g_server_info.server_sock_fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (g_server_info.server_sock_fd == -1) - { - DEBUG_SERVER_MSG("get socket is failed"); - goto ERROR; - } - - net_nfc_util_set_non_block_socket(g_server_info.server_sock_fd); - - result = remove(NET_NFC_SERVER_DOMAIN); - - memset(&saddrun_rv, 0, sizeof(struct sockaddr_un)); - saddrun_rv.sun_family = AF_UNIX; - strncpy(saddrun_rv.sun_path, NET_NFC_SERVER_DOMAIN, sizeof(saddrun_rv.sun_path) - 1); - - if ((result = bind(g_server_info.server_sock_fd, (struct sockaddr *)&saddrun_rv, sizeof(saddrun_rv))) < 0) - { - DEBUG_ERR_MSG("bind is failed"); - goto ERROR; - } - - if ((result = chmod(NET_NFC_SERVER_DOMAIN, 0777)) < 0) - { - DEBUG_ERR_MSG("can not change permission of UNIX DOMAIN file"); - goto ERROR; - } - -#else - struct sockaddr_in serv_addr; - - g_server_info.server_sock_fd = socket(PF_INET, SOCK_STREAM, 0); - if (g_server_info.server_sock_fd == -1) - { - DEBUG_SERVER_MSG("get socket is failed"); - goto ERROR; - } - - net_nfc_util_set_non_block_socket(g_server_info.server_sock_fd); - - memset(&serv_addr, 0x00, sizeof(struct sockaddr_in)); - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); - serv_addr.sin_port = htons(NET_NFC_SERVER_PORT); - - int val = 1; - - if (setsockopt(g_server_info.server_sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)) == 0) - { - DEBUG_SERVER_MSG("reuse address"); - } - - if (bind(g_server_info.server_sock_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) - { - DEBUG_ERR_MSG("bind is failed"); - goto ERROR; - } -#endif - - if ((result = listen(g_server_info.server_sock_fd, NET_NFC_CLIENT_MAX)) < 0) - { - DEBUG_ERR_MSG("listen is failed"); - goto ERROR; - } - - GIOCondition condition = (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_IN); - - if ((g_server_info.server_channel = g_io_channel_unix_new(g_server_info.server_sock_fd)) != NULL) - { - if ((g_server_info.server_src_id = g_io_add_watch(g_server_info.server_channel, condition, net_nfc_server_ipc_callback_func, NULL)) < 1) - { - DEBUG_ERR_MSG(" g_io_add_watch is failed"); - goto ERROR; - } - } - else - { - DEBUG_ERR_MSG(" g_io_channel_unix_new is failed"); - goto ERROR; - } - -#ifdef SECURITY_SERVER - gid = security_server_get_gid(NET_NFC_MANAGER_OBJECT); - if (gid == 0) - { - DEBUG_ERR_MSG("get gid from security server is failed. this object is not allowed by security server"); - goto ERROR; - } - - if ((cookies_size = security_server_get_cookie_size()) > 0) - { - _net_nfc_util_alloc_mem(cookies, cookies_size); - if (cookies == NULL) - { - DEBUG_ERR_MSG("alloc failed"); - goto ERROR; - } - } - else - { - DEBUG_ERR_MSG("security_server_get_cookie_size failed"); - goto ERROR; - } -#endif - - net_nfc_dispatcher_start_thread(); - DEBUG_SERVER_MSG("server ipc is initialized"); - - if (vconf_set_bool(NET_NFC_DISABLE_LAUNCH_POPUP_KEY, TRUE) != 0) - DEBUG_ERR_MSG("SERVER : launch state set vconf fail"); - - pthread_mutex_unlock(&g_server_socket_lock); - return true; - -ERROR : -#ifdef SECURITY_SERVER - if (cookies == NULL) - { - _net_nfc_util_free_mem(cookies); - } -#endif - - if (g_server_info.server_src_id > 0) - { - g_source_remove(g_server_info.server_src_id); - g_server_info.server_src_id = 0; - } - - if (g_server_info.server_channel != NULL) - { - g_io_channel_unref(g_server_info.server_channel); - g_server_info.server_channel = NULL; - } - - if (g_server_info.server_sock_fd != -1) - { - shutdown(g_server_info.server_sock_fd, SHUT_RDWR); - close(g_server_info.server_sock_fd); - g_server_info.server_sock_fd = -1; - } - - pthread_mutex_unlock(&g_server_socket_lock); - return false; -} - -void net_nfc_server_ipc_finalize() -{ - /* cleanup client */ - net_nfc_server_deinit_client_context(); - -#ifdef SECURITY_SERVER - if (cookies == NULL) - { - _net_nfc_util_free_mem(cookies); - } -#endif - - if (g_server_info.server_src_id > 0) - { - g_source_remove(g_server_info.server_src_id); - g_server_info.server_src_id = 0; - } - - if (g_server_info.server_channel != NULL) - { - g_io_channel_unref(g_server_info.server_channel); - g_server_info.server_channel = NULL; - } - - if (g_server_info.server_sock_fd != -1) - { - shutdown(g_server_info.server_sock_fd, SHUT_RDWR); - close(g_server_info.server_sock_fd); - g_server_info.server_sock_fd = -1; - } -} - -gboolean net_nfc_server_ipc_callback_func(GIOChannel *channel, GIOCondition condition, gpointer data) -{ - gboolean result = TRUE; - int sock_fd = g_io_channel_unix_get_fd(channel); - - if ((G_IO_ERR & condition) || (G_IO_HUP & condition)) - { - DEBUG_ERR_MSG("G_IO_ERR"); - if (sock_fd > 0) - { - if (sock_fd == g_server_info.server_sock_fd) - { - DEBUG_SERVER_MSG("server socket is closed"); - - net_nfc_dispatcher_cleanup_queue(); - net_nfc_server_ipc_finalize(); - } - else - { - DEBUG_SERVER_MSG("client socket is closed, socket [%d]", sock_fd); - - net_nfc_server_cleanup_client_context(sock_fd); - } - } - - result = FALSE; - } - else if (G_IO_NVAL & condition) - { - DEBUG_ERR_MSG("INVALID socket"); - result = FALSE; - } - else if (G_IO_IN & condition) - { - if (sock_fd > 0) - { - if (sock_fd == g_server_info.server_sock_fd) - { - /* client connect request */ - net_nfc_server_process_client_connect_request(); - } - else - { - net_nfc_error_e result = NET_NFC_OK; - - if (net_nfc_server_read_client_request(sock_fd, &result) == false) - { - switch (result) - { - case NET_NFC_OPERATION_FAIL : - DEBUG_SERVER_MSG("clear context and shutdown socket"); - net_nfc_server_cleanup_client_context(sock_fd); - result = FALSE; - break; - - default : - DEBUG_ERR_MSG("read client request is failed = [0x%x]", result); - net_nfc_server_cleanup_client_context(sock_fd); - result = FALSE; - break; - } - } - } - } - } - - return result; -} - -bool net_nfc_server_process_client_connect_request() -{ - socklen_t addrlen = 0; - int client_sock_fd = 0; - GIOChannel *client_channel = NULL; - uint32_t client_src_id = 0; - pid_t client_pid = -1; -#ifdef USE_UNIX_DOMAIN - struct ucred uc; - socklen_t uc_len = sizeof(uc); -#endif - DEBUG_SERVER_MSG("client is trying to connect to server"); - - if (net_nfc_server_get_client_count() >= NET_NFC_CLIENT_MAX) - { - DEBUG_SERVER_MSG("client is fully served. no more capa is remained."); - return false; - } - - if ((client_sock_fd = accept(g_server_info.server_sock_fd, NULL, &addrlen)) < 0) - { - DEBUG_ERR_MSG("can not accept client"); - return false; - } - -#ifdef USE_UNIX_DOMAIN - if (!getsockopt(client_sock_fd, SOL_SOCKET, SO_PEERCRED, &uc, &uc_len)) - { - client_pid = uc.pid; - } -#endif - DEBUG_SERVER_MSG("client [%d] is accepted by server, socket[%d]", - client_pid, client_sock_fd); - - GIOCondition condition = (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_IN); - - if ((client_channel = g_io_channel_unix_new(client_sock_fd)) != NULL) - { - if ((client_src_id = g_io_add_watch(client_channel, condition, - net_nfc_server_ipc_callback_func, NULL)) < 1) - { - DEBUG_ERR_MSG("add io callback is failed"); - goto ERROR; - } - } - else - { - DEBUG_ERR_MSG("create new g io channel is failed"); - goto ERROR; - } - - DEBUG_SERVER_MSG("client socket is bond with g_io_channel"); - - net_nfc_server_add_client_context(client_pid, client_sock_fd, - client_channel, client_src_id, NET_NFC_CLIENT_ACTIVE_STATE); - - return true; - -ERROR : - if (client_channel != NULL) - { - g_io_channel_unref(client_channel); - client_channel = NULL; - } - - if (client_sock_fd != -1) - { - shutdown(client_sock_fd, SHUT_RDWR); - close(client_sock_fd); - client_sock_fd = -1; - } - - return false; -} - -int __net_nfc_server_read_util(int client_sock_fd, void **detail, size_t size) -{ - static uint8_t flushing[128]; - - *detail = NULL; - _net_nfc_util_alloc_mem(*detail, size); - - if (*detail == NULL) - { - size_t read_size; - int readbyes = size; - - while (readbyes > 0) - { - read_size = readbyes > 128 ? 128 : readbyes; - if (net_nfc_server_recv_message_from_client(client_sock_fd, flushing, read_size) < 0) - { - return false; - } - readbyes -= read_size; - } - return false; - } - - if (net_nfc_server_recv_message_from_client(client_sock_fd, *detail, size) < 0) - { - _net_nfc_util_free_mem(*detail); - return false; - } - return true; -} - -bool net_nfc_server_read_client_request(int client_sock_fd, net_nfc_error_e *result) -{ - int read = 0; - uint32_t offset = 0; - uint32_t length = 0; - uint8_t *buffer = NULL; - net_nfc_request_msg_t *req_msg = NULL; - - if ((read = net_nfc_server_recv_message_from_client(client_sock_fd, (void *)&length, sizeof(length))) <= 0) - { - DEBUG_ERR_MSG("shutdown request from client"); - *result = NET_NFC_OPERATION_FAIL; - return false; - } - - if (read != sizeof(length)) - { - DEBUG_ERR_MSG("failed to read message length [%d]", read); - *result = NET_NFC_IPC_FAIL; - return false; - } - - if (length > NET_NFC_MAX_MESSAGE_LENGTH) - { - DEBUG_ERR_MSG("too long message [%d]", length); - *result = NET_NFC_IPC_FAIL; - return false; - } - - _net_nfc_util_alloc_mem(buffer, length); - if (buffer == NULL) - { - *result = NET_NFC_ALLOC_FAIL; - return false; - } - - memset(buffer, 0, length); - - if ((read = net_nfc_server_recv_message_from_client(client_sock_fd, (void *)buffer, length)) != length) - { - DEBUG_ERR_MSG("failed to read message [%d]", read); - _net_nfc_util_free_mem(buffer); - *result = NET_NFC_IPC_FAIL; - return false; - } - -#ifdef SECURITY_SERVER - uint32_t cookie_len = *(uint32_t *)(buffer + offset); - offset += sizeof(cookie_len); - - if (cookie_len == cookies_size && (length - offset) > cookies_size) - { - int error = 0; - - /* copy cookie */ - memcpy(cookies, buffer + offset, cookies_size); - offset += cookies_size; - - /* for debug */ -#if 0 - DEBUG_SERVER_MSG("recevied cookies"); - DEBUG_MSG_PRINT_BUFFER(cookies, cookie_len); -#endif - - /* check cookie */ - if ((error = security_server_check_privilege(cookies, gid)) < 0) - { - DEBUG_ERR_MSG("failed to authentificate client [%d]", error); - _net_nfc_util_free_mem(buffer); - *result = NET_NFC_SECURITY_FAIL; - return false; - } - } - else - { - DEBUG_ERR_MSG("there is no cookie or invalid in message"); - _net_nfc_util_free_mem(buffer); - *result = NET_NFC_SECURITY_FAIL; - return false; - } -#endif - - if (length > offset) - { - _net_nfc_util_alloc_mem(req_msg, length - offset); - if (req_msg != NULL) - { - memcpy(req_msg, buffer + offset, length - offset); - } - else - { - _net_nfc_util_free_mem(buffer); - *result = NET_NFC_ALLOC_FAIL; - return false; - } - } - else - { - _net_nfc_util_free_mem(buffer); - *result = NET_NFC_IPC_FAIL; - return false; - } - - _net_nfc_util_free_mem(buffer); - - pid_t client_pid = -1; - - net_nfc_client_info_t *info; - info = net_nfc_server_get_client_context(client_sock_fd); - if (info != NULL) - { - client_pid = info->pid; - } - DEBUG_MSG(">>>>>>>>>>>>>>> [%d] >> SERVER (msg [%d], length [%d])", client_pid, req_msg->request_type, length); - -#ifdef BROADCAST_MESSAGE - /* set client socket descriptor */ - req_msg->client_fd = client_sock_fd; -#endif - - /* process exceptional case of request type */ - switch (req_msg->request_type) - { - case NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE : - { - net_nfc_request_change_client_state_t *detail = (net_nfc_request_change_client_state_t *)req_msg; - - net_nfc_server_set_client_state(client_sock_fd, detail->client_state); - DEBUG_SERVER_MSG("net_nfc_server_read_client_request is finished"); - - _net_nfc_util_free_mem(req_msg); - - return true; - } - break; - - case NET_NFC_MESSAGE_SERVICE_SET_LAUNCH_STATE : - { - DEBUG_SERVER_MSG("checking NET_NFC_MESSAGE_SERVICE_SET_LAUNCH_STATE..."); -#if 1 - int ret = security_server_check_privilege_by_sockfd(req_msg->client_fd,"nfc-manager::common","w"); - - if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) - { - DEBUG_SERVER_MSG("checking faile and return..."); -// return false; - } -#endif - - net_nfc_request_set_launch_state_t *detail = (net_nfc_request_set_launch_state_t *)req_msg; - - net_nfc_server_set_launch_state(client_sock_fd, detail->set_launch_popup); - - _net_nfc_util_free_mem(req_msg); - - return true; - } - break; - - default : - break; - } - -#ifdef BROADCAST_MESSAGE - net_nfc_dispatcher_queue_push(req_msg); -#else - /* check current client context is activated. */ - if (net_nfc_server_get_client_state(client_sock_fd) == NET_NFC_CLIENT_ACTIVE_STATE) - { - DEBUG_SERVER_MSG("client is activated"); - net_nfc_dispatcher_queue_push(req_msg); - DEBUG_SERVER_MSG("net_nfc_server_read_client_request is finished"); - break; - } - else - { - DEBUG_SERVER_MSG("client is deactivated"); - - /* free req_msg */ - _net_nfc_util_free_mem(req_msg); - - DEBUG_SERVER_MSG("net_nfc_server_read_client_request is finished"); - return false; - } -#endif - - return true; -} - -#ifdef BROADCAST_MESSAGE -bool net_nfc_server_send_message_to_client(int socket, void *message, int length) -{ - int len = 0; - bool result = true; - - pthread_mutex_lock(&g_server_socket_lock); - len = send(socket, (void *)message, length, MSG_NOSIGNAL); - pthread_mutex_unlock(&g_server_socket_lock); - - if (len <= 0) - { - uint8_t buf[1024] = { 0x00, }; - - DEBUG_ERR_MSG("send failed : socket [%d], length [%d], [%s]", socket, length, strerror_r(errno, (char *)buf, sizeof(buf))); - if (errno == EPIPE) - { - abort(); - } - result = false; - } - - return result; -} -#else -bool net_nfc_server_send_message_to_client(void* message, int length) -{ - pthread_mutex_lock(&g_server_socket_lock); - int leng = send(g_server_info.client_sock_fd, (void *)message, length, 0); - pthread_mutex_unlock(&g_server_socket_lock); - - if(leng > 0) - { - return true; - } - else - { - DEBUG_ERR_MSG("failed to send message, socket = [%d], msg_length = [%d]", g_server_info.client_sock_fd, length); - return false; - } -} -#endif - -int net_nfc_server_recv_message_from_client(int client_sock_fd, void* message, int length) -{ - int leng = recv(client_sock_fd, message, length, 0); - - return leng; -} - -static void _net_nfc_for_each_cb(net_nfc_client_info_t *client, void *user_param) -{ - if (user_param != NULL) - { - int length = *(int *)user_param; - uint8_t *send_buffer = ((uint8_t *)user_param) + sizeof(int); - - if (net_nfc_server_send_message_to_client(client->socket, send_buffer, length) == true) - { -// DEBUG_MSG(">>>>> TO CLIENT [%d] >>>>> (msg [%d], length [%d])", client->socket, msg_type, length); - DEBUG_MSG("<<<<<<<<<<<<<<< [%d] << SERVER (length [%d])", client->pid, length); - } - } -} - -#ifdef BROADCAST_MESSAGE -bool net_nfc_broadcast_response_msg(int msg_type, ...) -{ - va_list list; - int total_size = 0; - int written_size = 0; - uint8_t *send_buffer = NULL; - - va_start(list, msg_type); - - /* total length */ - total_size += sizeof(msg_type); - total_size += net_nfc_util_get_va_list_length(list); - - _net_nfc_util_alloc_mem(send_buffer, total_size + sizeof(total_size)); - - memcpy(send_buffer + written_size, &(total_size), sizeof(total_size)); - written_size += sizeof(total_size); - - memcpy(send_buffer + written_size, &(msg_type), sizeof(msg_type)); - written_size += sizeof(msg_type); - - written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size + sizeof(total_size) - written_size, list); - - va_end(list); - - net_nfc_server_for_each_client_context(_net_nfc_for_each_cb, send_buffer); - - _net_nfc_util_free_mem(send_buffer); - - return true; -} - -bool net_nfc_send_response_msg(int socket, int msg_type, ...) -#else -bool net_nfc_send_response_msg(int msg_type, ...) -#endif -{ - va_list list; - int total_size = 0; - int written_size = 0; - uint8_t *send_buffer = NULL; - net_nfc_client_info_t *info; - - va_start(list, msg_type); - - total_size += sizeof(msg_type); - total_size += net_nfc_util_get_va_list_length(list); - - _net_nfc_util_alloc_mem(send_buffer, total_size + sizeof(total_size)); - -// memcpy(send_buffer + written_size, &(total_size), sizeof(total_size)); -// written_size += sizeof(total_size); - - memcpy(send_buffer + written_size, &(msg_type), sizeof(msg_type)); - written_size += sizeof(msg_type); - -// written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size + sizeof(total_size) - written_size, list); - written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size - written_size, list); - - va_end(list); - - if ((info = net_nfc_server_get_client_context(socket)) != NULL) - { -#ifdef BROADCAST_MESSAGE - if (net_nfc_server_send_message_to_client(socket, (void *)send_buffer, total_size) == true) -#else - if (net_nfc_server_send_message_to_client((void *)send_buffer, total_size) == true) -#endif - { - DEBUG_MSG("<<<<<<<<<<<<<<< [%d] << SERVER (msg [%d], length [%d])", info->pid, msg_type, total_size - sizeof(total_size)); - } - } - else - { - DEBUG_ERR_MSG("Client not found : socket [%d], length [%d]", socket, total_size + sizeof(total_size)); - } - - _net_nfc_util_free_mem(send_buffer); - - return true; -} - -void net_nfc_server_set_tag_info(void *info) -{ - net_nfc_request_target_detected_t *detail = (net_nfc_request_target_detected_t *)info; - net_nfc_current_target_info_s *target_info = NULL; - - pthread_mutex_lock(&g_server_socket_lock); - - if (g_server_info.target_info != NULL) - _net_nfc_util_free_mem(g_server_info.target_info); - - _net_nfc_util_alloc_mem(target_info, sizeof(net_nfc_current_target_info_s) + detail->target_info_values.length); - if (target_info != NULL) - { - target_info->handle = detail->handle; - target_info->devType = detail->devType; - - if (target_info->devType != NET_NFC_NFCIP1_INITIATOR && target_info->devType != NET_NFC_NFCIP1_TARGET) - { - target_info->number_of_keys = detail->number_of_keys; - target_info->target_info_values.length = detail->target_info_values.length; - memcpy(&target_info->target_info_values, &detail->target_info_values, target_info->target_info_values.length); - } - - g_server_info.target_info = target_info; - } - - pthread_mutex_unlock(&g_server_socket_lock); -} - -bool net_nfc_server_is_target_connected(void *handle) -{ - bool result = false; - - if (g_server_info.target_info != NULL && g_server_info.target_info->handle == handle) - result = true; - - return result; -} - -net_nfc_current_target_info_s *net_nfc_server_get_tag_info() -{ - return g_server_info.target_info; -} - -void net_nfc_server_free_current_tag_info() -{ - pthread_mutex_lock(&g_server_socket_lock); - - _net_nfc_util_free_mem(g_server_info.target_info); - - pthread_mutex_unlock(&g_server_socket_lock); -} diff --git a/src/manager/net_nfc_server_llcp.c b/src/manager/net_nfc_server_llcp.c new file mode 100755 index 0000000..b3b13da --- /dev/null +++ b/src/manager/net_nfc_server_llcp.c @@ -0,0 +1,2888 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 /*for pm lock*/ +//#include /* battery_adv */ + +#include "net_nfc_debug_internal.h" +#include "net_nfc_controller_internal.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_util_gdbus_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_llcp.h" +#include "net_nfc_server_p2p.h" +#include "net_nfc_server_process_snep.h" +#include "net_nfc_server_process_npp.h" +#include "net_nfc_server_process_handover.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 _llcp_client_data +{ + GDBusConnection *connection; + char *id; + net_nfc_target_handle_h handle; + net_nfc_llcp_socket_t socket; + void *user_data; +} +llcp_client_data; + + +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; + guint16 miu; + guint8 rw; + guint type; + guint sap; + gchar *service_name; +}; + +typedef struct _LlcpAcceptData LlcpAcceptData; + +struct _LlcpAcceptData +{ + NetNfcGDbusLlcp *llcp; + GDBusMethodInvocation *invocation; + + guint handle; + guint client_socket; +}; + +typedef struct _LlcpConnectData LlcpConnectData; + +struct _LlcpConnectData +{ + NetNfcGDbusLlcp *llcp; + GDBusMethodInvocation *invocation; + + guint32 handle; + guint32 client_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; + guint16 miu; + guint8 rw; + guint type; + guint sap; +}; + +typedef struct _LlcpSendData LlcpSendData; + +struct _LlcpSendData +{ + NetNfcGDbusLlcp *llcp; + GDBusMethodInvocation *invocation; + + guint32 handle; + guint32 client_socket; + + data_s data; +}; + +typedef struct _LlcpSendToData LlcpSendToData; + +struct _LlcpSendToData +{ + NetNfcGDbusLlcp *llcp; + GDBusMethodInvocation *invocation; + + guint32 handle; + guint32 client_socket; + guint8 sap; + + data_s data; +}; + +typedef struct _LlcpReceiveData LlcpReceiveData; + +struct _LlcpReceiveData +{ + NetNfcGDbusLlcp *llcp; + GDBusMethodInvocation *invocation; + + guint32 handle; + guint32 client_socket; + guint32 req_length; +}; + +typedef struct _LlcpCloseData LlcpCloseData; + +struct _LlcpCloseData +{ + NetNfcGDbusLlcp *llcp; + GDBusMethodInvocation *invocation; + + guint32 handle; + guint32 client_socket; +}; + +typedef struct _LlcpDisconnectData LlcpDisconnectData; + +struct _LlcpDisconnectData +{ + NetNfcGDbusLlcp *llcp; + GDBusMethodInvocation *invocation; + + guint32 handle; + guint32 client_socket; +}; + +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_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_incoming_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_send_to_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_accept_thread_func(gpointer user_data); + +static void llcp_handle_reject_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, + 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, + 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, + 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, + 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, + 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_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_req_length, + GVariant *smack_privilege, + gpointer user_data); + +static gboolean llcp_handle_close(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + GVariant *smack_privilege, + gpointer user_data); + +static gboolean llcp_handle_disconnect(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + GVariant *smack_privilege, + 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_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_socket_error_cb(net_nfc_llcp_socket_t socket, + net_nfc_error_e result, + data_s *data, + void *extra, + void *user_param) +{ + llcp_client_data *client_data = (llcp_client_data *)user_param; + GError *error = NULL; + + if (g_dbus_connection_emit_signal( + client_data->connection, + client_data->id, + "/org/tizen/NetNfcService/Llcp", + "org.tizen.NetNfcService.Llcp", + "Error", + g_variant_new("(uui)", + GPOINTER_TO_UINT(client_data->handle), + socket, + result), + &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"); + } + } +} + +static void llcp_incoming_cb(net_nfc_llcp_socket_t socket, + net_nfc_error_e result, + data_s *data, + void *extra, + void *user_param) +{ + llcp_client_data *client_data = (llcp_client_data *)user_param; + GError *error = NULL; + + if (g_dbus_connection_emit_signal( + client_data->connection, + client_data->id, + "/org/tizen/NetNfcService/Llcp", + "org.tizen.NetNfcService.Llcp", + "Incoming", + g_variant_new("(uuu)", + GPOINTER_TO_UINT(client_data->handle), + client_data->socket, + socket), + &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"); + } + } +} + +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 = (LlcpConnectData *)user_param; + + g_assert(llcp_data != NULL); + g_assert(llcp_data->llcp != NULL); + g_assert(llcp_data->invocation != NULL); + + net_nfc_gdbus_llcp_complete_connect(llcp_data->llcp, + llcp_data->invocation, + result, + socket); + + g_free(llcp_data->service_name); + + g_object_unref(llcp_data->invocation); + g_object_unref(llcp_data->llcp); + + 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 = (LlcpConnectSapData *)user_param; + + g_assert(llcp_data != NULL); + g_assert(llcp_data->llcp != NULL); + g_assert(llcp_data->invocation != NULL); + + net_nfc_gdbus_llcp_complete_connect_sap( + llcp_data->llcp, + llcp_data->invocation, + result, + 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) +{ + LlcpSendData *llcp_data = (LlcpSendData *)user_param; + + g_assert(llcp_data != NULL); + g_assert(llcp_data->llcp != NULL); + g_assert(llcp_data->invocation != NULL); + + net_nfc_gdbus_llcp_complete_send( + llcp_data->llcp, + llcp_data->invocation, + result, + socket); + + net_nfc_util_clear_data(&llcp_data->data); + + g_object_unref(llcp_data->invocation); + g_object_unref(llcp_data->llcp); + + g_free(llcp_data); +} + +static void llcp_send_to_cb(net_nfc_llcp_socket_t socket, + net_nfc_error_e result, + data_s *data, + void *extra, + void *user_param) +{ + LlcpSendToData *llcp_data = (LlcpSendToData *)user_param; + + g_assert(llcp_data != NULL); + g_assert(llcp_data->llcp != NULL); + g_assert(llcp_data->invocation != NULL); + + net_nfc_gdbus_llcp_complete_send_to( + llcp_data->llcp, + llcp_data->invocation, + result, + socket); + + net_nfc_util_clear_data(&llcp_data->data); + + 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) +{ + LlcpReceiveData *llcp_data = (LlcpReceiveData *)user_param; + GVariant *variant; + + g_assert(llcp_data != NULL); + g_assert(llcp_data->llcp != NULL); + g_assert(llcp_data->invocation != NULL); + + variant = net_nfc_util_gdbus_data_to_variant(data); + net_nfc_gdbus_llcp_complete_receive( + llcp_data->llcp, + llcp_data->invocation, + result, + 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) +{ + LlcpReceiveData *llcp_data = (LlcpReceiveData *)user_param; + GVariant *variant; + + g_assert(llcp_data != NULL); + g_assert(llcp_data->llcp != NULL); + g_assert(llcp_data->invocation != NULL); + + variant = net_nfc_util_gdbus_data_to_variant(data); + net_nfc_gdbus_llcp_complete_receive_from( + llcp_data->llcp, + llcp_data->invocation, + result, + (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) +{ + LlcpDisconnectData *llcp_data = (LlcpDisconnectData *)user_param; + + g_assert(llcp_data != NULL); + g_assert(llcp_data->llcp != NULL); + g_assert(llcp_data->invocation != NULL); + + net_nfc_gdbus_llcp_complete_disconnect( + llcp_data->llcp, + llcp_data->invocation, + result, + 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 = (LlcpConfigData *)user_data; + net_nfc_error_e result; + net_nfc_llcp_config_info_s config; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + config.miu = data->miu; + config.wks = data->wks; + config.lto = data->lto; + config.option = data->option; + + result = net_nfc_server_llcp_set_config(&config); + + net_nfc_gdbus_llcp_complete_config(data->llcp, + data->invocation, + result); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); +} + +static void llcp_handle_listen_thread_func(gpointer user_data) +{ + LlcpListenData *data = (LlcpListenData *)user_data; + llcp_client_data *client_data; + + net_nfc_llcp_socket_t socket = -1; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + client_data = g_try_new0(llcp_client_data, 1); + if (client_data == NULL) { + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + client_data->connection = g_dbus_method_invocation_get_connection( + data->invocation); + client_data->id = g_strdup( + g_dbus_method_invocation_get_sender(data->invocation)); + client_data->handle = (net_nfc_target_handle_h)data->handle; + + if (net_nfc_controller_llcp_create_socket(&socket, + data->type, + data->miu, + data->rw, + &result, + llcp_socket_error_cb, + client_data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_create_socket failed [%d]", result); + + goto ERROR; + } + + client_data->socket = socket; + + if (net_nfc_controller_llcp_bind(socket, + data->sap, + &result) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_bind failed [%d]", result); + + goto ERROR; + } + + if (net_nfc_controller_llcp_listen(GUINT_TO_POINTER(data->handle), + (uint8_t *)data->service_name, + socket, + &result, + llcp_incoming_cb, + client_data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_listen failed [%d]", result); + + goto ERROR; + } + + net_nfc_gdbus_llcp_complete_listen(data->llcp, data->invocation, + result, + GPOINTER_TO_UINT(socket)); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + + return; + +ERROR : + net_nfc_gdbus_llcp_complete_listen(data->llcp, data->invocation, + result, + -1); + + if (socket != -1) + net_nfc_controller_llcp_socket_close(socket, &result); + + g_free(client_data); + + g_free(data->service_name); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); +} + +static void llcp_handle_accept_thread_func(gpointer user_data) +{ + LlcpAcceptData *data = (LlcpAcceptData *)user_data; + llcp_client_data *client_data; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + client_data = g_try_new0(llcp_client_data, 1); + if (client_data == NULL) { + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + client_data->connection = g_dbus_method_invocation_get_connection( + data->invocation); + client_data->id = g_strdup( + g_dbus_method_invocation_get_sender(data->invocation)); + client_data->handle = (net_nfc_target_handle_h)data->handle; + client_data->socket = data->client_socket; + + if (net_nfc_controller_llcp_accept(data->client_socket, &result, + llcp_socket_error_cb, + client_data) == false) { + DEBUG_ERR_MSG("net_nfc_controller_llcp_accept failed [%d]", result); + + goto ERROR; + } + + net_nfc_gdbus_llcp_complete_accept(data->llcp, data->invocation, + result); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + + return; + +ERROR : + net_nfc_gdbus_llcp_complete_accept(data->llcp, data->invocation, + result); + + g_free(client_data); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); +} + +static void llcp_handle_reject_thread_func(gpointer user_data) +{ + LlcpAcceptData *data = (LlcpAcceptData *)user_data; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + if (net_nfc_controller_llcp_reject(GUINT_TO_POINTER(data->handle), + data->client_socket, + &result) == false) { + DEBUG_ERR_MSG("net_nfc_controller_llcp_reject failed [%d]", result); + } + + net_nfc_gdbus_llcp_complete_reject(data->llcp, data->invocation, + result); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); +} + + +static void llcp_handle_connect_thread_func(gpointer user_data) +{ + LlcpConnectData *data = (LlcpConnectData *)user_data; + llcp_client_data *client_data; + net_nfc_llcp_socket_t socket = -1; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + client_data = g_try_new0(llcp_client_data, 1); + if (client_data == NULL) { + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + client_data->connection = g_dbus_method_invocation_get_connection( + data->invocation); + client_data->id = g_strdup( + g_dbus_method_invocation_get_sender(data->invocation)); + client_data->handle = (net_nfc_target_handle_h)data->handle; + + if (net_nfc_controller_llcp_create_socket(&socket, + data->type, + data->miu, + data->rw, + &result, + llcp_socket_error_cb, + client_data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_create_socket failed [%d]", result); + + goto ERROR; + } + + client_data->socket = 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("net_nfc_controller_llcp_listen failed [%d]", result); + + goto ERROR; + } + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + + return; + +ERROR : + net_nfc_gdbus_llcp_complete_connect(data->llcp, data->invocation, + result, + -1); + + if (socket != -1) + net_nfc_controller_llcp_socket_close(socket, &result); + + g_free(client_data); + + g_free(data->service_name); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); +} + +static void llcp_handle_connect_sap_thread_func(gpointer user_data) +{ + LlcpConnectSapData *data = (LlcpConnectSapData *)user_data; + llcp_client_data *client_data; + + net_nfc_llcp_socket_t socket = -1; + net_nfc_error_e result = NET_NFC_OK; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + client_data = g_try_new0(llcp_client_data, 1); + if (client_data == NULL) { + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + client_data->connection = g_dbus_method_invocation_get_connection( + data->invocation); + client_data->id = g_strdup( + g_dbus_method_invocation_get_sender(data->invocation)); + client_data->handle = (net_nfc_target_handle_h)data->handle; + + if (net_nfc_controller_llcp_create_socket(&socket, + data->type, + data->miu, + data->rw, + &result, + llcp_socket_error_cb, + client_data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_create_socket failed [%d]", result); + + goto ERROR; + } + + client_data->socket = socket; + + if (net_nfc_controller_llcp_connect(GUINT_TO_POINTER(data->handle), + socket, + data->sap, + &result, + llcp_connect_cb, + data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_listen failed [%d]", result); + + goto ERROR; + } + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + + return; + +ERROR : + net_nfc_gdbus_llcp_complete_connect_sap(data->llcp, data->invocation, + result, + -1); + + if (socket != -1) + net_nfc_controller_llcp_socket_close(socket, &result); + + g_free(client_data); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); +} + +static void llcp_handle_send_thread_func(gpointer user_data) +{ + LlcpSendData *data = (LlcpSendData *)user_data; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + if (net_nfc_controller_llcp_send(GUINT_TO_POINTER(data->handle), + data->client_socket, + &data->data, + &result, + llcp_send_cb, + data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_send failed [%d]", result); + + net_nfc_gdbus_llcp_complete_send(data->llcp, + data->invocation, + result, + data->client_socket); + + net_nfc_util_clear_data(&data->data); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } +} + +static void llcp_handle_send_to_thread_func(gpointer user_data) +{ + LlcpSendToData *data = (LlcpSendToData *)user_data; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + if (net_nfc_controller_llcp_send_to(GUINT_TO_POINTER(data->handle), + data->client_socket, + &data->data, + data->sap, + &result, + llcp_send_to_cb, + data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_send_to failed [%d]", result); + + net_nfc_gdbus_llcp_complete_send_to(data->llcp, + data->invocation, + result, + data->client_socket); + + net_nfc_util_clear_data(&data->data); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } +} + +static void llcp_handle_receive_thread_func(gpointer user_data) +{ + LlcpReceiveData *data = (LlcpReceiveData *)user_data; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + if (net_nfc_controller_llcp_recv(GUINT_TO_POINTER(data->handle), + data->client_socket, + data->req_length, + &result, + llcp_receive_cb, + data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_recv failed [%d]", result); + + net_nfc_gdbus_llcp_complete_receive(data->llcp, + data->invocation, + result, + net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } +} + +static void llcp_handle_receive_from_thread_func(gpointer user_data) +{ + LlcpReceiveData *data = (LlcpReceiveData *)user_data; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + if (net_nfc_controller_llcp_recv_from(GUINT_TO_POINTER(data->handle), + data->client_socket, + data->req_length, + &result, + llcp_receive_from_cb, + data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_recv_from failed [%d]", result); + + net_nfc_gdbus_llcp_complete_receive_from(data->llcp, + data->invocation, + result, + -1, + net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } +} + +static void llcp_handle_close_thread_func(gpointer user_data) +{ + LlcpCloseData *data = (LlcpCloseData *)user_data; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + net_nfc_controller_llcp_socket_close(data->client_socket, &result); + + net_nfc_gdbus_llcp_complete_close(data->llcp, + data->invocation, + result, + data->client_socket); +} + +static void llcp_handle_disconnect_thread_func(gpointer user_data) +{ + LlcpDisconnectData *data = (LlcpDisconnectData *)user_data; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->llcp != NULL); + g_assert(data->invocation != NULL); + + if (GUINT_TO_POINTER(data->handle) == 0) + { + int ret_val; + + net_nfc_server_free_target_info(); + ret_val = display_unlock_state(LCD_NORMAL, PM_RESET_TIMER); + DEBUG_SERVER_MSG("net_nfc_controller_disconnect display_unlock_state" + "[%d]!!", ret_val); + } + + if (net_nfc_controller_llcp_disconnect(GUINT_TO_POINTER(data->handle), + data->client_socket, + &result, + llcp_disconnect_cb, + data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_disconnect failed [%d]", result); + + net_nfc_gdbus_llcp_complete_disconnect(data->llcp, + data->invocation, + result, + data->client_socket); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } +} + + +static gboolean llcp_handle_config(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + GVariant *arg_config, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpConfigData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpConfigData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_config(llcp, + invocation, + result); + + return TRUE; +} + +static gboolean llcp_handle_listen(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + guint16 arg_miu, + guint8 arg_rw, + gint32 arg_type, + guint8 arg_sap, + const gchar *arg_service_name, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpListenData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpListenData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->llcp = g_object_ref(llcp); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->client_socket = arg_client_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) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_free(data->service_name); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_listen(llcp, invocation, result, -1); + + return TRUE; +} + +static gboolean llcp_handle_accept(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpAcceptData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpAcceptData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->llcp = g_object_ref(llcp); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->client_socket = arg_client_socket; + + if (net_nfc_server_controller_async_queue_push( + llcp_handle_accept_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_accept(llcp, invocation, result); + + return TRUE; +} + +static gboolean llcp_handle_reject(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpAcceptData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpAcceptData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->llcp = g_object_ref(llcp); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->client_socket = arg_client_socket; + + if (net_nfc_server_controller_async_queue_push( + llcp_handle_reject_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_reject(llcp, invocation, result); + + return TRUE; +} + +static gboolean llcp_handle_connect(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + guint16 arg_miu, + guint8 arg_rw, + gint32 arg_type, + const gchar *arg_service_name, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpConnectData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpConnectData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->llcp = g_object_ref(llcp); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->client_socket = arg_client_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) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_free(data->service_name); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_connect(llcp, invocation, result, -1); + + return TRUE; +} + +static gboolean llcp_handle_connect_sap(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + guint16 arg_miu, + guint8 arg_rw, + gint32 arg_type, + guint8 arg_sap, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpConnectSapData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpConnectSapData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->llcp = g_object_ref(llcp); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->client_socket = arg_client_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) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_connect_sap(llcp,invocation, result, -1); + + return TRUE; +} + +static gboolean llcp_handle_send(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + GVariant *arg_data, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpSendData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpSendData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->llcp = g_object_ref(llcp); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->client_socket = arg_client_socket; + + net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data); + + if (net_nfc_server_controller_async_queue_push( + llcp_handle_send_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + net_nfc_util_clear_data(&data->data); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_send(llcp, invocation, + result, arg_client_socket); + + return TRUE; +} + +static gboolean llcp_handle_send_to(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + guint8 arg_sap, + GVariant *arg_data, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpSendToData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpSendToData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->llcp = g_object_ref(llcp); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->client_socket = arg_client_socket; + data->sap = arg_sap; + + net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data); + + if (net_nfc_server_controller_async_queue_push( + llcp_handle_send_to_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + net_nfc_util_clear_data(&data->data); + + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_send_to(llcp, invocation, + result, arg_client_socket); + + return TRUE; +} + +static gboolean llcp_handle_receive(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + guint32 arg_req_length, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpReceiveData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpReceiveData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->llcp = g_object_ref(llcp); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->client_socket = arg_client_socket; + data->req_length = arg_req_length; + + if (net_nfc_server_controller_async_queue_push( + llcp_handle_receive_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_receive(llcp, invocation, result, + net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + return TRUE; +} + +static gboolean llcp_handle_receive_from(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + guint32 arg_req_length, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpReceiveData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpReceiveData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->llcp = g_object_ref(llcp); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->client_socket = arg_client_socket; + data->req_length = arg_req_length; + + if (net_nfc_server_controller_async_queue_push( + llcp_handle_receive_from_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_receive_from(llcp, invocation, + result, -1, net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + return TRUE; +} + +static gboolean llcp_handle_close(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpCloseData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpCloseData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->llcp = g_object_ref(llcp); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->client_socket = arg_client_socket; + + if (net_nfc_server_controller_async_queue_push( + llcp_handle_close_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_close(llcp, invocation, + result, arg_client_socket); + + return TRUE; +} + +static gboolean llcp_handle_disconnect(NetNfcGDbusLlcp *llcp, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + guint32 arg_client_socket, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result; + LlcpDisconnectData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(LlcpDisconnectData, 1); + if (data == NULL) { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->llcp = g_object_ref(llcp); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + data->client_socket = arg_client_socket; + + if (net_nfc_server_controller_async_queue_push( + llcp_handle_disconnect_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->llcp); + + g_free(data); + } + + net_nfc_gdbus_llcp_complete_disconnect(llcp, invocation, + result, arg_client_socket); + + return TRUE; +} + +void net_nfc_server_llcp_deactivated(gpointer user_data) +{ + net_nfc_current_target_info_s *target_info = NULL; + net_nfc_target_handle_s *handle = NULL; + + target_info = net_nfc_server_get_target_info(); + + if(target_info != NULL && target_info->handle != NULL) + handle = target_info->handle; + + if (handle != NULL) + { + net_nfc_error_e result = NET_NFC_OK; + + if (net_nfc_controller_disconnect(handle, &result) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_disconnect failed, [%d]", result); +#if 0 + if (result != NET_NFC_NOT_CONNECTED) + { + net_nfc_controller_exception_handler(); + } + else + { + DEBUG_SERVER_MSG("target was not connected."); + } +#endif + } + + net_nfc_server_set_state(NET_NFC_SERVER_IDLE); + } + else + { + int ret_val = 0; + + ret_val = display_unlock_state(LCD_NORMAL, PM_RESET_TIMER); + + DEBUG_SERVER_MSG("the target was disconnected display_unlock_state = [%d]" , ret_val); + } + + /* send p2p detatch */ + if (net_nfc_server_controller_async_queue_push( + net_nfc_server_p2p_detached, NULL) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + } +} + +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 = (LlcpSimpleData *)user_param; + + DEBUG_SERVER_MSG("Check socket = [%x]" ,socket ); + + g_assert(simple_data != NULL); + + if (simple_data->error_callback) + { + simple_data->error_callback(result, + simple_data->handle, + socket, + data, + simple_data->user_data); + } + + g_free(simple_data); + simple_data = NULL; +} + +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 = (LlcpSimpleData *)user_param; + + g_assert(simple_data != NULL); + + 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); + } + + /* 'simple_data' will be freed in socket error callback */ +} + +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 = (LlcpSimpleData *)user_param; + + g_assert(simple_data != NULL); + + 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); + } + + /* 'simple_data' will be freed in socket error callback */ +} + +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 = (LlcpSimpleData *)user_param; + + g_assert(simple_data != NULL); + + 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 = (LlcpSimpleData *)user_param; + + g_assert(simple_data != NULL); + + if (simple_data->callback) + { + simple_data->callback(result, + simple_data->handle, + socket, + data, + simple_data->user_data); + } + + g_free(simple_data); +} + +static void _llcp_on_client_detached_cb(net_nfc_client_context_info_t *client) +{ + net_nfc_server_llcp_unregister_services(client->id); +} + +/* Public Function */ +gboolean net_nfc_server_llcp_init(GDBusConnection *connection) +{ + gboolean result; + 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-accept", + G_CALLBACK(llcp_handle_accept), + NULL); + + g_signal_connect(llcp_skeleton, + "handle-reject", + G_CALLBACK(llcp_handle_reject), + 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); + + result = g_dbus_interface_skeleton_export( + G_DBUS_INTERFACE_SKELETON(llcp_skeleton), + connection, + "/org/tizen/NetNfcService/Llcp", + &error); + if (result == TRUE) { + net_nfc_server_gdbus_register_on_client_detached_cb( + _llcp_on_client_detached_cb); + } else { + g_error_free(error); + + net_nfc_server_llcp_deinit(); + } + + + return result; +} + +void net_nfc_server_llcp_deinit(void) +{ + if (llcp_skeleton) + { + net_nfc_server_gdbus_unregister_on_client_detached_cb( + _llcp_on_client_detached_cb); + + g_object_unref(llcp_skeleton); + llcp_skeleton = NULL; + } +} + +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; + LlcpSimpleData *simple_data = NULL; + net_nfc_llcp_socket_t socket = -1; + net_nfc_llcp_config_info_s config; + + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + 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); + + goto ERROR; + } + + simple_data = g_try_new0(LlcpSimpleData, 1); + if (simple_data == NULL) { + DEBUG_ERR_MSG("g_try_new0 failed"); + + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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("net_nfc_controller_llcp_create_socket failed [%d]", result); + + goto ERROR; + } + + simple_data->socket = socket; + + if (net_nfc_controller_llcp_bind(socket, + sap, + &result) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_bind failed [%d]", result); + + goto ERROR; + } + + if (net_nfc_controller_llcp_listen(handle, + (uint8_t *)san, + socket, + &result, + llcp_simple_listen_cb, + simple_data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_listen failed [%d]", result); + + goto ERROR; + } + + DEBUG_SERVER_MSG("result [%d]", result); + + if (result == NET_NFC_BUSY) + result = NET_NFC_OK; + + return result; + +ERROR : + if (socket != -1) { + net_nfc_error_e temp; + + net_nfc_controller_llcp_socket_close(socket, &temp); + } + + 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; + LlcpSimpleData *simple_data = NULL; + net_nfc_llcp_socket_t socket = -1; + net_nfc_llcp_config_info_s config; + + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + 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); + + goto ERROR; + } + + simple_data = g_try_new0(LlcpSimpleData, 1); + if (simple_data == NULL) { + DEBUG_ERR_MSG("g_try_new0 failed"); + + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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("net_nfc_controller_llcp_create_socket failed [%d]", result); + + goto ERROR; + } + + 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("net_nfc_controller_llcp_connect failed [%d]", result); + + goto ERROR; + } + } + 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("net_nfc_controller_llcp_connect_by_url failed [%d]", result); + + goto ERROR; + } + } + + DEBUG_SERVER_MSG("result [%d]", result); + + if (result == NET_NFC_BUSY) + result = NET_NFC_OK; + + return result; + +ERROR : + if (socket != -1) { + net_nfc_error_e temp; + + net_nfc_controller_llcp_socket_close(socket, &temp); + } +#if 1 + if (simple_data != NULL) { + g_free(simple_data); + simple_data = NULL; + } +#endif + 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; + LlcpSimpleData *simple_data; + + simple_data = g_try_new0(LlcpSimpleData, 1); + if (simple_data != NULL) { + 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_socket_error_cb, + simple_data) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_accept failed [%d]", result); + } + } else { + DEBUG_ERR_MSG("g_try_new0 failed"); + + result = NET_NFC_ALLOC_FAIL; + } + + 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; + LlcpSimpleData *simple_data; + + simple_data = g_try_new0(LlcpSimpleData, 1); + if (simple_data != NULL) { + 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("net_nfc_controller_llcp_send failed [%d]", + result); + } + } else { + DEBUG_ERR_MSG("g_try_new0 failed"); + + result = NET_NFC_ALLOC_FAIL; + } + + 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; + LlcpSimpleData *simple_data; + + simple_data = g_try_new0(LlcpSimpleData, 1); + if (simple_data != NULL) { + 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("net_nfc_controller_llcp_recv failed [%d]", result); + + g_free(simple_data); + } + } else { + DEBUG_ERR_MSG("g_try_new0 failed"); + + result = NET_NFC_ALLOC_FAIL; + } + + 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_try_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; + net_nfc_error_e result; + net_nfc_target_type_e dev_type; + net_nfc_target_handle_s *handle; + + net_nfc_server_set_target_info((net_nfc_current_target_info_s *)user_data); + + g_free(user_data); + + target = net_nfc_server_get_target_info(); + + g_assert(target != NULL); + + handle = target->handle; + dev_type = target->devType; + + DEBUG_SERVER_MSG("connection type = [%d]", handle->connection_type); + 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; + } + net_nfc_server_llcp_start_registered_services(handle); + + net_nfc_server_p2p_discovered(handle); +} + +bool net_nfc_server_llcp_target_detected(void *info) +{ + if (net_nfc_server_controller_async_queue_push_force( + net_nfc_server_llcp_process, info) == FALSE) + { + DEBUG_ERR_MSG("can not push to controller thread"); + return false; + } + + return true; +} diff --git a/src/manager/net_nfc_server_manager.c b/src/manager/net_nfc_server_manager.c new file mode 100755 index 0000000..ae0952e --- /dev/null +++ b/src/manager/net_nfc_server_manager.c @@ -0,0 +1,439 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include "net_nfc_typedef_internal.h" +#include "net_nfc_debug_internal.h" +#include "net_nfc_controller_internal.h" + +#include "net_nfc_gdbus.h" +#include "net_nfc_server.h" +#include "net_nfc_server_common.h" +#include "net_nfc_server_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" +#include "net_nfc_server_route_table.h" +#include "net_nfc_addons.h" + +typedef struct _ManagerActivationData ManagerActivationData; + +struct _ManagerActivationData +{ + NetNfcGDbusManager *manager; + GDBusMethodInvocation *invocation; + gboolean is_active; +}; + + +static NetNfcGDbusManager *manager_skeleton = NULL; + +static net_nfc_error_e manager_active(void); + +static net_nfc_error_e 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 net_nfc_error_e manager_active(void) +{ + net_nfc_error_e result; + + if (net_nfc_controller_is_ready(&result) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_is_ready failed [%d]", result); + + return result; + } + + /* keep_SE_select_value */ + result = net_nfc_server_se_apply_se_current_policy(); + + /* load aids from database */ + net_nfc_server_route_table_load_db(); + + /* 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(); + + /* start addons */ + net_nfc_addons_init(); + + /* update route table */ + net_nfc_server_route_table_do_update(); + + /* current comsume issue for card only model */ + net_nfc_controller_set_screen_state(NET_NFC_SCREEN_OFF , &result); + + if (net_nfc_controller_configure_discovery( + NET_NFC_DISCOVERY_MODE_START, + NET_NFC_ALL_ENABLE, + &result) == true) + { + /* vconf on */ + if (vconf_set_bool(VCONFKEY_NFC_STATE, TRUE) != 0) + { + DEBUG_ERR_MSG("vconf_set_bool is failed"); + + result = NET_NFC_OPERATION_FAIL; + } + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_configure_discovery is failed, [%d]", result); + + net_nfc_server_controller_init(); + + net_nfc_server_force_polling_loop(); + + /* ADD TEMPORARY ABORT FOR DEBUG */ + //abort(); + } + + return result; +} + +/* reimplementation of net_nfc_service_deinit()*/ +static net_nfc_error_e manager_deactive(void) +{ + net_nfc_error_e result; + + if (net_nfc_controller_is_ready(&result) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_is_ready failed [%d]", result); + + return result; + } + + /* stop addons */ + net_nfc_addons_deinit(); + + + DEBUG_ERR_MSG("net_nfc_addons_deinit success!!!"); + + /* unregister all services */ + net_nfc_server_llcp_unregister_all(); + + /* keep_SE_select_value do not need to update vconf */ + result = net_nfc_server_se_apply_se_policy(SECURE_ELEMENT_POLICY_INVALID); + + if (net_nfc_controller_configure_discovery( + NET_NFC_DISCOVERY_MODE_STOP, + NET_NFC_ALL_DISABLE, + &result) == TRUE) + { + /* vconf off */ + if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0) + { + DEBUG_ERR_MSG("vconf_set_bool is failed"); + + result = NET_NFC_OPERATION_FAIL; + } + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_configure_discovery is failed, [%d]", result); + + /* ADD TEMPORARY ABORT FOR DEBUG */ + abort(); + } + + return result; +} + +static void manager_handle_active_thread_func(gpointer user_data) +{ + ManagerActivationData *data = (ManagerActivationData *)user_data; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->manager != NULL); + g_assert(data->invocation != NULL); + + if (data->is_active) + result = manager_active(); + else + result = manager_deactive(); + + if (result == NET_NFC_OK) { + INFO_MSG("nfc %s", data->is_active ? + "activated" : "deactivated"); + + net_nfc_gdbus_manager_emit_activated(data->manager, + data->is_active); + } else { + DEBUG_ERR_MSG("activation change failed, [%d]", result); + } + + net_nfc_gdbus_manager_complete_set_active(data->manager, + data->invocation, + result); + + g_object_unref(data->invocation); + g_object_unref(data->manager); + + g_free(data); + + /* shutdown process if it doesn't need */ + if (result == NET_NFC_OK && data->is_active == false && + net_nfc_server_gdbus_is_server_busy() == false) { + DEBUG_ERR_MSG("net_nfc_server_controller_deinit"); + net_nfc_server_controller_deinit(); + } +} + + +static gboolean manager_handle_set_active(NetNfcGDbusManager *manager, + GDBusMethodInvocation *invocation, + gboolean arg_is_active, + GVariant *smack_privilege, + gpointer user_data) +{ + ManagerActivationData *data = NULL; + gint 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::admin", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + DEBUG_SERVER_MSG("is_active %d", arg_is_active); + + data = g_try_new0(ManagerActivationData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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_and_block( + manager_handle_active_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->manager); + + g_free(data); + } + + net_nfc_gdbus_manager_complete_set_active(manager, invocation, result); + + return TRUE; +} + +static gboolean manager_handle_get_server_state(NetNfcGDbusManager *manager, + GDBusMethodInvocation *invocation, + GVariant *smack_privilege, + gpointer user_data) +{ + gint result = NET_NFC_OK; + guint32 state = NET_NFC_SERVER_IDLE; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto END; + } + + state = net_nfc_server_get_state(); + +END : + net_nfc_gdbus_manager_complete_get_server_state(manager, + invocation, + result, + state); + + return TRUE; +} + +/* server side */ +static void manager_active_thread_func(gpointer user_data) +{ + ManagerActivationData *data = + (ManagerActivationData *)user_data; + net_nfc_error_e result; + + g_assert(data != NULL); + + if (data->is_active) + result = manager_active(); + else + result = manager_deactive(); + if (result == NET_NFC_OK) + { + INFO_MSG("nfc %s", data->is_active ? + "activated" : "deactivated"); + + net_nfc_gdbus_manager_emit_activated(data->manager, + data->is_active); + } + else + { + DEBUG_ERR_MSG("activation change failed, [%d]", result); + } + + 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); + + net_nfc_server_manager_deinit(); + + 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) +{ + ManagerActivationData *data; + + if (manager_skeleton == NULL) + { + DEBUG_ERR_MSG("net_nfc_server_manager is not initialized"); + + return; + } + + DEBUG_SERVER_MSG("is_active %d", is_active); + + data = g_try_new0(ManagerActivationData, 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"); + + g_object_unref(data->manager); + g_free(data); + } +} + +bool net_nfc_server_manager_get_active() +{ + int value; + + if (vconf_get_bool(VCONFKEY_NFC_STATE, &value) < 0) + return false; + + return (!!value); +} diff --git a/src/manager/net_nfc_server_ndef.c b/src/manager/net_nfc_server_ndef.c new file mode 100755 index 0000000..b8a22ed --- /dev/null +++ b/src/manager/net_nfc_server_ndef.c @@ -0,0 +1,541 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_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_clear_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_clear_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 = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_new0(ReadData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->ndef = g_object_ref(ndef); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + + if (net_nfc_server_controller_async_queue_push( + ndef_read_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->ndef); + + g_free(data); + } + + net_nfc_gdbus_ndef_complete_read(ndef, invocation, result, + net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + return TRUE; +} + +static gboolean ndef_handle_write(NetNfcGDbusNdef *ndef, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + GVariant *arg_data, + GVariant *smack_privilege, + gpointer user_data) +{ + WriteData *data = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_new0(WriteData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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); + + if (net_nfc_server_controller_async_queue_push( + ndef_write_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + net_nfc_util_clear_data(&data->data); + + g_object_unref(data->invocation); + g_object_unref(data->ndef); + + g_free(data); + } + + net_nfc_gdbus_ndef_complete_write(ndef, invocation, result); + + return TRUE; +} + +static gboolean ndef_handle_make_read_only(NetNfcGDbusNdef *ndef, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + GVariant *smack_privilege, + gpointer user_data) +{ + MakeReadOnlyData *data = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_new0(MakeReadOnlyData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->ndef = g_object_ref(ndef); + data->invocation = g_object_ref(invocation); + data->handle = arg_handle; + + if (net_nfc_server_controller_async_queue_push( + ndef_make_read_only_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->ndef); + + g_free(data); + } + + net_nfc_gdbus_ndef_complete_make_read_only(ndef, invocation, result); + + return TRUE; +} + +static gboolean ndef_handle_format(NetNfcGDbusNdef *ndef, + GDBusMethodInvocation *invocation, + guint32 arg_handle, + GVariant *arg_key, + GVariant *smack_privilege, + gpointer user_data) +{ + FormatData *data = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_new0(FormatData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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); + + if (net_nfc_server_controller_async_queue_push( + ndef_format_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + net_nfc_util_clear_data(&data->key); + + g_object_unref(data->invocation); + g_object_unref(data->ndef); + + g_free(data); + } + + net_nfc_gdbus_ndef_complete_format(ndef, invocation, result); + + return TRUE; +} + +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; + } +} diff --git a/src/manager/net_nfc_server_p2p.c b/src/manager/net_nfc_server_p2p.c new file mode 100755 index 0000000..f1591c1 --- /dev/null +++ b/src/manager/net_nfc_server_p2p.c @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_manager_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_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( + 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_clear_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) +{ + gint result; + P2pSendData *data = NULL; + + 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_new0(P2pSendData, 1); + if(data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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); + + if (net_nfc_server_controller_async_queue_push( + p2p_send_data_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + net_nfc_util_clear_data(&data->data); + + g_object_unref(data->invocation); + g_object_unref(data->p2p); + + g_free(data); + } + + net_nfc_gdbus_p2p_complete_send(p2p, invocation, result); + + return TRUE; +} + + +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(gpointer user_data) +{ + INFO_MSG("====== p2p target detached ======"); + + /* release target information */ + net_nfc_server_free_target_info(); + + if (p2p_skeleton != NULL) + { + net_nfc_gdbus_p2p_emit_detached(p2p_skeleton); + } +} + +void net_nfc_server_p2p_discovered(net_nfc_target_handle_h handle) +{ + INFO_MSG("====== p2p target discovered ======"); + + if (p2p_skeleton == NULL) + { + DEBUG_ERR_MSG("p2p_skeleton is not initialized"); + + return; + } + + net_nfc_gdbus_p2p_emit_discovered(p2p_skeleton, + GPOINTER_TO_UINT(handle)); + + net_nfc_manager_util_play_sound(NET_NFC_TASK_START); +} + +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); + + net_nfc_manager_util_play_sound(NET_NFC_TASK_END); +} + +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_manager_util_play_sound(NET_NFC_TASK_END); + + net_nfc_util_clear_data(&data->data); + + g_object_unref(data->invocation); + g_object_unref(data->p2p); + + g_free(data); +} diff --git a/src/manager/net_nfc_server_process_handover.c b/src/manager/net_nfc_server_process_handover.c new file mode 100755 index 0000000..57dc3de --- /dev/null +++ b/src/manager/net_nfc_server_process_handover.c @@ -0,0 +1,2375 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_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" + + +typedef void (*_create_ch_msg_cb)(net_nfc_error_e result, + net_nfc_ch_message_s *msg, + 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; + net_nfc_ch_carrier_s *carrier; + 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 _create_config_context_t +{ + NET_NFC_CH_CONTEXT; + + _create_ch_msg_cb cb; + net_nfc_conn_handover_carrier_type_e current_type; + net_nfc_ch_message_s *message; + ndef_message_s *requester; /* for low power selector */ +} +_create_config_context_t; + +typedef struct _net_nfc_server_handover_process_config_context_t +{ + NET_NFC_CH_CONTEXT; + + net_nfc_server_handover_process_carrier_cb cb; +} +_process_config_context_t; + + + +static void _send_response(net_nfc_error_e result, + net_nfc_conn_handover_carrier_type_e carrier, + data_h ac_data, + void *user_param); + +static void _client_process(net_nfc_handover_context_t *context); + +static void _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 _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 _get_response_process(net_nfc_handover_context_t *context); + +static net_nfc_error_e _process_requester_carrier( + net_nfc_ch_carrier_s *carrier, + net_nfc_server_handover_process_carrier_cb cb, + void *user_param); + +static net_nfc_error_e _process_selector_carrier( + net_nfc_ch_carrier_s *carrier, + net_nfc_server_handover_process_carrier_cb cb, + void *user_param); +#if 0 +static int _net_nfc_server_handover_append_wifi_carrier_config( + _create_config_context_t *context); +#endif + +static net_nfc_error_e _create_requester_from_rawdata( + ndef_message_s **requestor, data_s *data); + +static net_nfc_error_e _create_requester_handover_message( + net_nfc_conn_handover_carrier_type_e type, + _create_ch_msg_cb cb, + void *user_param); + +static bool _check_hr_record_validation(ndef_message_s *message); + +static bool _check_hs_record_validation(ndef_message_s *message); + +static net_nfc_error_e _create_selector_handover_message( + net_nfc_conn_handover_carrier_type_e type, + _create_ch_msg_cb cb, + void *user_param); + +static int _iterate_create_carrier_configs(_create_config_context_t *context); + +static int _iterate_carrier_configs_to_next(_create_config_context_t *context); + +static int _iterate_carrier_configs_step(_create_config_context_t *context); + +static void _server_process(net_nfc_handover_context_t *context); + +#if 0 +static net_nfc_error_e +_net_nfc_server_handover_create_low_power_selector_message( + ndef_message_s *request_msg, + ndef_message_s *select_msg); +#endif +//////////////////////////////////////////////////////////////////////////// + +static void _send_response(net_nfc_error_e result, + net_nfc_conn_handover_carrier_type_e carrier, + data_h ac_data, + void *user_param) +{ + HandoverRequestData *handover_data = (HandoverRequestData *)user_param; + + g_assert(handover_data != NULL); + g_assert(handover_data->invocation != NULL); + g_assert(handover_data->handoverobj != NULL); + + net_nfc_gdbus_handover_complete_request( + handover_data->handoverobj, + handover_data->invocation, + result, + carrier, + net_nfc_util_gdbus_data_to_variant(ac_data)); + + if (handover_data->data) + { + net_nfc_util_free_data(handover_data->data); + } + + g_object_unref(handover_data->invocation); + g_object_unref(handover_data->handoverobj); + + g_free(handover_data); +} + +static net_nfc_error_e _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_init_data(data, length); + result = net_nfc_util_convert_ndef_message_to_rawdata(msg, data); + } + else + { + result = NET_NFC_INVALID_PARAM; + } + + return result; +} + +static void _bt_get_carrier_record_cb(net_nfc_error_e result, + net_nfc_ch_carrier_s *carrier, + void *user_param) +{ + _create_config_context_t *context = + (_create_config_context_t *)user_param; + + /* append record to ndef message */ + if (result == NET_NFC_OK) + { + net_nfc_ch_carrier_s *temp; + + net_nfc_util_duplicate_handover_carrier(&temp, carrier); + + result = net_nfc_util_append_handover_carrier(context->message, + temp); + if (result == 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); + } + + g_idle_add((GSourceFunc)_iterate_carrier_configs_to_next, + (gpointer)context); + } + + /* don't free context */ +} + +static void _bt_process_carrier_cb(net_nfc_error_e result, + net_nfc_conn_handover_carrier_type_e type, + data_s *data, + void *user_param) +{ + _process_config_context_t *context = + (_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("_bt_process_carrier_cb failed [%d]", + result); + } + + _net_nfc_util_free_mem(context); +} + +static void _wps_process_carrier_cb(net_nfc_error_e result, + net_nfc_conn_handover_carrier_type_e type, + data_s *data, + void *user_param) +{ + _process_config_context_t *context = + (_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("_wps_process_carrier_cb failed [%d]", + result); + } + + _net_nfc_util_free_mem(context); +} + +static net_nfc_error_e _get_carrier_record_by_priority_order( + net_nfc_ch_message_s *request, + net_nfc_ch_carrier_s **carrier) +{ + net_nfc_error_e result; + unsigned int carrier_count = 0; + + LOGD("[%s] START", __func__); + + if (request == NULL || carrier == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *carrier = NULL; + + result = net_nfc_util_get_handover_carrier_count(request, + &carrier_count); + if (result == 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; + *carrier == NULL && + priority < NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + priority++) + { + net_nfc_ch_carrier_s *temp; + + /* check each carrier record and create matched record */ + for (idx = 0; idx < carrier_count; idx++) + { + net_nfc_util_get_handover_carrier( + request, + idx, + &temp); + net_nfc_util_get_handover_carrier_type( + temp, &carrier_type); + if (carrier_type == priority) + { + DEBUG_SERVER_MSG("selected carrier type = [%d]", carrier_type); + + *carrier = temp; + result = NET_NFC_OK; + break; + } + } + } + } + else + { + DEBUG_ERR_MSG("net_nfc_util_get_handover_carrier_count failed, [%d]", result); + } + + LOGD("[%s] END", __func__); + + return result; +} + +static net_nfc_error_e _create_requester_from_rawdata( + ndef_message_s **requestor, data_s *data) +{ + net_nfc_error_e result; + ndef_message_s *temp = NULL; + + if (requestor == NULL) + return NET_NFC_NULL_PARAMETER; + + *requestor = NULL; + + result = net_nfc_util_create_ndef_message(&temp); + if (result == NET_NFC_OK) + { + result = net_nfc_util_convert_rawdata_to_ndef_message(data, + temp); + if (result == NET_NFC_OK) + { + if (_check_hr_record_validation(temp) == true) + { + *requestor = temp; + + result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("record is not valid or available"); + + net_nfc_util_free_ndef_message(temp); + result = NET_NFC_INVALID_PARAM; + } + } + else + { + DEBUG_ERR_MSG("net_nfc_util_convert_rawdata_to_ndef_message failed, [%d]", result); + + net_nfc_util_free_ndef_message(temp); + } + } else { + DEBUG_ERR_MSG("net_nfc_util_create_ndef_message failed [%d]", result); + } + + return result; +} + +static net_nfc_error_e _create_selector_from_rawdata( + ndef_message_s **selector, data_s *data) +{ + net_nfc_error_e result; + ndef_message_s *temp = NULL; + + if (selector == NULL) + return NET_NFC_NULL_PARAMETER; + + *selector = NULL; + + result = net_nfc_util_create_ndef_message(&temp); + if (result == NET_NFC_OK) + { + result = net_nfc_util_convert_rawdata_to_ndef_message(data, + temp); + if (result == NET_NFC_OK) + { + /* if record is not Hs record, then */ + if (_check_hs_record_validation(temp) == true) + { + *selector = temp; + result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("record is not valid or available"); + + net_nfc_util_free_ndef_message(temp); + result = NET_NFC_INVALID_PARAM; + } + } + else + { + DEBUG_ERR_MSG("net_nfc_util_convert_rawdata_to_ndef_message failed [%d]", result); + + net_nfc_util_free_ndef_message(temp); + } + } + else + { + DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", result); + } + + return result; +} + +static bool _check_hr_record_validation(ndef_message_s *message) +{ + unsigned int count; + net_nfc_ch_message_s *msg = NULL; + net_nfc_error_e result; + + LOGD("[%s] START", __func__); + + if (message == NULL) + return false; + + result = net_nfc_util_import_handover_from_ndef_message(message, &msg); + if (result != NET_NFC_OK) { + goto ERROR; + } + + if (msg->version != CH_VERSION) { + DEBUG_ERR_MSG("connection handover version is not matched"); + result = NET_NFC_INVALID_PARAM; + + goto ERROR; + } + + if (msg->type != NET_NFC_CH_TYPE_REQUEST) { + DEBUG_ERR_MSG("This is not connection handover request message"); + result = NET_NFC_INVALID_PARAM; + + goto ERROR; + } + + /* check cr record */ + if (msg->cr == 0) { + DEBUG_ERR_MSG("Collision resolution is wrong value"); + result = NET_NFC_INVALID_PARAM; + + goto ERROR; + } + + /* check alternative record count */ + result = net_nfc_util_get_handover_carrier_count(msg, &count); + if (result != NET_NFC_OK || count == 0) + { + DEBUG_ERR_MSG("there is no carrier reference"); + result = NET_NFC_INVALID_PARAM; + + goto ERROR; + } + + net_nfc_util_free_handover_message(msg); + + LOGD("[%s] END", __func__); + + return true; + +ERROR : + if (msg != NULL) { + net_nfc_util_free_handover_message(msg); + } + + LOGD("[%s] END", __func__); + + return false; +} + +static bool _check_hs_record_validation(ndef_message_s *message) +{ + net_nfc_ch_message_s *msg = NULL; + net_nfc_error_e result; + + LOGD("[%s] START", __func__); + + if (message == NULL) + return false; + + result = net_nfc_util_import_handover_from_ndef_message(message, &msg); + if (result != NET_NFC_OK) { + goto ERROR; + } + + if (msg->version != CH_VERSION) { + DEBUG_ERR_MSG("connection handover version is not matched"); + result = NET_NFC_INVALID_PARAM; + + goto ERROR; + } + + if (msg->type != NET_NFC_CH_TYPE_SELECT) { + DEBUG_ERR_MSG("This is not connection handover select message"); + result = NET_NFC_INVALID_PARAM; + + goto ERROR; + } + + net_nfc_util_free_handover_message(msg); + + LOGD("[%s] END", __func__); + + return true; + +ERROR : + if (msg != NULL) { + net_nfc_util_free_handover_message(msg); + } + + LOGD("[%s] END", __func__); + + return false; +} + +static int _iterate_carrier_configs_step(_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->message, + context->user_param); + } + + if (context->message != NULL) + { + net_nfc_util_free_handover_message(context->message); + } + + _net_nfc_util_free_mem(context); + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} + +#if 0 +static int _net_nfc_server_handover_append_wifi_carrier_config( + _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)_iterate_carrier_configs_to_next, + (gpointer)context); + break; + + default : + break; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} +#endif + +static int _iterate_carrier_configs_to_next(_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)_iterate_create_carrier_configs, + (gpointer)context); + } + else + { + DEBUG_ERR_MSG("context->result is error [%d]", context->result); + + g_idle_add((GSourceFunc)_iterate_carrier_configs_step, + (gpointer)context); + } + + return 0; +} + +static int _iterate_create_carrier_configs(_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( + _bt_get_carrier_record_cb, + context); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS]"); + g_idle_add((GSourceFunc)_iterate_carrier_configs_step, + (gpointer)context); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P]"); + g_idle_add((GSourceFunc)_iterate_carrier_configs_step, + (gpointer)context); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]"); + g_idle_add((GSourceFunc)_iterate_carrier_configs_step, + (gpointer)context); + break; + + default : + DEBUG_MSG("[unknown : %d]", context->current_type); + g_idle_add((GSourceFunc)_iterate_carrier_configs_step, + (gpointer)context); + break; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} + +static net_nfc_error_e _create_requester_handover_message( + net_nfc_conn_handover_carrier_type_e type, + _create_ch_msg_cb cb, + void *user_param) +{ + net_nfc_error_e result = NET_NFC_OK; + _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; + + result = net_nfc_util_create_handover_message( + &context->message); + if (result == NET_NFC_OK) { + net_nfc_util_set_handover_message_type(context->message, + NET_NFC_CH_TYPE_REQUEST); + + /* append carrier record */ + g_idle_add((GSourceFunc)_iterate_create_carrier_configs, + (gpointer)context); + } else { + DEBUG_ERR_MSG("net_nfc_util_create_handover_message failed, [%d]", result); + } + } + else + { + DEBUG_ERR_MSG("alloc failed"); + + result = NET_NFC_ALLOC_FAIL; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return result; +} + +static net_nfc_error_e _create_selector_handover_message( + net_nfc_conn_handover_carrier_type_e type, + _create_ch_msg_cb cb, + void *user_param) +{ + net_nfc_error_e result = NET_NFC_OK; + _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; + + result = net_nfc_util_create_handover_message( + &context->message); + if (result == NET_NFC_OK) { + net_nfc_util_set_handover_message_type(context->message, + NET_NFC_CH_TYPE_SELECT); + + /* append carrier record */ + g_idle_add((GSourceFunc)_iterate_create_carrier_configs, + (gpointer)context); + } else { + DEBUG_ERR_MSG("net_nfc_util_create_handover_message failed, [%d]", result); + } + } + 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_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; +} +#endif + +static net_nfc_error_e _process_requester_carrier(net_nfc_ch_carrier_s *carrier, + net_nfc_server_handover_process_carrier_cb cb, + void *user_param) +{ + net_nfc_error_e result = NET_NFC_OK; + _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_handover_carrier_type(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_prepare_pairing( + carrier, + _bt_process_carrier_cb, + context); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS]"); + _net_nfc_util_free_mem(context); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P]"); + _net_nfc_util_free_mem(context); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]"); + 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; +} + +static net_nfc_error_e _process_selector_carrier(net_nfc_ch_carrier_s *carrier, + net_nfc_server_handover_process_carrier_cb cb, + void *user_param) +{ + net_nfc_error_e result = NET_NFC_OK; + _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_handover_carrier_type(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_do_pairing( + carrier, + _bt_process_carrier_cb, + context); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS]"); + net_nfc_server_handover_wps_do_connect( + carrier, + _wps_process_carrier_cb, + 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 = _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 = _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_clear_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 = _convert_ndef_message_to_data( + selector, + &data); + + if (result == NET_NFC_OK) + { + /* process message */ + _process_requester_carrier( + 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_clear_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 = + _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 = _create_selector_handover_message( + 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 = + _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 _select_carrier_record(net_nfc_ch_message_s *request, + net_nfc_ch_carrier_s **carrier) +{ + net_nfc_error_e result; + uint32_t count; + + *carrier = NULL; + + /* get requester message */ + result = net_nfc_util_get_handover_carrier_count(request, &count); + if (result == NET_NFC_OK) + { + if (1/* power state */ || count == 1) + { + net_nfc_ch_carrier_s *temp; + + /* fill alternative carrier information */ + result = _get_carrier_record_by_priority_order(request, + &temp); + if (result == NET_NFC_OK) + { + net_nfc_util_duplicate_handover_carrier(carrier, + temp); + } + else + { + DEBUG_ERR_MSG("_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_handover_carrier_count failed [%d]", result); + } + + return result; +} + +#endif + +static void _create_carrier_configs_2_cb(net_nfc_error_e result, + net_nfc_ch_message_s *selector, + void *user_param) +{ + net_nfc_handover_context_t *context = + (net_nfc_handover_context_t *)user_param; + + DEBUG_SERVER_MSG("_server_create_carrier_config_cb result [%d]", result); + + if (context == NULL) + { + return; + } + + context->result = result; + + if (result == NET_NFC_OK) { + ndef_message_s *msg; + + net_nfc_util_export_handover_to_ndef_message(selector, &msg); + + result = _convert_ndef_message_to_data(msg, + &context->data); + + DEBUG_SERVER_MSG("selector message created, length [%d]", + context->data.length); + + context->state = NET_NFC_LLCP_STEP_03; + + net_nfc_util_free_ndef_message(msg); + } + else + { + DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector_msg failed [%d]", + result); + + context->state = NET_NFC_MESSAGE_LLCP_ERROR; + } + + _get_response_process(context); +} + +static void _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("_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_util_init_data(&context->data, data->length); + memcpy(context->data.buffer, data->buffer, context->data.length); + + _server_process(context); +} + +static void _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 = _create_selector_handover_message(context->type, + _create_carrier_configs_2_cb, + context); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("_create_selector_carrier_config failed [%d]", result); + } + break; + + case NET_NFC_LLCP_STEP_03 : + DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03"); + + result = _process_requester_carrier(context->carrier, + _process_carrier_record_2_cb, + context); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("_process_requester_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 _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 = _create_requester_from_rawdata(&request, data); + if (result == NET_NFC_OK) + { + net_nfc_ch_message_s *msg; + net_nfc_ch_carrier_s *carrier; + + net_nfc_util_import_handover_from_ndef_message(request, &msg); + + result = _select_carrier_record(msg, &carrier); + 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 = (void *)handle; + context->user_param = user_param; + context->state = NET_NFC_LLCP_STEP_02; + net_nfc_util_get_handover_carrier_type(carrier, + &context->type); + + net_nfc_util_duplicate_handover_carrier( + &context->carrier, carrier); + + _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_handover_message(msg); + 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 _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("_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; + } + + _server_process(context); +} + +static void _server_create_carrier_config_cb(net_nfc_error_e result, + net_nfc_ch_message_s *selector, + void *user_param) +{ + net_nfc_handover_context_t *context = + (net_nfc_handover_context_t *)user_param; + + DEBUG_SERVER_MSG("_server_create_carrier_config_cb, result [%d]", result); + + if (context == NULL) + { + return; + } + + if (result == NET_NFC_OK) + { + ndef_message_s *msg; + + result = net_nfc_util_export_handover_to_ndef_message(selector, + &msg); + if (result == NET_NFC_OK) { + result = _convert_ndef_message_to_data(msg, + &context->data); + if (result == NET_NFC_OK) { + DEBUG_SERVER_MSG("selector message created, length [%d]", + context->data.length); + + context->state = NET_NFC_LLCP_STEP_03; + context->result = result; + } else { + DEBUG_ERR_MSG("_convert_ndef_message_to_data failed [%d]", result); + + context->state = NET_NFC_MESSAGE_LLCP_ERROR; + context->result = result; + } + + net_nfc_util_free_ndef_message(msg); + } else { + DEBUG_ERR_MSG("net_nfc_util_export_handover_to_ndef_message failed [%d]", result); + + context->state = NET_NFC_MESSAGE_LLCP_ERROR; + context->result = result; + } + } + else + { + DEBUG_ERR_MSG("_create_selector_msg failed [%d]", result); + + context->state = NET_NFC_MESSAGE_LLCP_ERROR; + context->result = result; + } + + _server_process(context); +} + +static void _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("_server_recv_cb, socket [%x], result [%d]", socket, result); + + context->result = result; + + if (result == NET_NFC_OK) + { + net_nfc_util_append_data(&context->data, data); + + result = net_nfc_util_check_ndef_message_rawdata(&context->data); + if (result == NET_NFC_OK) { + /* message complete */ + result = _create_requester_from_rawdata(&request, &context->data); + if (result == NET_NFC_OK) + { + net_nfc_ch_message_s *msg; + net_nfc_ch_carrier_s *carrier; + + net_nfc_util_import_handover_from_ndef_message(request, + &msg); + + if (_select_carrier_record(msg, &carrier) == + NET_NFC_OK) + { + net_nfc_util_get_handover_carrier_type(carrier, + &context->type); + net_nfc_util_duplicate_handover_carrier( + &context->carrier, carrier); + + context->state = NET_NFC_LLCP_STEP_02; + } + else + { + /* low power */ + context->state = NET_NFC_LLCP_STEP_06; + } + + net_nfc_util_free_handover_message(msg); + net_nfc_util_free_ndef_message(request); + } + else + { + DEBUG_ERR_MSG("_create_requester_from_rawdata failed [%d]",result); + + context->state = NET_NFC_MESSAGE_LLCP_ERROR; + } + } else if (result == NET_NFC_BUFFER_TOO_SMALL) { + DEBUG_SERVER_MSG("incomplete ndef message, receive again"); + + context->state = NET_NFC_LLCP_STEP_01; + } else { + DEBUG_ERR_MSG("invalid handover message, [%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; + } + + _server_process(context); +} + +static void _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("_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_clear_data(&context->data); + net_nfc_util_free_handover_carrier(context->carrier); + context->carrier = NULL; + } + else + { + DEBUG_ERR_MSG("net_nfc_server_llcp_simple_send failed [%d]", + result); + context->state = NET_NFC_MESSAGE_LLCP_ERROR; + } + + _server_process(context); +} + +static void _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, + _handover_server_recv_cb, + context); + break; + + case NET_NFC_LLCP_STEP_02 : + DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02"); + + net_nfc_util_clear_data(&context->data); + + context->result = _create_selector_handover_message( + context->type, + _server_create_carrier_config_cb, + context); + if (context->result != NET_NFC_OK) + { + DEBUG_ERR_MSG("_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 = _process_requester_carrier( + context->carrier, + _server_process_carrier_record_cb, + context); + if (context->result != NET_NFC_OK) + { + DEBUG_ERR_MSG("_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, + _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); + + net_nfc_util_clear_data(&context->data); + + /* restart?? */ + break; + + default : + DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??"); + /* TODO */ + break; + } +} + +static void _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_handover_carrier(context->carrier); + net_nfc_util_clear_data(&context->data); + _net_nfc_util_free_mem(user_param); +} + +static void _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, + _server_error_cb, + accept_context); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_server_llcp_simple_accept failed, [%d]", + result); + + goto ERROR; + } + + _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( + _get_response_cb, NULL); + + /* start default handover server */ + result = net_nfc_server_llcp_simple_server(handle, CH_SAN, CH_SAP, + _server_incomming_cb, + _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( + _get_response_cb, NULL); + + /* start default handover server */ + result = net_nfc_server_llcp_simple_server(handle, + CH_SAN, CH_SAP, + _server_incomming_cb, + _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 _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("_server_process_carrier_record_cb, result [%d]", result); + + context->result = result; + + net_nfc_util_clear_data(&context->data); + + if (result == NET_NFC_OK) + { + net_nfc_util_init_data(&context->data, data->length); + memcpy(context->data.buffer, data->buffer, data->length); + + context->state = NET_NFC_LLCP_STEP_RETURN; + } + else + { + context->state = NET_NFC_MESSAGE_LLCP_ERROR; + } + + _client_process(context); +} + +static void _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) + { + net_nfc_util_append_data(&context->data, data); + + result = net_nfc_util_check_ndef_message_rawdata( + &context->data); + if (result == NET_NFC_OK) { + ndef_message_s *selector; + + result = _create_selector_from_rawdata(&selector, + &context->data); + if (result == NET_NFC_OK) + { + net_nfc_ch_message_s *msg; + net_nfc_ch_carrier_s *carrier; + + net_nfc_util_import_handover_from_ndef_message(selector, + &msg); + + result = _get_carrier_record_by_priority_order( + msg, &carrier); + if (result == NET_NFC_OK) + { + net_nfc_util_duplicate_handover_carrier( + &context->carrier, carrier); + + 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; + } + + net_nfc_util_free_handover_message(msg); + net_nfc_util_free_ndef_message(selector); + } + else + { + DEBUG_ERR_MSG("_create_selector_from_rawdata failed, [%d]", result); + + context->state = NET_NFC_STATE_ERROR; + } + } else if (result == NET_NFC_BUFFER_TOO_SMALL) { + DEBUG_SERVER_MSG("incomplete ndef message, receive again"); + + context->state = NET_NFC_LLCP_STEP_03; + } else { + DEBUG_ERR_MSG("invalid handover message, [%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_STATE_ERROR; + } + + _client_process(context); +} + +static void _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_clear_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; + } + + _client_process(context); +} + +static void _client_create_carrier_configs_cb(net_nfc_error_e result, + net_nfc_ch_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) + { + ndef_message_s *message; + + net_nfc_util_export_handover_to_ndef_message(msg, &message); + + result = _convert_ndef_message_to_data(message, &context->data); + if (result == NET_NFC_OK) + { + DEBUG_MSG_PRINT_BUFFER(context->data.buffer, context->data.length); + + context->state = NET_NFC_LLCP_STEP_02; + } + else + { + DEBUG_ERR_MSG("_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; + } + + _client_process(context); +} + + +//////////////////////////////////////////////////////////////////////////////// +static void _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"); + + result = _create_requester_handover_message(context->type, + _client_create_carrier_configs_cb, + context); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("_create_requester_carriers 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, + _client_send_cb, + context); + + net_nfc_util_clear_data(&context->data); + 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, + _client_recv_cb, + context); + break; + + case NET_NFC_LLCP_STEP_04 : + DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04"); + + result = _process_selector_carrier(context->carrier, + _client_process_carrier_record_cb, + context); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("_process_requester_carrier_record failed [%d]", result); + } + break; + + case NET_NFC_LLCP_STEP_RETURN : + DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN"); + + /* complete and invoke callback */ + _send_response(context->result, context->type, &context->data, + context->user_param); + + net_nfc_util_clear_data(&context->data); + + /* signal */ + + net_nfc_util_free_handover_carrier(context->carrier); + _net_nfc_util_free_mem(context); + break; + + case NET_NFC_STATE_ERROR : + default : + DEBUG_ERR_MSG("NET_NFC_STATE_ERROR"); + + _send_response(context->result, context->type, NULL, + context->user_param); + break; + } +} + +static void _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; + + _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 _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) + { + _send_response(result, + NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, + NULL, + user_param); + } + + 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, + _client_connected_cb, + _client_error_cb, + user_data); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client failed, [%d]", result); + } + + return result; +} diff --git a/src/manager/net_nfc_server_process_npp.c b/src/manager/net_nfc_server_process_npp.c new file mode 100755 index 0000000..ffac872 --- /dev/null +++ b/src/manager/net_nfc_server_process_npp.c @@ -0,0 +1,784 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_controller_internal.h" +#include "net_nfc_app_util_internal.h" +#include "net_nfc_server_p2p.h" +#include "net_nfc_server_llcp.h" +#include "net_nfc_server_process_npp.h" + + +typedef struct _net_nfc_npp_entry_t +{ + uint8_t op; + uint32_t length; + uint8_t data[0]; +} +__attribute__ ((packed)) net_nfc_npp_entry_t; + +typedef struct _net_nfc_npp_msg_t +{ + uint8_t version; + uint32_t entry_count; + net_nfc_npp_entry_t entry[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; + size_t miu; + data_s data; + size_t data_offset; + 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_ENTRY_HEADER_LEN (sizeof(net_nfc_npp_entry_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_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) +{ + size_t length = NPP_HEADER_LEN; + net_nfc_npp_msg_t *msg; + + if (data != NULL) + length += NPP_ENTRY_HEADER_LEN + data->length; + + net_nfc_util_init_data(message, length); + + msg = (net_nfc_npp_msg_t *)message->buffer; + msg->version = NPP_VERSION; + + if (data != NULL) + { + net_nfc_npp_entry_t *entity; + + DEBUG_SERVER_MSG("data->length [%d]", data->length); + + msg->entry_count = htonl(1); + + entity = msg->entry; + + 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->entry_count = 0; + } + + return NET_NFC_OK; +} + +static void __npp_server_received_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 *)user_data; + size_t length; + + length = MIN(data->length, + npp_data->data.length - npp_data->data_offset); + + memcpy(npp_data->data.buffer + npp_data->data_offset, + data->buffer, length); + + npp_data->data_offset += length; + + if (npp_data->data_offset == npp_data->data.length) { + INFO_MSG("receive message complete, length [%d]", npp_data->data.length); + + /* launch */ + if (npp_data->callback) { + npp_data->callback(result, &npp_data->data, + npp_data->user_data); + } + +// if (length < data->length) { +// /* start next entry */ +// } + } else { + INFO_MSG("fragmented message, read [%d], expected [%d]", npp_data->data_offset, npp_data->data.length); + + /* receive next fragment */ + result = net_nfc_server_llcp_simple_receive(npp_data->handle, + npp_data->socket, + __npp_server_received_cb, + npp_data); + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_server_llcp_simple_receive failed, [%d]", result); + + if (npp_data->callback) + npp_data->callback(result, NULL, + npp_data->user_data); + } + } +} + +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 = (NppData *)user_data; + + net_nfc_npp_msg_t *message; + net_nfc_npp_entry_t *entry; + + size_t length; + size_t entry_count; +// size_t i; + + if (npp_data == NULL) + return; + + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("receive failed [%d]", result); + + goto ERR; + } + + if (data == NULL || data->buffer == NULL || data->length == 0) + { + DEBUG_ERR_MSG("Wrong data"); + + result = NET_NFC_INVALID_PARAM; + + goto ERR; + } + + if (data->length < NPP_HEADER_LEN) + { + DEBUG_ERR_MSG("too short data, length [%d]", data->length); + + result = NET_NFC_INVALID_PARAM; + + goto ERR; + } + + message = (net_nfc_npp_msg_t *)data->buffer; + + 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); + + result = NET_NFC_NOT_SUPPORTED; + + goto ERR; + } + + entry_count = htonl(message->entry_count); + + if (entry_count > NPP_NDEF_ENTRY) + { + DEBUG_ERR_MSG("too many entries, support only one entry. count [%d]", + message->entry_count); + + result = NET_NFC_INVALID_PARAM; + + goto ERR; + } + + /* FIXME : ..... multi-entry is useless... I don't want to implement. */ +// for (i = 0; i < entry_count; i++) + { +// entry = (message->entry + i); + entry = message->entry; + + if (entry->op != NPP_ACTION_CODE) { + DEBUG_ERR_MSG("not supported action code, [0x%02x]", + entry->op); + + result = NET_NFC_INVALID_PARAM; + + goto ERR; + } + + length = htonl(entry->length); + + DEBUG_SERVER_MSG("action code [0x%02x], length [%d]", + entry->op, length); + + if (length > 0) + { + data_s temp; + + /* buffer create */ + net_nfc_util_init_data(&npp_data->data, length); + npp_data->data_offset = 0; + + temp.buffer = entry->data; + temp.length = data->length - + NPP_HEADER_LEN - NPP_ENTRY_HEADER_LEN; + + __npp_server_received_cb(result, handle, + socket, &temp, user_data); + } else { + DEBUG_ERR_MSG("invalid ndef length"); + + result = NET_NFC_INVALID_PARAM; + + goto ERR; + } + } + + return; + +ERR : + if (npp_data->callback) { + npp_data->callback(result, NULL, npp_data->user_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) + { + DEBUG_ERR_MSG("net_nfc_server_llcp_simple_receive failed, [%d]", result); + + if (npp_data->callback) + npp_data->callback(result, NULL, npp_data->user_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 *)user_data; + NppData *accept_data = NULL; + + 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); + + goto ERR; + } + + /* 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("net_nfc_server_llcp_simple_accept failed, [%d]", result); + + goto ERR; + } + + DEBUG_SERVER_MSG("socket [%x] accepted.. waiting for request message", + socket); + + npp_server_process(accept_data); + + return; + +ERR : + if (npp_data->callback) + npp_data->callback(result, NULL, npp_data->user_data); + + if (accept_data != NULL) { + g_free(accept_data); + } +} + +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 = (NppData *)user_data; + + if (npp_data == NULL) + return; + + if (npp_data->data_offset < npp_data->data.length) { + INFO_MSG("fragmented message, sent [%d], total [%d]", npp_data->data_offset, npp_data->data.length); + + npp_client_process(npp_data); + } else { + DEBUG_SERVER_MSG("send complete... [%d] length [%d]", result, npp_data->data.length); + + if (npp_data->callback) { + npp_data->callback(result, NULL, npp_data->user_data); + } + } +} + +/* FIXME : fragment */ +static void npp_client_process(NppData *npp_data) +{ + net_nfc_error_e result; + data_s data; + size_t length; + + if (npp_data == NULL) + return; + + length = MIN(npp_data->data.length - npp_data->data_offset, + npp_data->miu); + data.buffer = npp_data->data.buffer + npp_data->data_offset; + data.length = length; + npp_data->data_offset += length; + + /* 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("net_nfc_server_llcp_simple_send failed [%d]", result); + + goto ERR; + } + + return; + +ERR : + if (npp_data->callback) { + npp_data->callback(result, NULL, npp_data->user_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) +{ + NppData *npp_data = (NppData *)user_data; + + if (npp_data == NULL) + return; + + if (result == NET_NFC_OK) { + /*start npp client */ + DEBUG_SERVER_MSG("socket [%x] connected, send request message.", + socket); + npp_data->socket = socket; + + npp_client_process(npp_data); + } else { + DEBUG_ERR_MSG("connect socket failed, [%d]", result); + + if (npp_data->callback) + npp_data->callback(result, NULL, npp_data->user_data); + + net_nfc_util_clear_data(&npp_data->data); + g_free(npp_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) +{ + 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); + + net_nfc_util_clear_data(&npp_data->data); + 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; + + 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("net_nfc_server_llcp_simple_server failed [%d]", result); + + 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;; + NppData *npp_data; + + if (handle == NULL || data == NULL || data->buffer == NULL) { + DEBUG_ERR_MSG("handle is NULL"); + + return NET_NFC_NULL_PARAMETER; + } + + npp_data = g_try_new0(NppData, 1); + if (npp_data == NULL) { + DEBUG_ERR_MSG("alloc failed"); + + return NET_NFC_ALLOC_FAIL; + } + + npp_data->handle = handle; + npp_data->callback = callback; + npp_data->user_data = user_data; + /* FIXME */ + npp_data->miu = net_nfc_server_llcp_get_miu(); + + npp_create_message(data, &npp_data->data); + npp_data->data_offset = 0; + + result = net_nfc_server_llcp_simple_client(handle, + san, + sap, + npp_connected_cb, + npp_socket_error_cb, + npp_data); + if (result == NET_NFC_OK) { + 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); + } + } else { + DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client failed, [%d]", result); + + if (npp_data->callback) + { + npp_data->callback(result, NULL, npp_data->user_data); + } + + net_nfc_util_clear_data(&npp_data->data); + g_free(npp_data); + } + + 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; + + 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 || data->length == 0) + { + 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; +} diff --git a/src/manager/net_nfc_server_process_snep.c b/src/manager/net_nfc_server_process_snep.c new file mode 100755 index 0000000..c28d18e --- /dev/null +++ b/src/manager/net_nfc_server_process_snep.c @@ -0,0 +1,2161 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "net_nfc_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_tag.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 * 100) + +#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; + + for(list = g_list_first(list); list != NULL; list = g_list_next(list)) + { + net_nfc_server_cb_data_t *cb_data = + (net_nfc_server_cb_data_t *)list->data; + + if(list->data == NULL) + continue; + + 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_init_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_clear_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 0 /* snep unlimited */ + 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; + } +#endif + 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_init_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; + + /* 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); + result = NET_NFC_OK; + } else { + result = NET_NFC_ALLOC_FAIL; + + if (cb != NULL) { + cb(result, -1, NULL, user_param); + } + } + + 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; + + /* 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); + result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("_net_nfc_server_snep_create_send_context failed"); + + result = NET_NFC_ALLOC_FAIL; + + if (cb != NULL) { + cb(result, type, NULL, user_param); + } + } + + 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_init_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_clear_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 0 /* temp code */ + if (context->cb != NULL) + { + context->cb((net_nfc_snep_handle_h)context, + context->result, + context->type, + NULL, + context->user_param); + } +#endif + /* 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_clear_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_clear_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_clear_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("snep 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); + } +} + +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; + } + + if (net_nfc_server_target_connected(handle) == false) { + return NET_NFC_NOT_CONNECTED; + } + + _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; + } + + if (net_nfc_server_target_connected(context->handle) == false) { + return NET_NFC_NOT_CONNECTED; + } + + 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_clear_data(&context->data); + + if (data != NULL) + { + context->type = SNEP_RESP_SUCCESS; + + if (net_nfc_util_init_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_clear_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_init_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_client_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_clear_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; + } + + if (net_nfc_server_target_connected(handle) == false) { + return NET_NFC_NOT_CONNECTED; + } + + _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_clear_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; + } + + if (net_nfc_server_target_connected(context->handle) == false) { + return NET_NFC_NOT_CONNECTED; + } + + /* check type */ + _net_nfc_util_alloc_mem(job, sizeof(*job)); + if (job != NULL) + { + net_nfc_util_init_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); + 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) + { + result = 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_clear_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_error_e result; + + _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_init_data(&context->data, data->length); + if (context->data.buffer != NULL) + { + memcpy(context->data.buffer, data->buffer, + data->length); + } + /* start default snep client, register your callback */ + result = net_nfc_server_snep_client(handle, + SNEP_SAN, + SNEP_SAP, + _net_nfc_server_default_client_connected_cb_, + context); + + if (result != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_server_snep_client failed, [%d]", + result); + if (context->data.buffer != NULL) + { + net_nfc_util_clear_data(&context->data); + } + _net_nfc_util_free_mem(context); + } + return result; + } + 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; +} diff --git a/src/manager/net_nfc_server_route_table.c b/src/manager/net_nfc_server_route_table.c new file mode 100755 index 0000000..d6dfb8f --- /dev/null +++ b/src/manager/net_nfc_server_route_table.c @@ -0,0 +1,1695 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "vconf.h" + +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_controller_internal.h" +#include "net_nfc_server.h" +#include "net_nfc_server_se.h" +#include "net_nfc_server_vconf.h" +#include "net_nfc_server_route_table.h" + +#define PRINT_TABLE + +/* route table database */ +#define NFC_ROUTE_TABLE_DB_FILE "/opt/usr/data/nfc-manager-daemon/.route_table.db" +#define NFC_ROUTE_TABLE_DB_TABLE "route_table" + +typedef void (*_iterate_db_cb)(const char *package, net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, const char *aid, + bool unlock, int power, bool manifest, void *user_data); + +static sqlite3 *db; +static sqlite3_stmt *current_stmt; + +static net_nfc_error_e __route_table_add_aid(const char *id, + const char *package, net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + const char *aid, bool unlock, int power, bool manifest); + +static net_nfc_error_e __route_table_del_aid(const char *id, + const char *package, const char *aid, bool force); + +static bool __is_table_existing(const char *table) +{ + bool result; + char *sql; + int ret; + + sql = sqlite3_mprintf("SELECT count(*) FROM sqlite_master WHERE type='table' AND name ='%s';", table); + if (sql != NULL) { + sqlite3_stmt *stmt = NULL; + + ret = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL); + if (ret == SQLITE_OK) { + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + int count; + + count = sqlite3_column_int(stmt, 0); + if (count > 0) { + result = true; + } else { + result = false; + } + } else { + DEBUG_ERR_MSG("sqlite3_step failed, [%d:%s]", ret, sqlite3_errmsg(db)); + + result = false; + } + + sqlite3_finalize(stmt); + } else { + DEBUG_ERR_MSG("sqlite3_prepare_v2 failed, [%d:%s]", ret, sqlite3_errmsg(db)); + + result = false; + } + + sqlite3_free(sql); + } else { + DEBUG_ERR_MSG("sqlite3_mprintf failed"); + + result = false; + } + + return result; +} + +static void __create_table() +{ + int ret; + char *sql; + + sql = sqlite3_mprintf("CREATE TABLE %s(idx INTEGER PRIMARY KEY, package TEXT NOT NULL, se_type INTEGER, category INTEGER, aid TEXT NOT NULL COLLATE NOCASE, unlock INTEGER, power INTEGER, manifest INTEGER);", NFC_ROUTE_TABLE_DB_TABLE); + if (sql != NULL) { + char *error = NULL; + + ret = sqlite3_exec(db, sql, NULL, NULL, &error); + if (ret != SQLITE_OK) { + DEBUG_ERR_MSG("sqlite3_exec() failed, [%d:%s]", ret, error); + + sqlite3_free(error); + } + + sqlite3_free(sql); + } else { + DEBUG_ERR_MSG("sqlite3_mprintf failed"); + } +} + +static void __prepare_table() +{ + if (__is_table_existing(NFC_ROUTE_TABLE_DB_TABLE) == false) { + __create_table(); + } +} + +static void __initialize_db() +{ + int result; + char *error = NULL; + + if (db == NULL) { + result = sqlite3_open_v2(NFC_ROUTE_TABLE_DB_FILE, &db, + SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, + NULL); + if (result != SQLITE_OK) { + DEBUG_ERR_MSG("sqlite3_open_v2 failed, [%d]", result); + + goto ERR; + } + + /* Enable persist journal mode */ + result = sqlite3_exec(db, "PRAGMA journal_mode = PERSIST", + NULL, NULL, &error); + if (result != SQLITE_OK) { + DEBUG_ERR_MSG("Fail to change journal mode: %s", error); + sqlite3_free(error); + + goto ERR; + } + + __prepare_table(); + } + + return; + +ERR : + if (db != NULL) { + result = sqlite3_close(db); + if (result == SQLITE_OK) { + db = NULL; + } else { + DEBUG_ERR_MSG("sqlite3_close failed, [%d]", result); + } + } +} + +static void __finalize_db() +{ + int result; + + if (db != NULL) { + if (current_stmt != NULL) { + result = sqlite3_finalize(current_stmt); + if (result != SQLITE_OK) { + DEBUG_ERR_MSG("sqlite3_finalize failed, [%d]", result); + } + } + + result = sqlite3_close(db); + if (result == SQLITE_OK) { + db = NULL; + } else { + DEBUG_ERR_MSG("sqlite3_close failed, [%d]", result); + } + } +} + +static void __iterate_db(_iterate_db_cb cb, void *user_data) +{ + char *sql; + + if (cb == NULL) { + return; + } + + sql = sqlite3_mprintf("SELECT * FROM %s;", NFC_ROUTE_TABLE_DB_TABLE); + if (sql != NULL) { + sqlite3_stmt *stmt = NULL; + int ret; + + ret = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL); + if (ret == SQLITE_OK) { + const char *package; + net_nfc_se_type_e se_type; + net_nfc_card_emulation_category_t category; + const char *aid; + bool unlock; + int power; + bool manifest; + + while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) { + package = (const char *)sqlite3_column_text(stmt, 1); + se_type = (net_nfc_se_type_e)sqlite3_column_int(stmt, 2); + category = (net_nfc_card_emulation_category_t)sqlite3_column_int(stmt, 3); + aid = (const char *)sqlite3_column_text(stmt, 4); + unlock = (bool)sqlite3_column_int(stmt, 5); + power = sqlite3_column_int(stmt, 6); + manifest = (bool)sqlite3_column_int(stmt, 7); + + cb(package, se_type, category, aid, unlock, power, manifest, user_data); + } + + sqlite3_finalize(stmt); + } else { + DEBUG_ERR_MSG("sqlite3_prepare_v2 failed, [%d:%s]", ret, sqlite3_errmsg(db)); + } + + sqlite3_free(sql); + } else { + DEBUG_ERR_MSG("sqlite3_mprintf failed"); + } +} + +static net_nfc_error_e __insert_into_db(const char *package, net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, const char *aid, + bool unlock, int power, bool manifest) +{ + net_nfc_error_e result; + char *sql; + + sql = sqlite3_mprintf("INSERT INTO %s (package, se_type, category, aid, unlock, power, manifest) values(?, %d, %d, ?, %d, %d, %d);", + NFC_ROUTE_TABLE_DB_TABLE, se_type, category, (int)unlock, power, (int)manifest); + if (sql != NULL) { + sqlite3_stmt *stmt = NULL; + int ret; + + ret = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL); + if (ret == SQLITE_OK) { + ret = sqlite3_bind_text(stmt, 1, package, + strlen(package), SQLITE_STATIC); + if (ret != SQLITE_OK) { + DEBUG_ERR_MSG("sqlite3_bind_text failed, [%d]", ret); + + result = NET_NFC_OPERATION_FAIL; + goto END; + } + + ret = sqlite3_bind_text(stmt, 2, aid, + strlen(aid), SQLITE_STATIC); + if (ret != SQLITE_OK) { + DEBUG_ERR_MSG("sqlite3_bind_text failed, [%d]", ret); + + result = NET_NFC_OPERATION_FAIL; + goto END; + } + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + DEBUG_ERR_MSG("sqlite3_step failed, [%d:%s]", ret, sqlite3_errmsg(db)); + + result = NET_NFC_OPERATION_FAIL; + goto END; + } + + result = NET_NFC_OK; +END : + sqlite3_finalize(stmt); + } else { + DEBUG_ERR_MSG("sqlite3_prepare_v2 failed, [%d:%s]", ret, sqlite3_errmsg(db)); + + result = NET_NFC_OPERATION_FAIL; + } + + sqlite3_free(sql); + } else { + DEBUG_ERR_MSG("sqlite3_mprintf failed"); + + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} + +static net_nfc_error_e __delete_from_db(const char *package, const char *aid) +{ + net_nfc_error_e result; + char *sql; + char *error = NULL; + + sql = sqlite3_mprintf("DELETE FROM %s WHERE package=%Q AND aid=%Q;", + NFC_ROUTE_TABLE_DB_TABLE, package, aid); + if (sql != NULL) { + int ret; + + ret = sqlite3_exec(db, sql, NULL, NULL, &error); + if (ret == SQLITE_OK) { + result = NET_NFC_OK; + } else { + DEBUG_ERR_MSG("sqlite3_exec failed, [%d:%s]", ret, error); + + result = NET_NFC_OPERATION_FAIL; + sqlite3_free(error); + } + + sqlite3_free(sql); + } else { + DEBUG_ERR_MSG("sqlite3_mprintf failed"); + + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} +#if 0 +static net_nfc_error_e __delete_aids_from_db(const char *package) +{ + net_nfc_error_e result; + char *sql; + char *error = NULL; + + sql = sqlite3_mprintf("DELETE FROM %s WHERE package=%Q;", + NFC_ROUTE_TABLE_DB_TABLE, package); + if (sql != NULL) { + int ret; + + ret = sqlite3_exec(db, sql, NULL, NULL, &error); + if (ret == SQLITE_OK) { + result = NET_NFC_OK; + } else { + DEBUG_ERR_MSG("sqlite3_exec failed, [%d:%s]", ret, error); + + result = NET_NFC_OPERATION_FAIL; + sqlite3_free(error); + } + + sqlite3_free(sql); + } else { + DEBUG_ERR_MSG("sqlite3_mprintf failed"); + + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} +#endif +//////////////////////////////////////////////////////////////////////////////// + +static char *activated_payment; +static GPtrArray *activated_other; + +static void __update_payment_handler(const char *package) +{ + if (activated_payment != NULL) { + g_free(activated_payment); + } + + if (package != NULL) { + activated_payment = g_strdup(package); + } +} + +static bool __is_payment_handler(const char *package) +{ + return (activated_payment != NULL && + g_strcmp0(package, activated_payment) == 0); +} + +static void __set_payment_handler(const char *package) +{ + int result; + + result = vconf_set_str(VCONFKEY_NFC_PAYMENT_HANDLERS, + package != NULL ? package : ""); + if (result < 0) { + DEBUG_ERR_MSG("vconf_set_str(VCONFKEY_NFC_PAYMENT_HANDLER) failed, [%d]", result); + } +} + +static void __on_destroy_other_cb(gpointer data) +{ + g_free(data); +} + +static void __update_other_handler(const char *packages) +{ + if (activated_other != NULL) { + g_ptr_array_free(activated_other, true); + } + + if (packages != NULL) { + gchar **tokens; + gchar **ptr; + + activated_other = g_ptr_array_new_full(10, + __on_destroy_other_cb); + + tokens = g_strsplit(packages, "|", -1); + + for (ptr = tokens; *ptr != NULL; ptr++) { + g_ptr_array_add(activated_other, g_strdup(*ptr)); + } + + g_strfreev(tokens); + } +} + +void net_nfc_server_route_table_update_other_handler(const char *packages) +{ + __update_other_handler(packages); + + net_nfc_server_route_table_do_update(); +} + +static bool __is_other_handler(const char *package) +{ + bool result = false; + int i; + + for (i = 0; i < activated_other->len; i++) { + if (g_strcmp0(package, activated_other->pdata[i]) == 0) { + result = true; + break; + } + } + + return result; +} + +static void __remove_other_handler(const char *package) +{ + int i, found = -1, offset = 0; + char built[4096] = { 0, }; + + for (i = 0; i < activated_other->len; i++) { + if (g_strcmp0(package, (char *)activated_other->pdata[i]) == 0) { + found = i; + } else { + if (i != activated_other->len - 1) { + offset += snprintf(built + offset, + sizeof(built) - offset, "%s|", + (char *)activated_other->pdata[i]); + } else { + offset += snprintf(built + offset, + sizeof(built) - offset, "%s", + (char *)activated_other->pdata[i]); + } + } + } + + if (found >= 0) { + /* vconf update */ + i = vconf_set_str(VCONFKEY_NFC_OTHER_HANDLERS, built); + if (i < 0) { + DEBUG_ERR_MSG("vconf_set_str(VCONFKEY_NFC_OTHERS_HANDLER) failed, [%d]", i); + } + } +} + +static void __append_other_handler(const char *package) +{ + int result; + char *others; + char built[4096] = { 0, }; + + if (__is_other_handler(package) == true) { + return; + } + + others = vconf_get_str(VCONFKEY_NFC_OTHER_HANDLERS); + if (others != NULL) { + if (strlen(others) > 0) { + snprintf(built, sizeof(built), "%s|%s", others, package); + } else { + snprintf(built, sizeof(built), "%s", package); + } + + g_free(others); + } else { + snprintf(built, sizeof(built), "%s", package); + } + + /* vconf update */ + result = vconf_set_str(VCONFKEY_NFC_OTHER_HANDLERS, built); + if (result < 0) { + DEBUG_ERR_MSG("vconf_set_str(VCONFKEY_NFC_OTHERS_HANDLER) failed, [%d]", result); + } +} + +static bool __is_activated_handler(net_nfc_card_emulation_category_t category, + const char *package) +{ + /* set nfc-manager to default handler */ + if (g_strcmp0(package, "nfc-manager") == 0) { + return true; + } + + switch (category) { + case NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT : + return __is_payment_handler(package); + case NET_NFC_CARD_EMULATION_CATEGORY_OTHER : + return __is_other_handler(package); + default : + return false; + } +} + +static void __activate_handler(const char *package, + net_nfc_card_emulation_category_t category) +{ + switch (category) { + case NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT : + if (__is_payment_handler(package) == false) { + __set_payment_handler(package); + } + break; + + case NET_NFC_CARD_EMULATION_CATEGORY_OTHER : + if (__is_other_handler(package) == false) { + __append_other_handler(package); + } + break; + + default : + break; + } +} + +static void __deactivate_handler(const char *package, + net_nfc_card_emulation_category_t category) +{ + switch (category) { + case NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT : + if (__is_payment_handler(package) == true) { + __set_payment_handler(NULL); + } + break; + + case NET_NFC_CARD_EMULATION_CATEGORY_OTHER : + if (__is_other_handler(package) == true) { + __remove_other_handler(package); + } + break; + + default : + break; + } +} + +void net_nfc_server_route_table_update_category_handler(const char *package, + net_nfc_card_emulation_category_t category) +{ + switch (category) { + case NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT : + __update_payment_handler(package); + net_nfc_server_route_table_do_update(); + break; + + case NET_NFC_CARD_EMULATION_CATEGORY_OTHER : + __update_other_handler(package); + net_nfc_server_route_table_do_update(); + break; + + default : + break; + } +} + + +//////////////////////////////////////////////////////////////////////////////// + +/*Routing Table base on AID*/ +static GHashTable *routing_handlers; + +static bool __get_package_name(const char *id, char *package, size_t len) +{ + pid_t pid; + bool result; + + pid = net_nfc_server_gdbus_get_pid(id); + if (pid > 0) { + if (net_nfc_util_get_pkgid_by_pid(pid, + package, len) == true) { + result = true; + } else { + result = false; + } + } else { + result = false; + } + + return result; +} + +static void __on_key_destroy(gpointer data) +{ + if (data != NULL) { + g_free(data); + } +} + +static void __on_value_destroy(gpointer data) +{ + route_table_handler_t *listener = (route_table_handler_t *)data; + + if (data != NULL) { + int i; + + for (i = NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT; + i < NET_NFC_CARD_EMULATION_CATEGORY_MAX; + i++) { + if (listener->aids[i] != NULL) { + g_ptr_array_free(listener->aids[i], true); + } + } + + if (listener->id != NULL) { + g_free(listener->id); + } + + g_free(data); + } +} + +static void __on_aid_info_destroy(gpointer data) +{ + aid_info_t *info = (aid_info_t *)data; + + if (info->aid != NULL) { + g_free(info->aid); + } + + g_free(info); +} + +static void __on_iterate_db_aid_cb(const char *package, + net_nfc_se_type_e se_type, net_nfc_card_emulation_category_t category, + const char *aid, bool unlock, int power, bool manifest, void *user_data) +{ + net_nfc_server_route_table_add_handler(NULL, package); + + DEBUG_SERVER_MSG("package [%s], se_type [%d], category [%d], manifest [%d], aid [%s]", package, se_type, category, manifest, aid); + + __route_table_add_aid(NULL, package, se_type, category, aid, unlock, power, manifest); +} + +void net_nfc_server_route_table_init() +{ + if (routing_handlers == NULL) { + char *package; + + __initialize_db(); + + package = vconf_get_str(VCONFKEY_NFC_PAYMENT_HANDLERS); + __update_payment_handler(package); + if (package != NULL) { + g_free(package); + } + + package = vconf_get_str(VCONFKEY_NFC_OTHER_HANDLERS); + __update_other_handler(package); + if (package != NULL) { + g_free(package); + } + + routing_handlers = g_hash_table_new_full(g_str_hash, + g_str_equal, __on_key_destroy, __on_value_destroy); + } +} + +void net_nfc_server_route_table_load_db() +{ + if (routing_handlers != NULL) { + __iterate_db(__on_iterate_db_aid_cb, NULL); + } +} + +void net_nfc_server_route_table_deinit() +{ + if (routing_handlers != NULL) { + g_hash_table_destroy(routing_handlers); + routing_handlers = NULL; + + __finalize_db(); + } + +} + +route_table_handler_t *net_nfc_server_route_table_find_handler( + const char *package) +{ + return (route_table_handler_t *)g_hash_table_lookup(routing_handlers, + (gconstpointer)package); +} + +net_nfc_error_e net_nfc_server_route_table_add_handler(const char *id, + const char *package) +{ + route_table_handler_t *data; + net_nfc_error_e result; + + data = net_nfc_server_route_table_find_handler(package); + if (data == NULL) { + int i; + + DEBUG_SERVER_MSG("new package, [%s]", package); + + data = g_new0(route_table_handler_t, 1); + + data->package = g_strdup(package); + if (id != NULL) { + data->id = g_strdup(id); + } + + /* full aid list in array index 0 */ + data->aids[NET_NFC_CARD_EMULATION_CATEGORY_UNKNOWN] = + g_ptr_array_new_full(0, __on_aid_info_destroy); + + /* partial aid list for each category in array index > 1 */ + for (i = NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT; + i < NET_NFC_CARD_EMULATION_CATEGORY_MAX; + i++) { + data->aids[i] = g_ptr_array_new(); + } + + g_hash_table_insert(routing_handlers, (gpointer)g_strdup(package), + (gpointer)data); + + result = NET_NFC_OK; + } else { + if (id != NULL && data->id == NULL) { + DEBUG_SERVER_MSG("update client id, [%s]", id); + data->id = g_strdup(id); + } + + result = NET_NFC_OK; + } + + return result; +} + +static net_nfc_error_e __do_routing_aid(aid_info_t *info, bool commit) +{ + net_nfc_error_e result; + + if (info->is_routed == false) { + data_s temp = { 0, }; + + INFO_MSG("route aid, aid [%s]", info->aid); + + if (net_nfc_util_aid_is_prefix(info->aid) == true) { + DEBUG_SERVER_MSG("prefix..."); + } + + if (net_nfc_util_hex_string_to_binary(info->aid, &temp) == true) { + net_nfc_controller_secure_element_route_aid(&temp, info->se_type, info->power, &result); + if (result == NET_NFC_OK) { + info->is_routed = true; + + if (commit == true) { + net_nfc_controller_secure_element_commit_routing(&result); + } + } else { + DEBUG_ERR_MSG("net_nfc_controller_secure_element_route_aid failed, [%d]", result); + } + + net_nfc_util_clear_data(&temp); + } else { + DEBUG_ERR_MSG("net_nfc_util_hex_string_to_binary failed"); + + result = NET_NFC_ALLOC_FAIL; + } + } else { + DEBUG_ERR_MSG("already routed, aid [%s]", info->aid); + + result = NET_NFC_ALREADY_REGISTERED; + } + + return result; +} + +static net_nfc_error_e __do_unrouting_aid(aid_info_t *info, bool commit) +{ + net_nfc_error_e result; + + if (info->is_routed == true) { + data_s temp = { 0, }; + + INFO_MSG("unroute aid, aid [%s]", info->aid); + + if (net_nfc_util_aid_is_prefix(info->aid) == true) { + DEBUG_SERVER_MSG("prefix..."); + } + + if (net_nfc_util_hex_string_to_binary(info->aid, &temp) == true) { + net_nfc_controller_secure_element_unroute_aid(&temp, &result); + if (result == NET_NFC_OK) { + info->is_routed = false; + + if (commit == true) { + net_nfc_controller_secure_element_commit_routing(&result); + } + } else { + DEBUG_ERR_MSG("net_nfc_controller_secure_element_unroute_aid failed, [%d]", result); + } + + net_nfc_util_clear_data(&temp); + } else { + DEBUG_ERR_MSG("net_nfc_util_hex_string_to_binary failed"); + + result = NET_NFC_ALLOC_FAIL; + } + } else { + DEBUG_ERR_MSG("didn't routed, aid [%s]", info->aid); + + result = NET_NFC_NOT_REGISTERED; + } + + return result; +} + +#if 0 +net_nfc_error_e net_nfc_server_route_table_del_handler(const char *id, + const char *package, bool force) +{ + route_table_handler_t *data; + net_nfc_error_e result; + bool need_commit = false; + + data = net_nfc_server_route_table_find_handler(package); + if (data != NULL) { + int i; + aid_info_t *info; + + DEBUG_SERVER_MSG("deleting package, [%s]", package); + + for (i = NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT; + i < NET_NFC_CARD_EMULATION_CATEGORY_MAX; + i++) { + /* deactivate for each category */ + if (data->activated[i] == true) { + /* TODO */ + } + } + + for (i = (int)data->aids[0]->len - 1; i >= 0; i--) { + info = data->aids[0]->pdata[i]; + + if (force == true || info->manifest == false) { + if (__do_unrouting_aid(info, false) == NET_NFC_OK) { + need_commit = true; + } + + g_ptr_array_remove(data->aids[info->category], info); + g_ptr_array_remove_index(data->aids[0], i); + } else { + DEBUG_SERVER_MSG("manifest aid, skip deleting, [%s]", info->aid); + } + } + + if (need_commit == true) { + net_nfc_controller_secure_element_commit_routing(&result); + } + + if (data->aids[0]->len == 0) { + g_hash_table_remove(routing_handlers, package); + } else { + DEBUG_SERVER_MSG("remain some aids, [%d]", data->aids[0]->len); + } + + result = NET_NFC_OK; + } else { + DEBUG_ERR_MSG("package not found"); + + result = NET_NFC_OPERATION_FAIL; + } + + return result; +} +#else +net_nfc_error_e net_nfc_server_route_table_del_handler(const char *id, + const char *package, bool force) +{ + route_table_handler_t *data; + net_nfc_error_e result; + + data = net_nfc_server_route_table_find_handler(package); + if (data != NULL) { + net_nfc_card_emulation_category_t category; + + if (data->id != NULL) { + g_free(data->id); + data->id = NULL; + } + + if (data->aids[0]->len > 0) { + net_nfc_server_route_table_del_aids(id, package, force); + } + + for (category = NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT; + category < NET_NFC_CARD_EMULATION_CATEGORY_MAX; + category++) { + if (data->aids[category]->len == 0 && + data->activated[category] == true) { + /* deactivate for each category */ + DEBUG_SERVER_MSG("deactivate handler, [%d][%s]", category, package); + + /* TODO */ + __deactivate_handler(package, category); + } + } + + if (data->aids[0]->len == 0) { + DEBUG_SERVER_MSG("deleting package, [%s]", package); + + g_hash_table_remove(routing_handlers, package); + + result = NET_NFC_OK; + } else { + DEBUG_ERR_MSG("remain some aids, [%d]", data->aids[0]->len); + + result = NET_NFC_OPERATION_FAIL; + } + } else { + DEBUG_ERR_MSG("package not found"); + + result = NET_NFC_OPERATION_FAIL; + } + + return result; +} +#endif +void net_nfc_server_route_table_iterate_handler( + net_nfc_server_route_table_handler_iter_cb cb, void *user_data) +{ + GHashTableIter iter; + gpointer key; + route_table_handler_t *data; + + if (routing_handlers == NULL) + return; + + g_hash_table_iter_init(&iter, routing_handlers); + + while (g_hash_table_iter_next(&iter, &key, (gpointer)&data)) { + if (cb((const char *)key, data, user_data) == false) { + break; + } + } +} +#ifdef PRINT_TABLE +static const char *__get_se_name(net_nfc_se_type_e se_type) +{ + switch (se_type) { + case NET_NFC_SE_TYPE_ESE : + return "eSE"; + case NET_NFC_SE_TYPE_UICC : + return "UICC"; + case NET_NFC_SE_TYPE_SDCARD : + return "SD"; + case NET_NFC_SE_TYPE_HCE : + return "HCE"; + default : + return "Unknown"; + } +} + +static bool _display_route_table_cb(const char *package, + route_table_handler_t *handler, void *user_data) +{ + int i; + + DEBUG_SERVER_MSG(" + PACKAGE [%s|%s]", handler->package, handler->id); + + for (i = 0; i < handler->aids[0]->len; i++) { + aid_info_t *info = (aid_info_t *)handler->aids[0]->pdata[i]; + + DEBUG_SERVER_MSG(" +-- AID [%s], SE [%s], CATEGORY [%s%s], MANIFEST [%s]%s", + info->aid, + __get_se_name(info->se_type), + info->category == NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT ? "payment" : "other", + handler->activated[info->category] ? " (A)" : "", + info->manifest ? "manifest" : "dynamic", + info->is_routed ? ", (ROUTED)" : ""); + } + + return true; +} + +static void __display_route_table() +{ + DEBUG_SERVER_MSG(" +------------------------------------------------+"); + net_nfc_server_route_table_iterate_handler(_display_route_table_cb, NULL); + DEBUG_SERVER_MSG(" +------------------------------------------------+"); +} +#endif +static bool __activation_iter_cb(const char *package, + route_table_handler_t *handler, void *user_data) +{ + int i; + bool ret = true; + aid_info_t *info; + gpointer *params = (gpointer *)user_data; + net_nfc_se_type_e se_type; + net_nfc_card_emulation_category_t category; + + category = (net_nfc_card_emulation_category_t)params[1]; + se_type = (net_nfc_se_type_e)params[2]; + + if (params[0] != NULL && + g_ascii_strcasecmp(package, (const char *)params[0]) == 0) { + handler->activated[category] = true; + + (*(int *)params[3])++; + + for (i = 0; i < handler->aids[category]->len; i++) { + info = (aid_info_t *)handler->aids[category]->pdata[i]; + + if (info->se_type == se_type) { + if (info->is_routed == true) { + __do_unrouting_aid(info, false); + } + continue; + } + + if (info->is_routed == false) { + __do_routing_aid(info, false); + } + + /* FIXME : need commit?? check and return */ + } + + /* stop iterating */ + if (category == NET_NFC_CARD_EMULATION_CATEGORY_OTHER) { + ret = false; + } + } else { + if (category == NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT && + handler->activated[category] == true) { + handler->activated[category] = false; + + for (i = 0; i < handler->aids[category]->len; i++) { + info = (aid_info_t *)handler->aids[category]->pdata[i]; + + if (info->is_routed == true) { + __do_unrouting_aid(info, false); + } + + /* FIXME : need commit?? check and return */ + } + } + } + + return ret; +} + +net_nfc_error_e net_nfc_server_route_table_set_handler_activation( + const char *package, net_nfc_card_emulation_category_t category) +{ + net_nfc_error_e result; + gpointer params[4]; + int ret = 0; + + params[0] = (gpointer)package; + params[1] = (gpointer)category; + params[2] = (gpointer)net_nfc_server_se_get_se_type(); + params[3] = (gpointer)&ret; + + net_nfc_server_route_table_iterate_handler(__activation_iter_cb, + (void *)params); + +#ifdef PRINT_TABLE + __display_route_table(); +#endif + + if (ret == 1) { + INFO_MSG("activated category [%d], package [%s]", category, package); + + net_nfc_controller_secure_element_commit_routing(&result); + + result = NET_NFC_OK; + } else if (ret == 0) { + DEBUG_ERR_MSG("package not found : [%s]", package); + + result = NET_NFC_NO_DATA_FOUND; + } else { + DEBUG_ERR_MSG("wrong result : [%s][%d]", package, ret); + + result = NET_NFC_OPERATION_FAIL; + } + + return result; +} + + +route_table_handler_t *net_nfc_server_route_table_find_handler_by_id( + const char *id) +{ + route_table_handler_t *result; + char package[1024]; + + if (__get_package_name(id, package, sizeof(package)) == true) { + result = net_nfc_server_route_table_find_handler(package); + } else { + result = NULL; + } + + return result; +} + +net_nfc_error_e net_nfc_server_route_table_add_handler_by_id(const char *id) +{ + net_nfc_error_e result; + char package[1024]; + + if (__get_package_name(id, package, sizeof(package)) == true) { + result = net_nfc_server_route_table_add_handler(id, + package); + } else { + result = NET_NFC_INVALID_PARAM; + } + + return result; +} + +net_nfc_error_e net_nfc_server_route_table_del_handler_by_id(const char *id) +{ + net_nfc_error_e result; + char package[1024]; + + if (__get_package_name(id, package, sizeof(package)) == true) { + result = net_nfc_server_route_table_del_handler(id, package, false); + } else { + result = NET_NFC_INVALID_PARAM; + } + + return result; +} + + +net_nfc_error_e net_nfc_server_route_table_set_handler_activation_by_id( + const char *id, net_nfc_card_emulation_category_t category) +{ + net_nfc_error_e result; + char package[1024]; + + if (__get_package_name(id, package, sizeof(package)) == true) { + result = net_nfc_server_route_table_set_handler_activation( + package, category); + } else { + result = NET_NFC_INVALID_PARAM; + } + + return result; +} + + + +aid_info_t *net_nfc_server_route_table_find_aid(const char *package, + const char *aid) +{ + route_table_handler_t *handler; + + handler = net_nfc_server_route_table_find_handler(package); + if (handler != NULL) { + aid_info_t *info; + int i; + + for (i = 0; i < handler->aids[0]->len; i++) { + info = handler->aids[0]->pdata[i]; + + if (g_ascii_strcasecmp(aid, info->aid) == 0) { + return info; + } + } + } + + return NULL; +} + +static bool __find_handler_iter_cb(const char *package, + route_table_handler_t *handler, void *user_data) +{ + bool result = true; + gpointer *params = (gpointer *)user_data; + aid_info_t *aid; + + aid = net_nfc_server_route_table_find_aid(package, + (const char *)params[0]); + if (aid != NULL) { + if (aid->category != NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT || + handler->activated[aid->category] == true) { + params[1] = handler; + result = false; + } else { + DEBUG_SERVER_MSG("not activated payment aid, [%s]", aid->aid); + } + } + + return result; +} + +route_table_handler_t *net_nfc_server_route_table_find_handler_by_aid( + const char *aid) +{ + gpointer params[2]; + + params[0] = g_strdup(aid); + params[1] = NULL; + + net_nfc_server_route_table_iterate_handler(__find_handler_iter_cb, params); + + g_free(params[0]); + + return (route_table_handler_t *)params[1]; +} + +static bool __matched_aid_cb(const char *package, + route_table_handler_t *handler, void *user_data) +{ + bool result = true; + gpointer *params = (gpointer *)user_data; + + if (net_nfc_server_route_table_find_aid(package, + (const char *)params[0]) != NULL) { + params[1] = handler; + result = false; + } + + return result; +} + +aid_info_t *net_nfc_server_route_table_find_first_matched_aid(const char *aid) +{ + __matched_aid_cb(NULL, NULL, NULL); + + return NULL; +} + +static net_nfc_error_e __route_table_add_aid(const char *id, + const char *package, net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + const char *aid, bool unlock, int power, bool manifest) +{ + net_nfc_error_e result; + route_table_handler_t *data; + + data = net_nfc_server_route_table_find_handler(package); + if (data != NULL) { + if (net_nfc_server_route_table_find_aid(package, aid) == NULL) { + aid_info_t *info; + + DEBUG_SERVER_MSG("new aid, package [%s], se_type [%d], category [%d], aid [%s], ", package, se_type, category, aid); + + info = g_new0(aid_info_t, 1); + + info->aid = g_strdup(aid); + info->se_type = se_type; + info->category = category; + info->unlock = unlock; + info->power = power; + info->manifest = manifest; + + g_ptr_array_add(data->aids[0], info); + g_ptr_array_add(data->aids[category], info); + + if (se_type != net_nfc_server_se_get_se_type()) { + if (data->activated[category] == true) { + INFO_MSG("routing... package [%s], aid [%s], ", package, aid); + + result = __do_routing_aid(info, true); + } else { + INFO_MSG("not activated handler, aid [%s]", aid); + + result = NET_NFC_OK; + } + } else { + INFO_MSG("route to default SE... skip, aid [%s]", aid); + + result = NET_NFC_OK; + } + } else { + DEBUG_ERR_MSG("already exist, aid [%s]", aid); + + result = NET_NFC_ALREADY_REGISTERED; + } + } else { + DEBUG_ERR_MSG("package not found"); + + result = NET_NFC_OPERATION_FAIL; + } + + return result; +} + +static net_nfc_error_e __route_table_del_aid(const char *id, + const char *package, const char *aid, bool force) +{ + net_nfc_error_e result = NET_NFC_NO_DATA_FOUND; + route_table_handler_t *data; + + data = net_nfc_server_route_table_find_handler(package); + if (data != NULL && + (id == NULL || data->id == NULL || + g_ascii_strcasecmp(id, data->id) == 0)) { + int i; + + for (i = 0; i < data->aids[0]->len; i++) { + aid_info_t *info = (aid_info_t *)data->aids[0]->pdata[i]; + + if (g_ascii_strcasecmp(info->aid, aid) == 0) { + if (force == true || info->manifest == false) { + INFO_MSG("remove aid, package [%s], aid [%s]", package, aid); + + if (info->is_routed == true) { + __do_unrouting_aid(info, true); + } + + g_ptr_array_remove(data->aids[info->category], info); + g_ptr_array_remove_index(data->aids[0], i); + + result = NET_NFC_OK; + } else { + DEBUG_SERVER_MSG("cannot remove aid because it stored in manifest, aid [%s]", info->aid); + + result = NET_NFC_OPERATION_FAIL; + } + + break; + } + } + } + + return result; +} + +net_nfc_error_e net_nfc_server_route_table_add_aid(const char *id, + const char *package, net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + const char *aid) +{ + net_nfc_error_e result; + + result = net_nfc_server_route_table_add_handler(id, package); + if (result == NET_NFC_OK) { + result = __route_table_add_aid(id, + package, se_type, category, aid, true, 1, false); + if (result == NET_NFC_OK) { + result = __insert_into_db(package, se_type, category, aid, true, 1, false); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("__insert_into_db failed, [%d]", result); + + result = __route_table_del_aid(id, package, aid, false); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("__route_table_del_aid failed, [%d]", result); + } + } + } else { + DEBUG_ERR_MSG("net_nfc_server_route_table_add_aid failed, [%d]", result); + } + } else { + DEBUG_ERR_MSG("net_nfc_server_route_table_add_handler failed, [%d]", result); + } + +#ifdef PRINT_TABLE + __display_route_table(); +#endif + return result; +} + +net_nfc_error_e net_nfc_server_route_table_del_aid(const char *id, + const char *package, const char *aid, bool force) +{ + net_nfc_error_e result = NET_NFC_OK; + + result = __route_table_del_aid(id, package, aid, false); + if (result == NET_NFC_OK) { + } else { + DEBUG_ERR_MSG("__route_table_del_aid failed, [%d]", result); + } + + result = __delete_from_db(package, aid); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("__delete_from_db failed, [%d]", result); + } + +#ifdef PRINT_TABLE + __display_route_table(); +#endif + return result; +} + +net_nfc_error_e net_nfc_server_route_table_del_aids(const char *id, + const char *package, bool force) +{ + net_nfc_error_e result = NET_NFC_NO_DATA_FOUND; + route_table_handler_t *data; + bool need_commit = false; + + data = net_nfc_server_route_table_find_handler(package); + if (data != NULL && + (id == NULL || data->id == NULL || + g_ascii_strcasecmp(id, data->id) == 0)) { + int i; + + for (i = (int)data->aids[0]->len - 1; i >= 0; i--) { + aid_info_t *info = (aid_info_t *)data->aids[0]->pdata[i]; + + if (force == true || info->manifest == false) { + DEBUG_SERVER_MSG("remove aid, package [%s], aid [%s]", package, info->aid); + + if (info->is_routed == true && + __do_unrouting_aid(info, false) == NET_NFC_OK) { + need_commit = true; + } + + result = __delete_from_db(package, info->aid); + if (result != NET_NFC_OK) { + DEBUG_ERR_MSG("__delete_from_db failed, [%d]", result); + } + + g_ptr_array_remove(data->aids[info->category], info); + g_ptr_array_remove_index(data->aids[0], i); + } else { + DEBUG_SERVER_MSG("cannot remove aid because it stored in manifest, aid [%s]", info->aid); + } + } + } else { + DEBUG_SERVER_MSG("not found, package [%s]", package); + } + + if (need_commit == true) { + net_nfc_controller_secure_element_commit_routing(&result); + } + +#ifdef PRINT_TABLE + __display_route_table(); +#endif + return result; +} + +void net_nfc_server_route_table_iterate_aid(const char *package, + net_nfc_server_route_table_aid_iter_cb cb, void *user_data) +{ + GHashTableIter iter; + gpointer key; + route_table_handler_t *data; + int i; + aid_info_t *info; + + if (routing_handlers == NULL) + return; + + g_hash_table_iter_init(&iter, routing_handlers); + + while (g_hash_table_iter_next(&iter, &key, (gpointer)&data)) { + for (i = 0; i < data->aids[0]->len; i++) { + info = (aid_info_t *)data->aids[0]->pdata[i]; + + cb((const char *)key, data, info, user_data); + } + } +} + +aid_info_t *net_nfc_server_route_table_find_aid_by_id(const char *id, + const char *aid) +{ + aid_info_t *result; + char package[1024]; + + if (__get_package_name(id, package, sizeof(package)) == true) { + result = net_nfc_server_route_table_find_aid(package, aid); + } else { + result = NULL; + } + + return result; + +} + +net_nfc_error_e net_nfc_server_route_table_add_aid_by_id(const char *id, + net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + const char *aid) +{ + net_nfc_error_e result; + char package[1024]; + + if (__get_package_name(id, package, sizeof(package)) == true) { + result = net_nfc_server_route_table_add_aid(id, + package, se_type, category, aid); + } else { + result = NET_NFC_INVALID_PARAM; + } + + return result; +} + +net_nfc_error_e net_nfc_server_route_table_del_aid_by_id(const char *id, + const char *aid, bool force) +{ + net_nfc_error_e result = NET_NFC_NO_DATA_FOUND; + char package[1024]; + + if (__get_package_name(id, package, sizeof(package)) == true) { + result = net_nfc_server_route_table_del_aid(id, + package, aid, force); + } + + return result; +} + + +void net_nfc_server_route_table_iterate_aid_by_id(const char *id, + net_nfc_server_route_table_aid_iter_cb cb, void *user_data) +{ + char package[1024]; + + if (__get_package_name(id, package, sizeof(package)) == true) { + net_nfc_server_route_table_iterate_aid(package, cb, user_data); + } +} + + +net_nfc_error_e net_nfc_server_route_table_insert_aid_into_db( + const char *package, net_nfc_se_type_e se_type, + net_nfc_card_emulation_category_t category, + const char *aid, bool unlock, int power) +{ + net_nfc_error_e result; + + result = __insert_into_db(package, se_type, category, + aid, unlock, power, true); + if (result == NET_NFC_OK) { + result = net_nfc_server_route_table_add_handler(NULL, package); + if (result == NET_NFC_OK) { + result = __route_table_add_aid(NULL, + package, se_type, category, aid, + unlock, power, true); + if (result == NET_NFC_OK) { + if (category == NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT) { + char *handler; + + handler = vconf_get_str(VCONFKEY_NFC_PAYMENT_HANDLERS); + if (handler == NULL || strlen(handler) == 0) { + DEBUG_SERVER_MSG("set to default payment handler, [%s]", package); + + __activate_handler(package, category); + } + + if (handler != NULL) { + g_free(handler); + } + } else { + if (__is_activated_handler(category, package) == false) { + __activate_handler(package, category); + } + } + } else { + DEBUG_ERR_MSG("net_nfc_server_route_table_add_aid failed, [%d]", result); + } + } else { + DEBUG_ERR_MSG("net_nfc_server_route_table_add_handler failed, [%d]", result); + } + } else { + DEBUG_ERR_MSG("__insert_into_db failed, [%d]", result); + } + +#ifdef PRINT_TABLE + __display_route_table(); +#endif + return result; +} + +net_nfc_error_e net_nfc_server_route_table_delete_aid_from_db( + const char *package, const char *aid) +{ + net_nfc_error_e result; + + result = net_nfc_server_route_table_del_aid(NULL, package, aid, true); + + return result; +} + +net_nfc_error_e net_nfc_server_route_table_delete_aids_from_db( + const char *package) +{ + net_nfc_error_e result; + + result = net_nfc_server_route_table_del_aids(NULL, package, true); + + return result; +} + +static bool __update_table_iter_cb(const char *package, + route_table_handler_t *handler, void *user_data) +{ + gpointer *params = (gpointer *)user_data; + int i; + aid_info_t *info; + net_nfc_se_type_e se_type; + net_nfc_card_emulation_category_t category; + int *ret; + + se_type = (net_nfc_se_type_e)params[0]; + ret = (int *)params[1]; + + for (category = NET_NFC_CARD_EMULATION_CATEGORY_PAYMENT; + category < NET_NFC_CARD_EMULATION_CATEGORY_MAX; + category++) { + if (__is_activated_handler(category, package) == true) { + for (i = 0; i < handler->aids[category]->len; i++) { + info = (aid_info_t *)handler->aids[category]->pdata[i]; + + if (info->se_type == se_type) { + /* unroute aid when se type is same with default */ + if (info->is_routed == true) { + __do_unrouting_aid(info, false); + } + + continue; + } + + if (info->is_routed == false) { + __do_routing_aid(info, false); + } + } + + handler->activated[category] = true; + } else { + for (i = 0; i < handler->aids[category]->len; i++) { + info = (aid_info_t *)handler->aids[category]->pdata[i]; + + if (info->is_routed == true) { + __do_unrouting_aid(info, false); + } + } + + handler->activated[category] = false; + } + } + + (*ret) = 0; + + return true; +} + +net_nfc_error_e net_nfc_server_route_table_do_update(void) +{ + net_nfc_error_e result = NET_NFC_OK; + gpointer params[3]; + net_nfc_se_type_e se_type; + int ret = 0; + +// if (net_nfc_controller_secure_element_clear_aid_table(&result) == false) { +// DEBUG_ERR_MSG("net_nfc_controller_secure_element_clear_aid_table failed, [%d]", result); +// } + + se_type = net_nfc_server_se_get_se_type(); + + params[0] = (gpointer)se_type; + params[1] = (gpointer)&ret; + + net_nfc_server_route_table_iterate_handler(__update_table_iter_cb, + (void *)params); + + if (ret == 0) { + INFO_MSG("routing table update complete"); + + result = NET_NFC_OK; + } else if (ret > 1) { + DEBUG_ERR_MSG("some packages are not updated, [%d]", ret); + + result = NET_NFC_OPERATION_FAIL; + } else { + DEBUG_ERR_MSG("wrong result, [%d]", ret); + + result = NET_NFC_OPERATION_FAIL; + } + + net_nfc_controller_secure_element_commit_routing(&result); + +#ifdef PRINT_TABLE + __display_route_table(); +#endif + + return result; +} diff --git a/src/manager/net_nfc_server_se.c b/src/manager/net_nfc_server_se.c new file mode 100755 index 0000000..8ad6bd3 --- /dev/null +++ b/src/manager/net_nfc_server_se.c @@ -0,0 +1,3643 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "net_nfc_server.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_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" +#include "net_nfc_server_route_table.h" + +enum +{ + SE_UICC_UNAVAILABLE = -1, + SE_UICC_ON_PROGRESS = 0, + SE_UICC_READY = 1, +}; + +static NetNfcGDbusSecureElement *se_skeleton = NULL; + +/* TODO : make a list for handles */ +static TapiHandle *gdbus_uicc_handle; +static net_nfc_target_handle_s *gdbus_ese_handle; + +static int gdbus_uicc_ready; + +/* server_side */ +typedef struct _ServerSeData ServerSeData; + +struct _ServerSeData +{ + data_s aid; + data_s param; + guint event; +}; + +typedef struct _SeSetCardEmul SeSetCardEmul; + +struct _SeSetCardEmul +{ + NetNfcGDbusSecureElement *object; + GDBusMethodInvocation *invocation; + gint mode; +}; + +typedef struct _SeDataSeType SeDataSeType; + +struct _SeDataSeType +{ + NetNfcGDbusSecureElement *object; + GDBusMethodInvocation *invocation; + gint se_type; +}; + +typedef struct _SeDataTransactionFgDispatch SeDataTransactionFgDispatch; + +struct _SeDataTransactionFgDispatch +{ + NetNfcGDbusSecureElement *object; + GDBusMethodInvocation *invocation; + int FgDispatch; +}; + +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; +}; + +typedef struct _ChangeCardEmulMode ChangeCardEmulMode; + +struct _ChangeCardEmulMode +{ + NetNfcGDbusSecureElement *object; + GDBusMethodInvocation *invocation; + gint mode; +}; + +typedef struct _SeDefaultRoute +{ + NetNfcGDbusSecureElement *object; + GDBusMethodInvocation *invocation; + net_nfc_target_handle_s* handle; + guint switch_on; + guint switch_off; + guint battery_off; +} +SeDefaultRoute; +TelSimApdu_t apdu_data = { 0, }; +TelSimApduResp_t *resp_apdu = NULL; +TelSimAtrResp_t *resp_atr = NULL; + +typedef struct _SeDataAid +{ + NetNfcGDbusSecureElement *object; + GDBusMethodInvocation *invocation; + net_nfc_target_handle_s *handle; + char *package; + char *aid; + guint se_type; + guint category; + gboolean unlock; + guint power; +} +SeDataAid; + + +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 void se_policy_apply_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); + +static net_nfc_card_emulation_mode_t __se_get_se_state( + net_nfc_secure_element_policy_e policy); + +static net_nfc_se_type_e __se_get_se_type( + net_nfc_secure_element_policy_e policy); + + +static net_nfc_secure_element_policy_e current_policy; + + +static net_nfc_card_emulation_mode_t __se_get_se_state( + net_nfc_secure_element_policy_e policy) +{ + net_nfc_card_emulation_mode_t state; + + switch (policy) { + case SECURE_ELEMENT_POLICY_ESE_ON : + state = NET_NFC_CARD_EMELATION_ENABLE; + break; + + case SECURE_ELEMENT_POLICY_UICC_ON : + if (gdbus_uicc_ready == SE_UICC_READY) { + state = NET_NFC_CARD_EMELATION_ENABLE; + } else { + state = NET_NFC_CARD_EMULATION_DISABLE; + } + break; + + case SECURE_ELEMENT_POLICY_HCE_ON : + state = NET_NFC_CARD_EMELATION_ENABLE; + break; + + default : + state = NET_NFC_CARD_EMULATION_DISABLE; + break; + } + + return state; +} + +void net_nfc_server_se_policy_apply() +{ + if (se_skeleton == NULL) + { + DEBUG_ERR_MSG("net_nfc_server_manager is not initialized"); + + return; + } + + DEBUG_SERVER_MSG("se policy apply start"); + + if (net_nfc_server_controller_async_queue_push( + se_policy_apply_thread_func, + NULL) == FALSE) + { + DEBUG_ERR_MSG("can not push to controller thread"); + } +} + +net_nfc_card_emulation_mode_t net_nfc_server_se_get_se_state() +{ + net_nfc_card_emulation_mode_t state; + int se_policy = SECURE_ELEMENT_POLICY_INVALID; + + if (vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_policy) != 0) { + DEBUG_ERR_MSG("vconf_get_int failed"); + } + + state = __se_get_se_state(se_policy); + + DEBUG_SERVER_MSG("se state [%s]", state ? "activated" : "deactivated"); + + return state; +} + +net_nfc_error_e net_nfc_server_se_set_se_state( + net_nfc_card_emulation_mode_t state) +{ + net_nfc_error_e result; + int se_policy = SECURE_ELEMENT_POLICY_INVALID; + + if (vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_policy) != 0) { + DEBUG_ERR_MSG("vconf_get_int failed"); + + return NET_NFC_OPERATION_FAIL; + } + + if (__se_get_se_type(se_policy) == NET_NFC_SE_TYPE_UICC && + gdbus_uicc_ready != SE_UICC_READY) { + DEBUG_ERR_MSG("UICC not initialized, changing state not permitted"); + + return NET_NFC_OPERATION_FAIL; + } + + if (se_policy == SECURE_ELEMENT_POLICY_INVALID) { + DEBUG_ERR_MSG("invalid se is selected, changing state not permitted"); + + return NET_NFC_OPERATION_FAIL; + } + + if (__se_get_se_state(se_policy) != state) { + switch (__se_get_se_type(se_policy)) { + case NET_NFC_SE_TYPE_UICC : + if (state == NET_NFC_CARD_EMELATION_ENABLE) { + se_policy = SECURE_ELEMENT_POLICY_UICC_ON; + } else { + se_policy = SECURE_ELEMENT_POLICY_UICC_OFF; + } + break; + + case NET_NFC_SE_TYPE_ESE : + /* FIXME */ + if (state == NET_NFC_CARD_EMELATION_ENABLE) { + se_policy = SECURE_ELEMENT_POLICY_ESE_ON; + } else { + se_policy = SECURE_ELEMENT_POLICY_ESE_OFF; + } + break; + + case NET_NFC_SE_TYPE_HCE : + /* FIXME */ + if (state == NET_NFC_CARD_EMELATION_ENABLE) { + se_policy = SECURE_ELEMENT_POLICY_HCE_ON; + } else { + se_policy = SECURE_ELEMENT_POLICY_HCE_OFF; + } + break; + + default : + se_policy = SECURE_ELEMENT_POLICY_INVALID; + break; + } + + if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, se_policy) == 0) { + result = NET_NFC_OK; + } else { + DEBUG_ERR_MSG("vconf_set_int failed"); + + result = NET_NFC_OPERATION_FAIL; + } + } else { + DEBUG_ERR_MSG("same state"); + + result = NET_NFC_INVALID_STATE; + } + + return result; +} + +inline static const char *__se_get_se_name(net_nfc_se_type_e type) +{ + const char *name; + + switch (type) { + case NET_NFC_SE_TYPE_UICC : + name = "UICC"; + break; + + case NET_NFC_SE_TYPE_ESE : + name = "eSE"; + break; + + case NET_NFC_SE_TYPE_HCE : + name = "HCE"; + break; + + default : + name = "unknown"; + break; + } + + return name; +} + +static net_nfc_se_type_e __se_get_se_type( + net_nfc_secure_element_policy_e policy) +{ + net_nfc_se_type_e type; + + switch (policy) + { + case SECURE_ELEMENT_POLICY_UICC_ON : + case SECURE_ELEMENT_POLICY_UICC_OFF : + type = NET_NFC_SE_TYPE_UICC; + break; + + case SECURE_ELEMENT_POLICY_ESE_ON : + case SECURE_ELEMENT_POLICY_ESE_OFF : + type = NET_NFC_SE_TYPE_ESE; + break; + + case SECURE_ELEMENT_POLICY_HCE_ON : + case SECURE_ELEMENT_POLICY_HCE_OFF : + type = NET_NFC_SE_TYPE_HCE; + break; + + default: + type = NET_NFC_SE_TYPE_NONE; + break; + } + + return type; +} + +net_nfc_se_type_e net_nfc_server_se_get_se_type() +{ + net_nfc_se_type_e se_type; + int wallet_mode = 0; +/* + if (vconf_get_int(VCONFKEY_NFC_WALLET_MODE, &wallet_mode) != 0) { + DEBUG_ERR_MSG("vconf_get_int failed"); + } + + if (wallet_mode != NET_NFC_WALLET_MODE_UICC) { + int se_policy = SECURE_ELEMENT_POLICY_INVALID; + + if (vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_policy) != 0) { + DEBUG_ERR_MSG("vconf_get_int failed"); + } + + se_type = __se_get_se_type(se_policy); + } else { + se_type = NET_NFC_SE_TYPE_UICC; + } + + DEBUG_SERVER_MSG("active se [%s]", __se_get_se_name(se_type)); +*/ + return se_type; +} + +net_nfc_error_e net_nfc_server_se_set_se_type(net_nfc_se_type_e type) +{ + net_nfc_error_e result; + int se_policy = SECURE_ELEMENT_POLICY_INVALID; + int wallet_mode = 0; +/* + if (vconf_get_int(VCONFKEY_NFC_WALLET_MODE, &wallet_mode) != 0) { + DEBUG_ERR_MSG("vconf_get_int failed"); + + return NET_NFC_OPERATION_FAIL; + } + + if (vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_policy) != 0) { + DEBUG_ERR_MSG("vconf_get_int failed"); + + return NET_NFC_OPERATION_FAIL; + } + + + if (wallet_mode == NET_NFC_WALLET_MODE_UICC) { + DEBUG_ERR_MSG("not supported in wallet mode"); + + return NET_NFC_INVALID_STATE; + } + + if (__se_get_se_type(se_policy) != type) { + switch (type) { + case NET_NFC_SE_TYPE_UICC : + if (__se_get_se_state(se_policy) == + NET_NFC_CARD_EMELATION_ENABLE) { + se_policy = SECURE_ELEMENT_POLICY_UICC_ON; + } else { + se_policy = SECURE_ELEMENT_POLICY_UICC_OFF; + } + break; + + case NET_NFC_SE_TYPE_ESE : + if (__se_get_se_state(se_policy) == + NET_NFC_CARD_EMELATION_ENABLE) { + se_policy = SECURE_ELEMENT_POLICY_ESE_ON; + } else { + se_policy = SECURE_ELEMENT_POLICY_ESE_OFF; + } + break; + + case NET_NFC_SE_TYPE_HCE : + if (__se_get_se_state(se_policy) == + NET_NFC_CARD_EMELATION_ENABLE) { + se_policy = SECURE_ELEMENT_POLICY_HCE_ON; + } else { + se_policy = SECURE_ELEMENT_POLICY_HCE_OFF; + } + break; + + default : + se_policy = SECURE_ELEMENT_POLICY_INVALID; + break; + } + + if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, se_policy) == 0) { + result = NET_NFC_OK; + } else { + DEBUG_ERR_MSG("vconf_set_int failed"); + + result = NET_NFC_OPERATION_FAIL; + } + } else { + DEBUG_ERR_MSG("activated already, [%s]", __se_get_se_name(type)); + + result = NET_NFC_INVALID_STATE; + } +*/ + return result; +} + +static net_nfc_secure_element_policy_e __se_get_se_policy() +{ + int se_policy = SECURE_ELEMENT_POLICY_INVALID; + int wallet_mode = 0; +/* + if (vconf_get_int(VCONFKEY_NFC_WALLET_MODE, &wallet_mode) != 0) { + DEBUG_ERR_MSG("vconf_get_int failed"); + } + + if (vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_policy) != 0) { + DEBUG_ERR_MSG("vconf_get_int failed"); + } + + if (wallet_mode == NET_NFC_WALLET_MODE_UICC) { + if (__se_get_se_state(se_policy) == + NET_NFC_CARD_EMELATION_ENABLE) { + se_policy = SECURE_ELEMENT_POLICY_UICC_ON; + } else { + se_policy = SECURE_ELEMENT_POLICY_UICC_OFF; + } + } + else if(wallet_mode == NET_NFC_WALLET_MODE_ESE) { + if (__se_get_se_state(se_policy) == + NET_NFC_CARD_EMELATION_ENABLE) { + se_policy = SECURE_ELEMENT_POLICY_ESE_ON; + } else { + se_policy = SECURE_ELEMENT_POLICY_ESE_OFF; + } + } + else if(wallet_mode == NET_NFC_WALLET_MODE_HCE) { + if (__se_get_se_state(se_policy) == + NET_NFC_CARD_EMELATION_ENABLE) { + se_policy = SECURE_ELEMENT_POLICY_HCE_ON; + } else { + se_policy = SECURE_ELEMENT_POLICY_HCE_OFF; + } + } +*/ + + return se_policy; +} +#if 0 +net_nfc_error_e net_nfc_server_se_set_se_policy( + net_nfc_secure_element_policy_e policy) +{ + net_nfc_error_e result = NET_NFC_OK; + int vconf_key; + int wallet_mode = 0; + int se_type = 0; + + DEBUG_SERVER_MSG("set se policy [%d]", policy); + + if (vconf_get_int(VCONFKEY_NFC_WALLET_MODE, &wallet_mode) != 0) { + DEBUG_ERR_MSG("vconf_get_int failed"); + } + + if (vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_type) != 0) { + DEBUG_ERR_MSG("vconf_get_int failed"); + } + + if (wallet_mode == VCONFKEY_NFC_WALLET_MODE_MANUAL) { + if (policy == SECURE_ELEMENT_POLICY_UICC_ON) { + if (se_type == SECURE_ELEMENT_POLICY_ESE_ON || + se_type == SECURE_ELEMENT_POLICY_ESE_OFF) { + policy = SECURE_ELEMENT_POLICY_ESE_ON; + } + } else if (policy == SECURE_ELEMENT_POLICY_UICC_OFF) { + if (se_type == SECURE_ELEMENT_POLICY_ESE_ON || + se_type == SECURE_ELEMENT_POLICY_ESE_OFF) { + policy = SECURE_ELEMENT_POLICY_ESE_OFF; + } + } + } + + switch (policy) + { + case SECURE_ELEMENT_POLICY_UICC_ON : + vconf_key = VCONFKEY_NFC_SE_POLICY_UICC_ON; + break; + + case SECURE_ELEMENT_POLICY_UICC_OFF : + vconf_key = VCONFKEY_NFC_SE_POLICY_UICC_OFF; + break; + + case SECURE_ELEMENT_POLICY_ESE_ON : + vconf_key = VCONFKEY_NFC_SE_POLICY_ESE_ON; + break; + + case SECURE_ELEMENT_POLICY_ESE_OFF : + vconf_key = VCONFKEY_NFC_SE_POLICY_ESE_OFF; + break; + + default: + vconf_key = VCONFKEY_NFC_SE_POLICY_NONE; + break; + } + + if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, vconf_key) != 0) { + DEBUG_ERR_MSG("vconf_set_int failed"); + result = NET_NFC_OPERATION_FAIL; + } + + return result; +} +#endif +/* 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_OK; + net_nfc_target_handle_s *handle = NULL; + + if (net_nfc_controller_secure_element_open( + NET_NFC_SE_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; +} + +static void _sim_apdu_cb(TapiHandle *handle, int result, + void *data, void *user_data) +{ + TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result; + resp_apdu = (TelSimApduResp_t *)data; + GMainLoop *loop = (GMainLoop *)user_data; + + g_main_loop_quit(loop); +} + +static void _sim_atr_cb(TapiHandle *handle, int result, + void *data, void *user_data) +{ + TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result; + resp_atr = (TelSimAtrResp_t *)data; + GMainLoop *loop = (GMainLoop *)user_data; + + g_main_loop_quit(loop); +} + + +static bool _se_uicc_send_apdu(net_nfc_target_handle_s *handle, + data_s *apdu, data_s **response) +{ + bool ret; + int result; + GMainLoop *loop = NULL; + + if (apdu == NULL || apdu->buffer == NULL || response == NULL) + return false; + + apdu_data.apdu = apdu->buffer; + apdu_data.apdu_len = apdu->length; + loop = g_main_loop_new(NULL, false); + + result = tel_req_sim_apdu((TapiHandle *)handle, &apdu_data, _sim_apdu_cb, &loop); + if (result == 0 && + resp_apdu->apdu_resp_len > 0) { + data_s *temp = NULL; + + g_main_loop_run(loop); + + temp = net_nfc_util_create_data(resp_apdu->apdu_resp_len); + if (temp != NULL) { + memcpy(temp->buffer, + resp_apdu->apdu_resp, + temp->length); + + *response = temp; + ret = true; + } else { + DEBUG_ERR_MSG("alloc failed"); + + ret = false; + } + } else { + DEBUG_ERR_MSG("tel_call_sim_sync failed, [%d]", result); + + ret = false; + } + + return ret; +} + +static bool _se_uicc_get_atr(net_nfc_target_handle_s *handle, data_s **atr) +{ + bool ret; + int result; + GMainLoop *loop; + + if (atr == NULL) + return false; + + loop = g_main_loop_new(NULL, false); + + result = tel_req_sim_atr((TapiHandle *)handle, _sim_atr_cb, &loop); + if (result == 0){ + data_s *temp = NULL; + + g_main_loop_run(loop); + + temp = net_nfc_util_create_data(resp_atr->atr_resp_len); + if (temp != NULL) { + memcpy(temp->buffer, resp_atr->atr_resp, + temp->length); + + *atr = temp; + ret = true; + } else { + DEBUG_ERR_MSG("alloc failed"); + + ret = false; + } + } else { + DEBUG_ERR_MSG("tel_call_sim_sync failed, [%d]", result); + + ret = false; + } + + return ret; +} + +#ifdef ENABLE_TELEPHONY +static void _se_uicc_prepare(void) +{ + gdbus_uicc_handle = tel_init(NULL); +} + +static void _vconf_sim_status_cb(keynode_t *node, void *user_data) +{ + DEBUG_SERVER_MSG("VCONFKEY_TELEPHONY_SIM_STATUS [%d]", node->value.i); + + switch (node->value.i) { + case VCONFKEY_TELEPHONY_SIM_STATUS_INIT_COMPLETED : + { + int se_policy; + + gdbus_uicc_ready = SE_UICC_READY; + + _se_uicc_prepare(); + + se_policy = __se_get_se_policy(); + + DEBUG_SERVER_MSG("current se policy [%d]", se_policy); + + if (se_policy == SECURE_ELEMENT_POLICY_UICC_ON) { + net_nfc_server_se_apply_se_policy(SECURE_ELEMENT_POLICY_UICC_ON); + } + } + break; + case VCONFKEY_TELEPHONY_SIM_STATUS_CARD_REMOVED : + case VCONFKEY_TELEPHONY_SIM_STATUS_CARD_ERROR : + case VCONFKEY_TELEPHONY_SIM_STATUS_CARD_BLOCKED : + case VCONFKEY_TELEPHONY_SIM_STATUS_CARD_CRASHED : + gdbus_uicc_ready = SE_UICC_UNAVAILABLE; +#if 0 + if (__se_get_se_policy() == SECURE_ELEMENT_POLICY_UICC_ON) { + net_nfc_server_se_set_se_policy(SECURE_ELEMENT_POLICY_UICC_OFF); + } +#endif + break; + + + case VCONFKEY_TELEPHONY_SIM_STATUS_CARD_NOT_PRESENT : +#if 0 /* temp_patch_for_no_SIM_currency_issue */ + { + int ret; + int se_type; + ret = vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_type); + + if (ret == 0 && + se_type == VCONFKEY_NFC_SE_TYPE_UICC) + { + net_nfc_error_e result = NET_NFC_OK; + DEBUG_SERVER_MSG("_vconf_sim_status_cb VCONFKEY_NFC_SE_TYPE_UICC but VCONFKEY_TELEPHONY_SIM_STATUS_CARD_NOT_PRESENT "); + + /*turn off ESE*/ + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_ESE, + SECURE_ELEMENT_OFF_MODE, + &result); + + /*turn on UICC*/ + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_UICC, + SECURE_ELEMENT_VIRTUAL_MODE, + &result); + } + } + break; +#endif + default : + break; + } +} + +static void _se_uicc_init(void) +{ + int status; + + vconf_notify_key_changed(VCONFKEY_TELEPHONY_SIM_STATUS, + _vconf_sim_status_cb, NULL); + + if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_STATUS, &status) == 0) { + DEBUG_SERVER_MSG("VCONFKEY_TELEPHONY_SIM_STATUS [%d]", status); + + switch (status) { + case VCONFKEY_TELEPHONY_SIM_STATUS_INIT_COMPLETED : + gdbus_uicc_ready = SE_UICC_READY; + + _se_uicc_prepare(); + break; + + case VCONFKEY_TELEPHONY_SIM_STATUS_UNKNOWN : + case VCONFKEY_TELEPHONY_SIM_STATUS_INITIALIZING : + case VCONFKEY_TELEPHONY_SIM_STATUS_PIN_REQUIRED : + case VCONFKEY_TELEPHONY_SIM_STATUS_PUK_REQUIRED : + case VCONFKEY_TELEPHONY_SIM_STATUS_NCK_REQUIRED : + case VCONFKEY_TELEPHONY_SIM_STATUS_NSCK_REQUIRED : + case VCONFKEY_TELEPHONY_SIM_STATUS_SPCK_REQUIRED : + case VCONFKEY_TELEPHONY_SIM_STATUS_CCK_REQUIRED : + case VCONFKEY_TELEPHONY_SIM_STATUS_SIM_LOCK_REQUIRED : + gdbus_uicc_ready = SE_UICC_ON_PROGRESS; + break; + + case VCONFKEY_TELEPHONY_SIM_STATUS_CARD_NOT_PRESENT : +#if 0 /* temp_patch_for_no_SIM_currency_issue */ + { + int ret; + int se_type; + ret = vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_type); + + if (ret == 0 && + se_type == VCONFKEY_NFC_SE_TYPE_UICC) + { + net_nfc_error_e result = NET_NFC_OK; + DEBUG_SERVER_MSG("_se_uicc_init VCONFKEY_NFC_SE_TYPE_UICC but VCONFKEY_TELEPHONY_SIM_STATUS_CARD_NOT_PRESENT "); + + /*turn off ESE*/ + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_ESE, + SECURE_ELEMENT_OFF_MODE, + &result); + + /*turn on UICC*/ + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_UICC, + SECURE_ELEMENT_VIRTUAL_MODE, + &result); + } + } + break; +#endif + case VCONFKEY_TELEPHONY_SIM_STATUS_CARD_ERROR : + case VCONFKEY_TELEPHONY_SIM_STATUS_CARD_BLOCKED : + case VCONFKEY_TELEPHONY_SIM_STATUS_CARD_CRASHED : + default : + gdbus_uicc_ready = SE_UICC_UNAVAILABLE; + break; + } + } +} + +static void _se_uicc_deinit() +{ + if (gdbus_uicc_handle != NULL) { + tel_deinit(gdbus_uicc_handle); + + gdbus_uicc_handle = NULL; + } + + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SIM_STATUS, + _vconf_sim_status_cb); +} +#endif + +static net_nfc_target_handle_s *_se_uicc_open(void) +{ + net_nfc_target_handle_s *result = NULL; + + if (gdbus_uicc_ready == SE_UICC_READY && gdbus_uicc_handle != NULL) { + 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_ready == SE_UICC_READY && + gdbus_uicc_handle != NULL && + (TapiHandle *)handle == gdbus_uicc_handle); +} + +static void _se_uicc_close(net_nfc_target_handle_s *handle) +{ +} + +net_nfc_error_e net_nfc_server_se_apply_se_policy( + net_nfc_secure_element_policy_e policy) +{ + net_nfc_error_e result = NET_NFC_OK; + + net_nfc_controller_secure_element_set_clear_routing_entry(NET_NFC_SE_TECH_ENTRY, &result); + + net_nfc_controller_secure_element_set_clear_routing_entry(NET_NFC_SE_PROTOCOL_ENTRY, &result); + + switch (policy) + { + case SECURE_ELEMENT_POLICY_UICC_ON : + if (gdbus_uicc_ready == SE_UICC_READY) + { + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_ESE, + SECURE_ELEMENT_OFF_MODE, + &result); + + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_HCE, + SECURE_ELEMENT_OFF_MODE, + &result); + + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_UICC, + SECURE_ELEMENT_VIRTUAL_MODE, + &result); +#if 0 + net_nfc_controller_secure_element_set_default_route( + NET_NFC_SE_TYPE_UICC, NET_NFC_SE_TYPE_NONE, + NET_NFC_SE_TYPE_UICC, &result); +#else + net_nfc_controller_secure_element_set_route_entry( + NET_NFC_SE_TECH_ENTRY, NET_NFC_SE_TECH_A_B_ISO_NFC_DEP, + NET_NFC_SE_TYPE_UICC, 0x39, &result); + + net_nfc_controller_secure_element_set_route_entry( + NET_NFC_SE_PROTOCOL_ENTRY, NET_NFC_SE_TECH_A_B_ISO_NFC_DEP, + NET_NFC_SE_TYPE_UICC, 0x39, &result); + +#endif + + current_policy = policy; + } + else + { + current_policy = SECURE_ELEMENT_POLICY_UICC_OFF; + } + break; + + case SECURE_ELEMENT_POLICY_ESE_ON : + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_UICC, + SECURE_ELEMENT_OFF_MODE, + &result); + + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_HCE, + SECURE_ELEMENT_OFF_MODE, + &result); + + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_ESE, + SECURE_ELEMENT_VIRTUAL_MODE, + &result); +#if 0 + net_nfc_controller_secure_element_set_default_route( + NET_NFC_SE_TYPE_ESE, NET_NFC_SE_TYPE_NONE, + NET_NFC_SE_TYPE_ESE, &result); +#else + net_nfc_controller_secure_element_set_route_entry( + NET_NFC_SE_TECH_ENTRY, NET_NFC_SE_TECH_A_B_ISO_NFC_DEP, + NET_NFC_SE_TYPE_ESE, 0x39, &result); + + net_nfc_controller_secure_element_set_route_entry( + NET_NFC_SE_PROTOCOL_ENTRY, NET_NFC_SE_TECH_A_B_ISO_NFC_DEP, + NET_NFC_SE_TYPE_ESE, 0x39, &result); + +#endif + current_policy = policy; + break; + + case SECURE_ELEMENT_POLICY_HCE_ON : + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_UICC, + SECURE_ELEMENT_OFF_MODE, + &result); + + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_ESE, + SECURE_ELEMENT_OFF_MODE, + &result); + + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_HCE, + SECURE_ELEMENT_VIRTUAL_MODE, + &result); +#if 0 + net_nfc_controller_secure_element_set_default_route( + NET_NFC_SE_TYPE_HCE, NET_NFC_SE_TYPE_NONE, + NET_NFC_SE_TYPE_HCE, &result); +#else + net_nfc_controller_secure_element_set_route_entry( + NET_NFC_SE_TECH_ENTRY, NET_NFC_SE_TECH_A_B_ISO_NFC_DEP, + NET_NFC_SE_TYPE_HCE, 0x39, &result); + + net_nfc_controller_secure_element_set_route_entry( + NET_NFC_SE_PROTOCOL_ENTRY, NET_NFC_SE_TECH_A_B_ISO_NFC_DEP, + NET_NFC_SE_TYPE_HCE, 0x39, &result); + +#endif + current_policy = policy; + break; + + case SECURE_ELEMENT_POLICY_UICC_OFF : + case SECURE_ELEMENT_POLICY_ESE_OFF : + case SECURE_ELEMENT_POLICY_HCE_OFF : + default : + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_ESE, + SECURE_ELEMENT_OFF_MODE, + &result); + + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_UICC, + SECURE_ELEMENT_OFF_MODE, + &result); + + net_nfc_controller_set_secure_element_mode( + SECURE_ELEMENT_TYPE_HCE, + SECURE_ELEMENT_OFF_MODE, + &result); +#if 0 + net_nfc_controller_secure_element_set_default_route( + NET_NFC_SE_TYPE_NONE, NET_NFC_SE_TYPE_NONE, + NET_NFC_SE_TYPE_NONE, &result); +#else + net_nfc_controller_secure_element_set_route_entry( + NET_NFC_SE_INVALID_ENTRY, NET_NFC_SE_INVALID_TECH_PROTO, + NET_NFC_SE_TYPE_NONE, 0x39, &result); + + net_nfc_controller_secure_element_set_route_entry( + NET_NFC_SE_INVALID_ENTRY, NET_NFC_SE_INVALID_TECH_PROTO, + NET_NFC_SE_TYPE_NONE, 0x39, &result); + +#endif + current_policy = policy; + break; + } + + return result; +} + +net_nfc_error_e net_nfc_server_se_apply_se_current_policy() +{ + net_nfc_secure_element_policy_e policy; + + policy = __se_get_se_policy(); + + DEBUG_SERVER_MSG("current se policy [%d]", policy); + + return net_nfc_server_se_apply_se_policy(policy); +} + +net_nfc_error_e net_nfc_server_se_change_wallet_mode( + net_nfc_wallet_mode_e wallet_mode) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_secure_element_policy_e new_policy; + bool is_type_changed = false; + bool is_card_mode_changed = false; + + new_policy = __se_get_se_policy(); + + DEBUG_SERVER_MSG("current policy [%d], new policy [%d]", current_policy, new_policy); + + if (__se_get_se_type(current_policy) != __se_get_se_type(new_policy)) { + is_type_changed = true; + } + + if (__se_get_se_state(current_policy) != __se_get_se_state(new_policy)) { + is_card_mode_changed = true; + } + + if (is_type_changed == true || is_card_mode_changed == true) { + result = net_nfc_server_se_apply_se_current_policy(); + } + + if (is_type_changed == true) { + net_nfc_gdbus_secure_element_emit_se_type_changed(NULL, + __se_get_se_type(new_policy)); + } + + if (is_card_mode_changed == true) { + net_nfc_gdbus_secure_element_emit_card_emulation_mode_changed( + NULL, __se_get_se_state(new_policy)); + } + + return result; +} + +static void se_policy_apply_thread_func(gpointer user_data) +{ + net_nfc_error_e result; + + result = net_nfc_server_se_apply_se_current_policy(); +} + +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; + } + + 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); + +#if 0 /* it causes some problems when user repeats open/close */ + /* 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_server_controller_deinit(); + } +#endif +} + +static gboolean se_handle_close_secure_element( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + guint arg_handle, + GVariant *smack_privilege) +{ + SeDataHandle *data = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataHandle, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->handle = (net_nfc_target_handle_s *)arg_handle; + + if (net_nfc_server_controller_async_queue_push_force( + se_close_secure_element_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_close_secure_element( + object, invocation, result); + + return TRUE; +} + +static void se_get_atr_thread_func(gpointer user_data) +{ + SeDataHandle *detail = (SeDataHandle *)user_data; + net_nfc_error_e result = NET_NFC_OK; + data_s *atr = NULL; + GVariant *data; + + g_assert(detail != NULL); + g_assert(detail->object != NULL); + g_assert(detail->invocation != NULL); + + if (_se_is_uicc_handle(detail->handle) == true) + { + if (_se_uicc_get_atr(detail->handle, &atr) == true) { + result = NET_NFC_OK; + } else { + result = NET_NFC_OPERATION_FAIL; + } + } + 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_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 = NULL; + gint 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::ese", + "r") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataHandle, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->handle = (net_nfc_target_handle_s *)arg_handle; + + if (net_nfc_server_controller_async_queue_push_force( + se_get_atr_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_get_atr(object, invocation, + result, net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + return TRUE; +} + +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 (detail->se_type == NET_NFC_SE_TYPE_UICC) + { + 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 == NET_NFC_SE_TYPE_ESE) + { + handle = net_nfc_server_se_open_ese(); + if (handle != NULL) + { + result = NET_NFC_OK; + + 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 = NULL; + gint 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::ese", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataSeType, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->se_type= arg_type; + + if (net_nfc_server_controller_async_queue_push_force( + se_open_secure_element_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_open_secure_element( + object, invocation, result, 0); + + return TRUE; +} + +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 = NET_NFC_OK; + 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) + { + ret = _se_uicc_send_apdu(detail->handle, &apdu_data, &response); + if (ret == false) { + DEBUG_ERR_MSG("_se_uicc_send_apdu failed"); + + result = NET_NFC_OPERATION_FAIL; + } else { + result = NET_NFC_OK; + } + } + 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); + } + + net_nfc_util_clear_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 = NULL; + gint 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::ese", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataApdu, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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); + + if (net_nfc_server_controller_async_queue_push_force( + se_send_apdu_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_variant_unref(data->data); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_send_apdu(object, invocation, + result, net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + return TRUE; +} + +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_OPERATION_FAIL; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + result = net_nfc_server_se_set_se_type(data->se_type); + + if (result == NET_NFC_OK) + 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 = NULL; + gint 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::card_emul", + "w") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataSeType, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->se_type = arg_type; + + if (net_nfc_server_controller_async_queue_push( + se_set_data_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_set(object, invocation, result); + + return TRUE; +} + +static void se_get_data_thread_func(gpointer user_data) +{ + SeDataSeType *data = (SeDataSeType *)user_data; + net_nfc_error_e result = NET_NFC_OK; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + net_nfc_gdbus_secure_element_complete_get(data->object, + data->invocation, + result, + net_nfc_server_se_get_se_type()); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static gboolean se_handle_get( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + GVariant *smack_privilege) +{ + SeDataSeType *data = NULL; + gint 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::card_emul", + "r") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataSeType, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + + if (net_nfc_server_controller_async_queue_push( + se_get_data_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_get(object, invocation, + result, 0); + + return TRUE; +} + +static void _se_change_card_emulation_mode_thread_func(gpointer user_data) +{ + ChangeCardEmulMode *data = (ChangeCardEmulMode *)user_data; + net_nfc_error_e result = NET_NFC_OPERATION_FAIL; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + result = net_nfc_server_se_set_se_state(data->mode); + + net_nfc_gdbus_secure_element_complete_set_card_emulation( + data->object, data->invocation, result); + + if (result == NET_NFC_OK) { + net_nfc_gdbus_secure_element_emit_card_emulation_mode_changed( + data->object, data->mode); + } + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static gboolean se_handle_change_card_emulation_mode( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + gint arg_mode, + GVariant *smack_privilege) +{ + ChangeCardEmulMode *data = NULL; + 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::card_emul", + "w") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(ChangeCardEmulMode, 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"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->mode = arg_mode; + + result = net_nfc_server_controller_async_queue_push( + _se_change_card_emulation_mode_thread_func, data); + if (result == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_set_card_emulation(object, + invocation, result); + + return TRUE; + +} + +static void se_get_secure_element_mode_thread_func(gpointer user_data) +{ + SeDataSeType *data = (SeDataSeType *)user_data; + net_nfc_error_e result = NET_NFC_OK; + net_nfc_card_emulation_mode_t card_emulation_state; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + card_emulation_state = net_nfc_server_se_get_se_state(); + + net_nfc_gdbus_secure_element_complete_get_card_emulation(data->object, + data->invocation, + result, + card_emulation_state); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static void se_enable_transaction_fg_dispatch(gpointer user_data) +{ + SeDataTransactionFgDispatch *data = (SeDataTransactionFgDispatch *)user_data; + net_nfc_error_e result = NET_NFC_OK; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + result = net_nfc_server_gdbus_set_transaction_fg_dispatch( + g_dbus_method_invocation_get_sender(data->invocation), + data->FgDispatch); + + net_nfc_gdbus_secure_element_complete_set_transaction_fg_dispatch ( + data->object, + data->invocation, + result); +} + +static gboolean se_handle_get_card_emulation_mode( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + GVariant *smack_privilege) +{ + SeDataSeType *data = NULL; + gint 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::card_emul", + "r") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataSeType, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + + if (net_nfc_server_controller_async_queue_push( + se_get_secure_element_mode_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_get_card_emulation(object, invocation, + result, 0); + + return TRUE; +} + +static gboolean se_handle_set_transaction_fg_dispatch( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + gint arg_mode, + GVariant *smack_privilege) +{ + SeDataTransactionFgDispatch *data = NULL; + gint 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::card_emul", + "r") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataTransactionFgDispatch, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->FgDispatch= arg_mode; + + if (net_nfc_server_controller_async_queue_push( + se_enable_transaction_fg_dispatch, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_get_card_emulation(object, invocation, + result, 0); + + return TRUE; +} + +static void se_check_transaction_permission(gpointer user_data) +{ + SeDataApdu *data = (SeDataApdu *)user_data; + net_nfc_error_e result; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + result = NET_NFC_OK; + + net_nfc_gdbus_secure_element_complete_check_transaction_permission( + data->object, + data->invocation, + result); + + g_variant_unref(data->data); + g_object_unref(data->invocation); + g_object_unref(data->object); +} + +static gboolean se_handle_check_transaction_permission( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + GVariant *arg_aid, + GVariant *smack_privilege) +{ + SeDataApdu *data = NULL; + gint 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::card_emul", + "r") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataApdu, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->data = g_variant_ref(arg_aid); + + if (net_nfc_server_controller_async_queue_push( + se_check_transaction_permission, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->data); + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_check_transaction_permission( + object, invocation, result); + + return TRUE; +} + +//////////////////////////////////////////////////////////////////////////////// + +static void se_set_default_route_thread_func(gpointer user_data) +{ + SeDefaultRoute *detail = (SeDefaultRoute *)user_data; + net_nfc_error_e result = NET_NFC_OK; + + g_assert(detail != NULL); + g_assert(detail->object != NULL); + g_assert(detail->invocation != NULL); + + INFO_MSG(">>> Call se_set_default_route_thread_func"); + + net_nfc_controller_secure_element_set_default_route(detail->switch_on, + detail->switch_off, detail->battery_off, &result); + + net_nfc_gdbus_secure_element_complete_set_default_route( + detail->object, + detail->invocation, + result); + + g_object_unref(detail->invocation); + g_object_unref(detail->object); + + g_free(detail); +} + +static gboolean se_handle_set_default_route( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + guint switch_on, + guint switch_off, + guint battery_off, + GVariant *smack_privilege) +{ + SeDefaultRoute *data = NULL; + gint 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::card_emul", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDefaultRoute, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->switch_on = switch_on; + data->switch_off = switch_off; + data->battery_off = battery_off; + + if (net_nfc_server_controller_async_queue_push_force( + se_set_default_route_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_set_default_route( + object, invocation, result); + + return TRUE; +} + + + +static void se_is_activated_aid_handler_thread_func(gpointer user_data) +{ + SeDataAid *data = (SeDataAid *)user_data; + net_nfc_error_e result = NET_NFC_OK; + route_table_handler_t *handler; + gboolean activated = false; + const char *id; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + INFO_MSG(">>> Call se_is_activated_aid_handler_thread_func"); + + id = g_dbus_method_invocation_get_sender(data->invocation); + + handler = net_nfc_server_route_table_find_handler_by_id(id); + if (handler != NULL) { + int i; + aid_info_t *info; + + for (i = 0; i < handler->aids[0]->len; i++) { + info = (aid_info_t *)handler->aids[0]->pdata[i]; + + if (g_ascii_strcasecmp(info->aid, data->aid) == 0) { + activated = handler->activated[info->category]; + break; + } + } + + if (i < handler->aids[0]->len) { + result = NET_NFC_OK; + } else { + result = NET_NFC_NO_DATA_FOUND; + } + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + net_nfc_gdbus_secure_element_complete_is_activated_aid_handler( + data->object, data->invocation, result, activated); + + g_free(data->aid); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static gboolean se_handle_is_activated_aid_handler( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + guint se_type, + const gchar *aid, + GVariant *smack_privilege) +{ + SeDataAid *data = NULL; + gint 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::card_emul", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataAid, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->se_type = se_type; + data->aid = g_strdup(aid); + + if (net_nfc_server_controller_async_queue_push_force( + se_is_activated_aid_handler_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_free(data->aid); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_is_activated_aid_handler( + object, invocation, result, false); + + return TRUE; +} + +static void se_is_activated_category_handler_thread_func(gpointer user_data) +{ + SeDataAid *data = (SeDataAid *)user_data; + net_nfc_error_e result; + route_table_handler_t *handler; + gboolean activated = false; + const char *id; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + INFO_MSG(">>> Call se_is_activated_category_handler_thread_func"); + + id = g_dbus_method_invocation_get_sender(data->invocation); + + handler = net_nfc_server_route_table_find_handler_by_id(id); + if (handler != NULL) { + activated = handler->activated[data->category]; + result = NET_NFC_OK; + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + net_nfc_gdbus_secure_element_complete_is_activated_category_handler( + data->object, data->invocation, result, activated); + + g_free(data->aid); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static gboolean se_handle_is_activated_category_handler( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + guint se_type, + guint category, + GVariant *smack_privilege) +{ + SeDataAid *data = NULL; + gint 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::card_emul", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataAid, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->se_type = se_type; + data->category = category; + + if (net_nfc_server_controller_async_queue_push_force( + se_is_activated_category_handler_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_is_activated_category_handler( + object, invocation, result, false); + + return TRUE; +} + +static bool __get_aids_iter_cb(const char *package, + route_table_handler_t *handler, aid_info_t *aid, void *user_data) +{ + gpointer* params = (gpointer *)user_data; + + if (aid->category == (net_nfc_card_emulation_category_t)params[0]) { + g_variant_builder_add((GVariantBuilder *)params[1], + "(sb)", aid->aid, (gboolean)aid->manifest); + } + + return true; +} + +static void se_get_registered_aids_thread_func(gpointer user_data) +{ + SeDataAid *data = (SeDataAid *)user_data; + net_nfc_error_e result = NET_NFC_OK; + const char *id; + GVariantBuilder builder; + GVariant *aids; + gpointer params[2]; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + INFO_MSG(">>> Call se_get_registered_aids_thread_func"); + + id = g_dbus_method_invocation_get_sender(data->invocation); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("a(sb)")); + + params[0] = (gpointer)data->category; + params[1] = &builder; + + net_nfc_server_route_table_iterate_aid_by_id(id, __get_aids_iter_cb, + params); + + aids = g_variant_builder_end(&builder); + + net_nfc_gdbus_secure_element_complete_get_registered_aids( + data->object, data->invocation, result, aids); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static gboolean se_handle_get_registered_aids( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + guint se_type, + guint category, + GVariant *smack_privilege) +{ + SeDataAid *data = NULL; + gint 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::card_emul", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataAid, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->se_type = se_type; + data->category = category; + + if (net_nfc_server_controller_async_queue_push_force( + se_get_registered_aids_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + GVariantBuilder builder; + GVariant *aids; + + g_variant_builder_init(&builder, G_VARIANT_TYPE("a(sb)")); + aids = g_variant_builder_end(&builder); + + net_nfc_gdbus_secure_element_complete_get_registered_aids( + object, invocation, result, aids); + + return TRUE; +} + +static void se_register_aid_thread_func(gpointer user_data) +{ + SeDataAid *data = (SeDataAid *)user_data; + net_nfc_error_e result = NET_NFC_OK; + route_table_handler_t *handler; + const char *id; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + INFO_MSG(">>> Call se_register_aid_thread_func"); + + id = g_dbus_method_invocation_get_sender(data->invocation); + + handler = net_nfc_server_route_table_find_handler_by_id(id); + if (handler == NULL) { + result = net_nfc_server_route_table_add_handler_by_id(id); + if (result == NET_NFC_OK) { + handler = net_nfc_server_route_table_find_handler_by_id(id); + } + } + + if (handler != NULL) { + result = net_nfc_server_route_table_add_aid_by_id(id, + data->se_type, data->category, data->aid); + } + + net_nfc_gdbus_secure_element_complete_register_aid( + data->object, data->invocation, result); + + g_free(data->aid); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static gboolean se_handle_register_aid( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + guint se_type, + guint category, + const gchar *aid, + GVariant *smack_privilege) +{ + SeDataAid *data = NULL; + gint 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::card_emul", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataAid, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->se_type = se_type; + data->category = category; + data->aid = g_strdup(aid); + + if (net_nfc_server_controller_async_queue_push_force( + se_register_aid_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_free(data->aid); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_register_aid( + object, invocation, result); + + return TRUE; +} + +static void se_unregister_aid_thread_func(gpointer user_data) +{ + SeDataAid *data = (SeDataAid *)user_data; + net_nfc_error_e result = NET_NFC_OK; + route_table_handler_t *handler; + const char *id; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + INFO_MSG(">>> Call se_unregister_aid_thread_func"); + + id = g_dbus_method_invocation_get_sender(data->invocation); + + handler = net_nfc_server_route_table_find_handler_by_id(id); + if (handler != NULL) { + net_nfc_server_route_table_del_aid_by_id(id, data->aid, false); + + result = NET_NFC_OK; + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + net_nfc_gdbus_secure_element_complete_unregister_aid( + data->object, data->invocation, result); + + g_free(data->aid); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static gboolean se_handle_unregister_aid( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + guint se_type, + guint category, + const gchar *aid, + GVariant *smack_privilege) +{ + SeDataAid *data = NULL; + gint 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::card_emul", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataAid, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->se_type = se_type; + data->category = category; + data->aid = g_strdup(aid); + + if (net_nfc_server_controller_async_queue_push_force( + se_unregister_aid_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_free(data->aid); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_unregister_aid( + object, invocation, result); + + return TRUE; +} + +static void se_unregister_aids_thread_func(gpointer user_data) +{ + SeDataAid *data = (SeDataAid *)user_data; + net_nfc_error_e result = NET_NFC_OK; + route_table_handler_t *handler; + const char *id; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + INFO_MSG(">>> Call se_unregister_aids_thread_func"); + + id = g_dbus_method_invocation_get_sender(data->invocation); + + handler = net_nfc_server_route_table_find_handler_by_id(id); + if (handler != NULL) { + result = net_nfc_server_route_table_del_aids(id, + handler->package, false); + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + net_nfc_gdbus_secure_element_complete_unregister_aids( + data->object, data->invocation, result); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static gboolean se_handle_unregister_aids( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + guint se_type, + guint category, + GVariant *smack_privilege) +{ + SeDataAid *data = NULL; + gint 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::card_emul", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataAid, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->se_type = se_type; + data->category = category; + + if (net_nfc_server_controller_async_queue_push_force( + se_unregister_aids_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_unregister_aids( + object, invocation, result); + + return TRUE; +} + +static void se_add_route_aid_thread_func(gpointer user_data) +{ + SeDataAid *detail = (SeDataAid *)user_data; + net_nfc_error_e result = NET_NFC_OK; + + g_assert(detail != NULL); + g_assert(detail->object != NULL); + g_assert(detail->invocation != NULL); + + INFO_MSG(">>> Call se_add_route_aid_thread_func"); + + result = net_nfc_server_route_table_insert_aid_into_db(detail->package, + detail->se_type, detail->category, detail->aid, + detail->unlock, detail->power); + + net_nfc_gdbus_secure_element_complete_add_route_aid( + detail->object, detail->invocation, result); + + g_free(detail->aid); + g_free(detail->package); + + g_object_unref(detail->invocation); + g_object_unref(detail->object); + + g_free(detail); +} + +static gboolean se_handle_add_route_aid( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + const gchar *package, + const gchar *aid, + guint se_type, + guint category, + gboolean unlock, + guint power, + GVariant *smack_privilege) +{ + SeDataAid *data = NULL; + gint result; + + INFO_MSG(">>> REQUEST from [%s]", + g_dbus_method_invocation_get_sender(invocation)); +#if 0 + /* 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } +#endif + data = g_try_new0(SeDataAid, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->package = g_strdup(package); + data->aid = g_strdup(aid); + data->se_type = se_type; + data->category = category; + data->unlock = unlock; + data->power = power; + + INFO_MSG(">>> hce_add_aid_thread_func"); + + if (net_nfc_server_controller_async_queue_push_force( + se_add_route_aid_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_free(data->aid); + g_free(data->package); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_add_route_aid(object, invocation, + result); + + return TRUE; +} + +static void se_remove_route_aid_thread_func(gpointer user_data) +{ + SeDataAid *detail = (SeDataAid *)user_data; + net_nfc_error_e result = NET_NFC_OK; + + g_assert(detail != NULL); + g_assert(detail->object != NULL); + g_assert(detail->invocation != NULL); + + INFO_MSG(">>> Call se_remove_route_aid_thread_func"); + + result = net_nfc_server_route_table_delete_aid_from_db(detail->package, + detail->aid); + + net_nfc_gdbus_secure_element_complete_remove_route_aid( + detail->object, detail->invocation, result); + + g_free(detail->aid); + g_free(detail->package); + + g_object_unref(detail->invocation); + g_object_unref(detail->object); + + g_free(detail); +} + + +static gboolean se_handle_remove_route_aid( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + const gchar *package, + const gchar *aid, + GVariant *smack_privilege) +{ + SeDataAid *data = NULL; + gint result; + + INFO_MSG(">>> REQUEST from [%s]", + g_dbus_method_invocation_get_sender(invocation)); +#if 0 + /* 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } +#endif + data = g_try_new0(SeDataAid, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->package = g_strdup(package); + data->aid = g_strdup(aid); + + if (net_nfc_server_controller_async_queue_push_force( + se_remove_route_aid_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_free(data->aid); + g_free(data->package); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_remove_route_aid( + object, invocation, result); + + return TRUE; +} + +static void se_remove_package_aids_thread_func(gpointer user_data) +{ + SeDataAid *detail = (SeDataAid *)user_data; + net_nfc_error_e result = NET_NFC_OK; + + g_assert(detail != NULL); + g_assert(detail->object != NULL); + g_assert(detail->invocation != NULL); + + INFO_MSG(">>> Call se_remove_package_aids_thread_func"); + + result = net_nfc_server_route_table_delete_aids_from_db(detail->package); + if (result == NET_NFC_OK) { + result = net_nfc_server_route_table_del_handler(NULL, + detail->package, true); + } + + net_nfc_gdbus_secure_element_complete_remove_package_aids( + detail->object, detail->invocation, result); + + g_free(detail->package); + + g_object_unref(detail->invocation); + g_object_unref(detail->object); + + g_free(detail); +} + +static gboolean se_handle_remove_package_aids( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + const gchar *package, + const gchar *aid, + GVariant *smack_privilege) +{ + SeDataAid *data = NULL; + gint result; + + INFO_MSG(">>> REQUEST from [%s]", + g_dbus_method_invocation_get_sender(invocation)); +#if 0 + /* 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } +#endif + data = g_try_new0(SeDataAid, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->package = g_strdup(package); + + if (net_nfc_server_controller_async_queue_push_force( + se_remove_package_aids_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_free(data->package); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + net_nfc_gdbus_secure_element_complete_remove_package_aids( + object, invocation, result); + + return TRUE; +} + +static bool __check_category_iter_cb(const char *package, + route_table_handler_t *handler, aid_info_t *aid, void *user_data) +{ + gpointer* params = (gpointer *)user_data; + + if (aid->category == (net_nfc_card_emulation_category_t)params[0]) { + g_variant_builder_add((GVariantBuilder *)params[1], + "(s)", package); + + return false; + } + + return true; +} + +static bool __get_handlers_iter_cb(const char *package, + route_table_handler_t *handler, void *user_data) +{ + /* skip current package */ + if (g_strcmp0(package, "nfc-manager") == 0) { + return true; + } + + net_nfc_server_route_table_iterate_aid(package, + __check_category_iter_cb, user_data); + + return true; +} + +static void se_get_registered_handlers_thread_func(gpointer user_data) +{ + SeDataAid *data = (SeDataAid *)user_data; + net_nfc_error_e result = NET_NFC_OK; + GVariantBuilder builder; + GVariant *handlers; + gpointer params[2]; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + INFO_MSG(">>> Call se_get_registered_aids_thread_func"); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("a(s)")); + +#ifdef ACCESS_CONTROL + pid_t pid; + const char *name; + bool ret = false; + + name = g_dbus_method_invocation_get_sender(data->invocation); + pid = net_nfc_server_gdbus_get_pid(name); + + ret = net_nfc_service_check_access_control(pid, + NET_NFC_ACCESS_CONTROL_PLATFORM); + if (ret == false) + { + DEBUG_ERR_MSG("access control denied"); + result = NET_NFC_SECURITY_FAIL; + + goto END; + } +#endif + params[0] = (gpointer)data->category; + params[1] = &builder; + + net_nfc_server_route_table_iterate_handler(__get_handlers_iter_cb, + params); + +#ifdef ACCESS_CONTROL +END : +#endif + handlers = g_variant_builder_end(&builder); + + net_nfc_gdbus_secure_element_complete_get_registered_handlers( + data->object, data->invocation, result, handlers); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static gboolean se_handle_get_registered_handlers( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + guint se_type, + guint category, + GVariant *smack_privilege) +{ + SeDataAid *data = NULL; + gint 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::admin", + "r") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(SeDataAid, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->category = category; + + if (net_nfc_server_controller_async_queue_push_force( + se_get_registered_handlers_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); + } + + GVariantBuilder builder; + GVariant *packages; + + g_variant_builder_init(&builder, G_VARIANT_TYPE("a(s)")); + packages = g_variant_builder_end(&builder); + + net_nfc_gdbus_secure_element_complete_get_registered_handlers( + object, invocation, result, packages); + + return TRUE; +} + +gboolean net_nfc_server_se_init(GDBusConnection *connection) +{ + GError *error = NULL; + gboolean result; + + if (se_skeleton) + g_object_unref(se_skeleton); + + net_nfc_server_route_table_init(); + +#ifdef ENABLE_TELEPHONY + /* initialize UICC */ + _se_uicc_init(); +#endif + 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-get", + G_CALLBACK(se_handle_get), + NULL); + + g_signal_connect(se_skeleton, + "handle-set-card-emulation", + G_CALLBACK(se_handle_change_card_emulation_mode), + NULL); + + g_signal_connect(se_skeleton, + "handle-get-card-emulation", + G_CALLBACK(se_handle_get_card_emulation_mode), + 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); + + g_signal_connect(se_skeleton, + "handle-set-transaction-fg-dispatch", + G_CALLBACK(se_handle_set_transaction_fg_dispatch), + NULL); + + g_signal_connect(se_skeleton, + "handle-check-transaction-permission", + G_CALLBACK(se_handle_check_transaction_permission), + NULL); + + g_signal_connect(se_skeleton, + "handle-set-default-route", + G_CALLBACK(se_handle_set_default_route), + NULL); + + g_signal_connect(se_skeleton, + "handle-is-activated-aid-handler", + G_CALLBACK(se_handle_is_activated_aid_handler), + NULL); + + g_signal_connect(se_skeleton, + "handle-is-activated-category-handler", + G_CALLBACK(se_handle_is_activated_category_handler), + NULL); + + g_signal_connect(se_skeleton, + "handle-get-registered-aids", + G_CALLBACK(se_handle_get_registered_aids), + NULL); + + g_signal_connect(se_skeleton, + "handle-register-aid", + G_CALLBACK(se_handle_register_aid), + NULL); + + g_signal_connect(se_skeleton, + "handle-unregister-aid", + G_CALLBACK(se_handle_unregister_aid), + NULL); + + g_signal_connect(se_skeleton, + "handle-unregister-aids", + G_CALLBACK(se_handle_unregister_aids), + NULL); + + g_signal_connect(se_skeleton, + "handle-add-route-aid", + G_CALLBACK(se_handle_add_route_aid), + NULL); + + g_signal_connect(se_skeleton, + "handle-remove-route-aid", + G_CALLBACK(se_handle_remove_route_aid), + NULL); + + g_signal_connect(se_skeleton, + "handle-remove-package-aids", + G_CALLBACK(se_handle_remove_package_aids), + NULL); + + g_signal_connect(se_skeleton, + "handle-get-registered-handlers", + G_CALLBACK(se_handle_get_registered_handlers), + 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; + +#ifdef ENABLE_TELEPHONY + /* de-initialize UICC */ + _se_uicc_deinit(); +#endif + } +} + +static void se_detected_thread_func(gpointer user_data) +{ + net_nfc_target_handle_s *handle = NULL; + uint32_t devType = 0; + GVariant *data = NULL; + net_nfc_error_e result = NET_NFC_OK; + + 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; + bool fg_dispatch; + pid_t focus_app_pid; + + g_assert(user_data != NULL); + + if (detail->event == NET_NFC_MESSAGE_SE_START_TRANSACTION) { + GVariant *aid = NULL; + GVariant *param = NULL; + uint8_t se_type; + + aid = net_nfc_util_gdbus_data_to_variant(&(detail->aid)); + param = net_nfc_util_gdbus_data_to_variant(&(detail->param)); + se_type = net_nfc_server_se_get_se_type(); + focus_app_pid = net_nfc_app_util_get_focus_app_pid(); + fg_dispatch = net_nfc_app_util_check_transaction_fg_dispatch(); + + DEBUG_SERVER_MSG("TRANSACTION event fg dispatch [%d]", fg_dispatch); + + /* TODO : check access control */ + net_nfc_gdbus_secure_element_emit_transaction_event( + se_skeleton, + se_type, + aid, + param, + fg_dispatch, + focus_app_pid); + + if (fg_dispatch != true) { + net_nfc_app_util_launch_se_transaction_app( + se_type, + detail->aid.buffer, + detail->aid.length, + detail->param.buffer, + detail->param.length); + } + + DEBUG_SERVER_MSG("launch se app end"); + } + + net_nfc_util_clear_data(&detail->param); + net_nfc_util_clear_data(&detail->aid); + + g_free(detail); +} + +static void se_rf_field_thread_func(gpointer user_data) +{ + DEBUG_SERVER_MSG("check se_skeleton = [0x%p]", se_skeleton); + + if (se_skeleton == NULL) + { + DEBUG_ERR_MSG("se skeleton is not initialized"); + return; + } + + net_nfc_gdbus_secure_element_emit_rf_detected( + se_skeleton); +} + +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_force( + 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_try_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_init_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_init_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_force( + se_transcation_thread_func, detail) == FALSE) { + DEBUG_ERR_MSG("can not push to controller thread"); + + net_nfc_util_clear_data(&detail->param); + net_nfc_util_clear_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_clear_data(&se_event->param); + net_nfc_util_clear_data(&se_event->aid); + + _net_nfc_util_free_mem(info); +} + +void net_nfc_server_se_rf_field_on(void *info) +{ + DEBUG_SERVER_MSG("net_nfc_server_se_rf_field_on"); + + if (net_nfc_server_controller_async_queue_push_force( + se_rf_field_thread_func, + NULL) == FALSE) { + DEBUG_ERR_MSG("can not push to controller thread"); + } + + /* FIXME : should be removed when plugins would be fixed*/ + _net_nfc_util_free_mem(info); +} diff --git a/src/manager/net_nfc_server_snep.c b/src/manager/net_nfc_server_snep.c new file mode 100755 index 0000000..c86c332 --- /dev/null +++ b/src/manager/net_nfc_server_snep.c @@ -0,0 +1,1085 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_debug_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) { + + GDBusConnection *connection; + char *client_id; + void *user_data; + + g_variant_get(parameter, "(usu)", + (guint *)&connection, + &client_id, + (guint *)&user_data); + + g_object_unref(connection); + g_variant_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 = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + 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) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + if (net_nfc_server_controller_async_queue_push( + snep_server_start_thread_func, parameter) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (parameter != NULL) { + g_object_unref(invocation); + g_object_unref(object); + + g_variant_unref(parameter); + } + + net_nfc_gdbus_snep_complete_server_start(object, invocation, result); + + return TRUE; +} + +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 = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + 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) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + if (net_nfc_server_controller_async_queue_push( + snep_client_start_thread_func, parameter) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (parameter != NULL) { + g_object_unref(invocation); + g_object_unref(object); + + g_variant_unref(parameter); + } + + net_nfc_gdbus_snep_complete_client_start(object, invocation, result); + + return TRUE; +} + +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_clear_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 = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + 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) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + if (net_nfc_server_controller_async_queue_push( + snep_client_send_request_thread_func, parameter) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (parameter != NULL) { + g_object_unref(invocation); + g_object_unref(object); + + g_variant_unref(parameter); + } + + net_nfc_gdbus_snep_complete_client_request(object, + invocation, + result, + NET_NFC_LLCP_STOP, + net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + return TRUE; +} + +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 = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + 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) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + if (net_nfc_server_controller_async_queue_push( + snep_stop_service_thread_func, parameter) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (parameter != NULL) { + g_object_unref(invocation); + g_object_unref(object); + + g_variant_unref(parameter); + } + + net_nfc_gdbus_snep_complete_stop_snep(object, + invocation, + result); + + return TRUE; +} + +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 = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + 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) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + if (net_nfc_server_controller_async_queue_push( + snep_register_server_thread_func, parameter) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (parameter != NULL) { + g_object_unref(invocation); + g_object_unref(object); + + g_variant_unref(parameter); + } + + net_nfc_gdbus_snep_complete_server_register(object, + invocation, + result); + + return TRUE; +} + +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 = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + 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) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + if (net_nfc_server_controller_async_queue_push( + snep_unregister_server_thread_func, parameter) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (parameter != NULL) { + g_object_unref(invocation); + g_object_unref(object); + + g_variant_unref(parameter); + } + + net_nfc_gdbus_snep_complete_server_unregister(object, + invocation, + result); + + return TRUE; +} + +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; + } +} diff --git a/src/manager/net_nfc_server_system_handler.c b/src/manager/net_nfc_server_system_handler.c new file mode 100755 index 0000000..96cddab --- /dev/null +++ b/src/manager/net_nfc_server_system_handler.c @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_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, + int 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, + gint state, + gint focus_state, + GVariant *smack_privilege, + gpointer user_data) +{ + int result = NET_NFC_OK; + + 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::common", + "w") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + net_nfc_server_gdbus_set_launch_state( + g_dbus_method_invocation_get_sender(invocation), + state, focus_state); + +ERROR : + + net_nfc_gdbus_popup_complete_set(popup_manager, invocation, result); + + return TRUE; +} + +static gboolean popup_handle_get(NetNfcGDbusPopup *popup_manager, + GDBusMethodInvocation *invocation, + GVariant *smack_privilege, + gpointer user_data) +{ + gboolean state = FALSE; + int result = NET_NFC_OK; + + 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::common", + "r") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + state = net_nfc_server_gdbus_get_launch_state( + g_dbus_method_invocation_get_sender(invocation)); + +ERROR : + + net_nfc_gdbus_popup_complete_get(popup_manager, invocation, + result, 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); + + net_nfc_server_system_handler_deinit(); + } + + return result; +} + +void net_nfc_server_system_handler_deinit(void) +{ + if (popup_skeleton) + { + g_object_unref(popup_skeleton); + popup_skeleton = NULL; + } +} diff --git a/src/manager/net_nfc_server_tag.c b/src/manager/net_nfc_server_tag.c new file mode 100755 index 0000000..19f6e73 --- /dev/null +++ b/src/manager/net_nfc_server_tag.c @@ -0,0 +1,951 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include + +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_manager_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" + +#define CHECK_PRESENCE_DELAY 50 /* ms */ + +typedef struct _CurrentTagInfoData CurrentTagInfoData; + +struct _CurrentTagInfoData +{ + NetNfcGDbusTag *tag; + GDBusMethodInvocation *invocation; +}; + +typedef struct _CheckPresenceData CheckPresenceData; + +struct _CheckPresenceData +{ + net_nfc_target_type_e dev_type; + net_nfc_target_handle_s *handle; +}; + +static gboolean tag_read_ndef_message(net_nfc_target_handle_s *handle, + int dev_type, + data_s **read_ndef); + +static void tag_check_presence_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_barcode(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; +#if 0 +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); + } + else + { + DEBUG_ERR_MSG("response is NULL"); + } + + return result; +} +#endif +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 0 + 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"); +#endif + if (net_nfc_controller_connect(handle, &result) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_connect failed"); +#if 0 + DEBUG_ERR_MSG("net_nfc_controller_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(); + } +#endif + return FALSE; + } + } + + if (net_nfc_controller_read_ndef(handle, &temp, &result) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_read_ndef failed, [%d]", result); + + return FALSE; + } + + DEBUG_SERVER_MSG("net_nfc_controller_read_ndef success"); + + if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC) + { + if (net_nfc_controller_connect(handle, &result) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_connect failed"); +#if 0 + DEBUG_ERR_MSG("net_nfc_controller_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(); + } +#endif + if (temp) + { + net_nfc_util_free_data(temp); + temp = NULL; + } + + return FALSE; + } + } + + *read_ndef = temp; + + return TRUE; +} + +static void tag_check_presence_thread_func(gpointer user_data) +{ + CheckPresenceData *data = (CheckPresenceData *)user_data; + net_nfc_error_e result = NET_NFC_OK; + net_nfc_target_handle_s *handle; + + g_assert(data != NULL); + g_assert(data->handle != NULL); + + handle = data->handle; + + if (handle->connection_type == NET_NFC_P2P_CONNECTION_TARGET || + handle->connection_type == NET_NFC_TAG_CONNECTION) + { + bool present = false; + + present = net_nfc_controller_check_target_presence( + handle, &result); + if (present == true) { + net_nfc_server_controller_async_queue_delayed_push_force( + CHECK_PRESENCE_DELAY, + tag_check_presence_thread_func, + user_data); + } else { + INFO_MSG("all tags were detached"); + + if (result != NET_NFC_NOT_INITIALIZED && + result != NET_NFC_INVALID_HANDLE) + { + if (net_nfc_controller_disconnect(handle, + &result) == false) + { + DEBUG_ERR_MSG("try to disconnect result = [%d]", result); +#if 0 + net_nfc_controller_exception_handler(); +#endif + } + } + + goto END; + } + } else { + DEBUG_ERR_MSG("abnormal state"); + + goto END; + } + + return; + +END : + net_nfc_server_free_target_info(); + + net_nfc_server_set_state(NET_NFC_SERVER_IDLE); + + net_nfc_gdbus_tag_emit_tag_detached(tag_skeleton, + GPOINTER_TO_UINT(handle), + data->dev_type); + + g_free(data); +} + +static data_s *_get_barcode_from_target_info(net_nfc_current_target_info_s *target_info) +{ + gint i = 0; + gint length; + data_s *data = NULL; + gchar *str = NULL; + guint8 *pos = target_info->target_info_values.buffer; + + while (i < target_info->number_of_keys) + { + /* 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; + + length = *pos; /* first value is length of value */ + pos++; + + if(strncmp(str, "UID", 3) == 0 && length > 0) + { + data = (data_s *)calloc(1, sizeof(data_s)); + if(data == NULL) + return NULL; + + data->length = length; + + data->buffer = (uint8_t *)calloc(data->length, sizeof(uint8_t)); + if(data->buffer == NULL) + { + free(data); + return NULL; + } + + memcpy(data->buffer, pos, data->length); + + break; + } + + pos += length; + i++; + } + + if(str != NULL) + g_free(str); + + return data; +} + +static void tag_get_barcode_thread_func(gpointer user_data) +{ + data_s *data = NULL; + net_nfc_current_target_info_s *target_info; + net_nfc_error_e result = NET_NFC_OPERATION_FAIL; + CurrentTagInfoData *info_data = (CurrentTagInfoData *)user_data; + + 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) + { + if (target_info->devType == NET_NFC_BARCODE_128_PICC || + target_info->devType == NET_NFC_BARCODE_256_PICC) + { + data = _get_barcode_from_target_info(target_info); + + if(data != NULL && data->length != 0 && data->buffer != NULL) + result = NET_NFC_OK; + } + else + { + result = NET_NFC_NOT_SUPPORTED; + } + } + else + { + result = NET_NFC_NOT_CONNECTED; + } + + net_nfc_gdbus_tag_complete_get_barcode(info_data->tag, + info_data->invocation, + result, + net_nfc_util_gdbus_data_to_variant(data)); + + if (data != NULL) { + net_nfc_util_free_data(data); + } + + g_object_unref(info_data->invocation); + g_object_unref(info_data->tag); + + g_free(info_data); +} + +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_OPERATION_FAIL; + 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, + result, + (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_object_unref(info_data->invocation); + g_object_unref(info_data->tag); + + g_free(info_data); +} + +static bool _is_supported_tags(net_nfc_current_target_info_s *target) +{ + return true; +} + +static void _start_check_presence(net_nfc_current_target_info_s *target) +{ + CheckPresenceData *presence_data = NULL; + + /* start polling tags presence */ + INFO_MSG("start polling tags presence"); + + presence_data = g_new0(CheckPresenceData, 1); + presence_data->dev_type = target->devType; + presence_data->handle = target->handle; + + net_nfc_server_controller_async_queue_delayed_push_force( + CHECK_PRESENCE_DELAY, + tag_check_presence_thread_func, + presence_data); +} + +static bool _process_attached_tags(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; + + net_nfc_server_set_target_info(target); + target = net_nfc_server_get_target_info(); + + g_assert(target != NULL); + + if (net_nfc_controller_connect(target->handle, &result) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_connect failed, [%d]", result); +#if 0 + DEBUG_ERR_MSG("net_nfc_controller_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(); + } +#endif + return false; + } + + net_nfc_server_set_state(NET_NFC_TAG_CONNECTED); + + INFO_MSG("tags are connected"); + + target_info_values = net_nfc_util_gdbus_buffer_to_variant( + target->target_info_values.buffer, + target->target_info_values.length); +#if 1 + if (_is_supported_tags(target) == true) { +#endif + is_ndef_supported = net_nfc_controller_check_ndef(target->handle, + &ndef_card_state, + (int *)&max_data_size, + (int *)&actual_data_size, + &result); + 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) + { + net_nfc_app_util_process_ndef(recv_data); + raw_data = net_nfc_util_gdbus_data_to_variant(recv_data); + + net_nfc_util_free_data(recv_data); + } + else + { + DEBUG_ERR_MSG("tag_read_ndef_message 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 1 + } else { + INFO_MSG("unsupported tags are attached"); + + net_nfc_app_util_show_notification(IDS_SIGNAL_1, NULL); + + raw_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0); + } +#endif + + if (tag_skeleton != NULL) { + /* 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); + + net_nfc_manager_util_play_sound(NET_NFC_TASK_START); + } else { + DEBUG_ERR_MSG("tag skeleton is not initialized"); + } + + return true; +} + +static void tag_slave_target_detected_thread_func(gpointer user_data) +{ + net_nfc_current_target_info_s *target = + (net_nfc_current_target_info_s *)user_data; + +#if 0 + if (_is_supported_tags(target) == true) { +#endif + if (_process_attached_tags(target) == false) { + DEBUG_ERR_MSG("_process_attached_tags failed"); + } +#if 0 + } else { + INFO_MSG("unsupported tags are attached"); + + net_nfc_app_util_show_notification(IDS_SIGNAL_1); + + } +#endif + + _start_check_presence(target); + + g_free(user_data); +} + + +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; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto END; + } + + target_info = net_nfc_server_get_target_info(); + if (target_info != NULL) + { + dev_type = target_info->devType; + is_connected = TRUE; + } + + result = NET_NFC_OK; + +END : + net_nfc_gdbus_tag_complete_is_tag_connected(tag, + invocation, + result, + is_connected, + (gint32)dev_type); + + return TRUE; +} + +static gboolean tag_handle_get_barcode(NetNfcGDbusTag *tag, + GDBusMethodInvocation *invocation, + GVariant *smack_privilege, + gpointer user_data) +{ + CurrentTagInfoData *info_data = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + info_data = g_try_new0(CurrentTagInfoData, 1); + if (info_data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + info_data->tag = g_object_ref(tag); + info_data->invocation = g_object_ref(invocation); + + if (net_nfc_server_controller_async_queue_push( + tag_get_barcode_thread_func, info_data) == FALSE) + { + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + return TRUE; + +ERROR : + + if (info_data != NULL) { + g_object_unref(info_data->invocation); + g_object_unref(info_data->tag); + + g_free(info_data); + } + + net_nfc_gdbus_tag_complete_get_barcode(tag, + invocation, + result, + net_nfc_util_gdbus_data_to_variant(NULL)); + + return TRUE; +} + +static gboolean tag_handle_get_current_tag_info(NetNfcGDbusTag *tag, + GDBusMethodInvocation *invocation, + GVariant *smack_privilege, + gpointer user_data) +{ + CurrentTagInfoData *info_data = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + info_data = g_try_new0(CurrentTagInfoData, 1); + if (info_data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + info_data->tag = g_object_ref(tag); + info_data->invocation = g_object_ref(invocation); + + if (net_nfc_server_controller_async_queue_push( + tag_get_current_tag_info_thread_func, info_data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (info_data != NULL) { + g_object_unref(info_data->invocation); + g_object_unref(info_data->tag); + + g_free(info_data); + } + + net_nfc_gdbus_tag_complete_get_current_tag_info(tag, + invocation, + result, + false, + GPOINTER_TO_UINT(NULL), + NET_NFC_UNKNOWN_TARGET, + false, + 0, + 0, + 0, + 0, + net_nfc_util_gdbus_buffer_to_variant(NULL, 0), + net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + return TRUE; +} + +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; + gint 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::p2p", + "r") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto END; + } + + target_info = net_nfc_server_get_target_info(); + if (target_info != NULL) + { + handle = target_info->handle; + devType = target_info->devType; + } + + result = NET_NFC_OK; + +END : + net_nfc_gdbus_tag_complete_get_current_target_handle(tag, + invocation, + result, + (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-barcode", + G_CALLBACK(tag_handle_get_barcode), + 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(net_nfc_current_target_info_s *info) +{ + if (current_target_info) + g_free(current_target_info); + + current_target_info = g_malloc0(sizeof(net_nfc_current_target_info_s) + + info->target_info_values.length); + + current_target_info->handle = info->handle; + current_target_info->devType = info->devType; + + if (current_target_info->devType != NET_NFC_NFCIP1_INITIATOR && + current_target_info->devType != NET_NFC_NFCIP1_TARGET) + { + current_target_info->number_of_keys = info->number_of_keys; + current_target_info->target_info_values.length = + info->target_info_values.length; + + memcpy(¤t_target_info->target_info_values, + &info->target_info_values, + current_target_info->target_info_values.length + sizeof(int)); + } +} + +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; +} + +bool net_nfc_server_tag_target_detected(void *info) +{ + if (net_nfc_server_controller_async_queue_push_force( + tag_slave_target_detected_thread_func, info) == FALSE) + { + DEBUG_ERR_MSG("can not push to controller thread"); + return false; + } + + return true; +} diff --git a/src/manager/net_nfc_server_test.c b/src/manager/net_nfc_server_test.c new file mode 100755 index 0000000..dbe0478 --- /dev/null +++ b/src/manager/net_nfc_server_test.c @@ -0,0 +1,687 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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); + + net_nfc_util_free_data(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_clear_data(&data->data); + + g_object_unref(data->invocation); + g_object_unref(data->test); + + g_free(data); +} + +static void test_handle_ese_test_thread_func(gpointer user_data) +{ + TestData *data = (TestData *)user_data; + net_nfc_error_e result = NET_NFC_OK; + + DEBUG_SERVER_MSG("test_handle_ese_test_thread_func working!!"); + + g_assert(data != NULL); + g_assert(data->test != NULL); + g_assert(data->invocation != NULL); + + net_nfc_controller_ese_test(&result); + + net_nfc_gdbus_test_complete_ese_test(data->test, + data->invocation, + (gint)result); + + 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 = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + DEBUG_SERVER_MSG("sim_test"); + + data = g_try_new0(TestData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->test = g_object_ref(test); + data->invocation = g_object_ref(invocation); + + if (net_nfc_server_controller_async_queue_push( + test_handle_sim_test_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->test); + + g_free(data); + } + + net_nfc_gdbus_test_complete_sim_test(test, invocation, result); + + return TRUE; +} + +static gboolean test_handle_prbs_test(NetNfcGDbusTest *test, + GDBusMethodInvocation *invocation, + guint32 arg_tech, + guint32 arg_rate, + GVariant *smack_privilege, + gpointer user_data) +{ + TestPrbsData *data = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + DEBUG_SERVER_MSG("prbs_test"); + + data = g_try_new0(TestPrbsData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->test = g_object_ref(test); + data->invocation = g_object_ref(invocation); + data->tech = arg_tech; + data->rate = arg_rate; + + if (net_nfc_server_controller_async_queue_push( + test_handle_prbs_test_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->test); + + g_free(data); + } + + net_nfc_gdbus_test_complete_prbs_test(test, invocation, result); + + return TRUE; +} + +static gboolean test_handle_get_firmware_version(NetNfcGDbusTest *test, + GDBusMethodInvocation *invocation, + GVariant *smack_privilege, + gpointer user_data) +{ + TestData *data = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(TestData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->test = g_object_ref(test); + data->invocation = g_object_ref(invocation); + + if (net_nfc_server_controller_async_queue_push( + test_handle_get_firmware_version_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->test); + + g_free(data); + } + + net_nfc_gdbus_test_complete_get_firmware_version(test, + invocation, + result, + NULL); + + return TRUE; +} + +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 = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(TestSetEeData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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); + + if (net_nfc_server_controller_async_queue_push( + test_handle_set_ee_data_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->test); + + g_free(data); + } + + net_nfc_gdbus_test_complete_set_ee_data(test, invocation, result); + + return TRUE; +} + +static gboolean test_handle_ese_test(NetNfcGDbusTest *test, + GDBusMethodInvocation *invocation, + GVariant *smack_privilege, + gpointer user_data) +{ + TestData *data = NULL; + gint result; + + INFO_MSG(">>> ESE TEST REQUEST from [%s]", + g_dbus_method_invocation_get_sender(invocation)); +#if 0 + /* 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } +#endif + DEBUG_SERVER_MSG("ese_test"); + + data = g_try_new0(TestData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->test = g_object_ref(test); + data->invocation = g_object_ref(invocation); + + if (net_nfc_server_controller_async_queue_push( + test_handle_ese_test_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->test); + + g_free(data); + } + + net_nfc_gdbus_test_complete_ese_test(test, invocation, result); + + return TRUE; +} + +static void test_handle_set_se_tech_type_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_test_set_se_tech_type(&result, + (net_nfc_se_type_e)data->mode, data->reg_id); + + net_nfc_gdbus_test_complete_set_se_tech_type(data->test, + data->invocation, + (gint)result); + + g_object_unref(data->invocation); + g_object_unref(data->test); + + g_free(data); +} + +static gboolean test_handle_set_se_tech_type(NetNfcGDbusTest *test, + GDBusMethodInvocation *invocation, + guint32 type, + guint32 tech, + GVariant *smack_privilege, + gpointer user_data) +{ + TestSetEeData *data = NULL; + gint 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"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(TestSetEeData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + data->test = g_object_ref(test); + data->invocation = g_object_ref(invocation); + data->mode = type; + data->reg_id = tech; + + if (net_nfc_server_controller_async_queue_push( + test_handle_set_se_tech_type_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + g_object_unref(data->invocation); + g_object_unref(data->test); + + g_free(data); + } + + net_nfc_gdbus_test_complete_set_se_tech_type(test, invocation, result); + + return TRUE; +} + +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); + + g_signal_connect(test_skeleton, + "handle-ese-test", + G_CALLBACK(test_handle_ese_test), + NULL); + + g_signal_connect(test_skeleton, + "handle-set-se-tech-type", + G_CALLBACK(test_handle_set_se_tech_type), + 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; + } +} diff --git a/src/manager/net_nfc_server_transceive.c b/src/manager/net_nfc_server_transceive.c new file mode 100755 index 0000000..d2ab79e --- /dev/null +++ b/src/manager/net_nfc_server_transceive.c @@ -0,0 +1,359 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 = NET_NFC_OK; + 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) + { + net_nfc_util_free_data(data); + } + + net_nfc_util_clear_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 = NULL; + gint 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", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(TransceiveSendData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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); + + if (net_nfc_server_controller_async_queue_push( + transceive_data_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + net_nfc_util_clear_data(&data->transceive_info.trans_data); + + g_object_unref(data->invocation); + g_object_unref(data->transceive); + + g_free(data); + } + + net_nfc_gdbus_transceive_complete_transceive_data( + transceive, + invocation, + result, + net_nfc_util_gdbus_buffer_to_variant(NULL, 0)); + + return TRUE; +} + +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 */ + net_nfc_util_free_data(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_clear_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 = NULL; + gint 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", + "rw") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + result = NET_NFC_PERMISSION_DENIED; + + goto ERROR; + } + + data = g_try_new0(TransceiveSendData, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + result = NET_NFC_ALLOC_FAIL; + + goto ERROR; + } + + 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); + + if (net_nfc_server_controller_async_queue_push( + transceive_thread_func, data) == FALSE) + { + /* return error if queue was blocked */ + DEBUG_SERVER_MSG("controller is processing important message.."); + result = NET_NFC_BUSY; + + goto ERROR; + } + + return TRUE; + +ERROR : + if (data != NULL) { + net_nfc_util_clear_data(&data->transceive_info.trans_data); + + g_object_unref(data->invocation); + g_object_unref(data->transceive); + + g_free(data); + } + + net_nfc_gdbus_transceive_complete_transceive(transceive, + invocation, result); + + return TRUE; +} + + +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; + } +} diff --git a/src/manager/net_nfc_server_vconf.c b/src/manager/net_nfc_server_vconf.c new file mode 100755 index 0000000..c52784e --- /dev/null +++ b/src/manager/net_nfc_server_vconf.c @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "net_nfc_typedef.h" +#include "net_nfc_debug_internal.h" +#include "net_nfc_server_common.h" +#include "net_nfc_server_manager.h" +#include "net_nfc_server_se.h" +#include "net_nfc_server_route_table.h" +#include "net_nfc_server_vconf.h" + +static void net_nfc_server_vconf_lock_state_changed(keynode_t *key, + void *user_data); + +static void net_nfc_server_vconf_pm_state_changed(keynode_t *key, + void *user_data); + +#ifdef ENABLE_TELEPHONY +static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key, + void *user_data); +#endif + +static void net_nfc_server_vconf_lock_state_changed(keynode_t *key, + void *user_data) +{ + + gint state = 0; + gint result; + gint lock_state = 0; + + 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; + } + + if (vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state) != 0) + DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_IDLE_LOCK_STATE"); + + + if (lock_state == VCONFKEY_IDLE_UNLOCK || + lock_state == VCONFKEY_IDLE_LOCK) + { + net_nfc_server_restart_polling_loop(); + } + +} + +static void net_nfc_server_vconf_pm_state_changed(keynode_t *key, + void *user_data) +{ + gint state = 0; + gint pm_state = 0; + gint lock_screen_set = 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); + + result = vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &lock_screen_set); + + if (result != 0) + DEBUG_ERR_MSG("can not get %s", "VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT"); + + DEBUG_SERVER_MSG("lock_screen_set : %d", lock_screen_set); + +#if 0 + if ( lock_screen_set == SETTING_SCREEN_LOCK_TYPE_NONE && + (pm_state == VCONFKEY_PM_STATE_NORMAL || + pm_state == VCONFKEY_PM_STATE_LCDOFF) ) +#endif + 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_se_type_changed(keynode_t *key, + void *user_data) +{ + net_nfc_server_se_policy_apply(); +} + +void net_nfc_server_vconf_init(void) +{ + vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE, + net_nfc_server_vconf_lock_state_changed, + NULL); +#if 1 + vconf_notify_key_changed(VCONFKEY_PM_STATE, + net_nfc_server_vconf_pm_state_changed, + NULL); +#endif + + vconf_notify_key_changed(VCONFKEY_NFC_SE_TYPE, + net_nfc_server_vconf_se_type_changed, + NULL); +} + +void net_nfc_server_vconf_deinit(void) +{ + vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE, + net_nfc_server_vconf_lock_state_changed); + + vconf_ignore_key_changed(VCONFKEY_NFC_SE_TYPE, + net_nfc_server_vconf_se_type_changed); +} + +bool net_nfc_check_csc_vconf(void) +{ + int state = 0;; + gint result = 0; + + if (state == true) + { + DEBUG_ERR_MSG("This is CSC Booting!!"); + return true; + } + else + { + DEBUG_ERR_MSG("This is Normal Booting!!"); + return false; + } +} + +bool net_nfc_check_start_polling_vconf(void) +{ + gint lock_state = 0; + gint lock_screen_set = 0; + gint pm_state = 0; + + if (vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state) != 0) + DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_IDLE_LOCK_STATE"); + + if (vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &lock_screen_set) != 0) + DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT"); + + if (vconf_get_int(VCONFKEY_PM_STATE, &pm_state) != 0) + DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_PM_STATE"); + + + DEBUG_SERVER_MSG("lock_screen_set:%d ,pm_state:%d,lock_state:%d", + lock_screen_set , pm_state , lock_state); + + if (lock_state == VCONFKEY_IDLE_UNLOCK) + { + DEBUG_SERVER_MSG("polling enable"); + return TRUE; + } + + if (lock_state == VCONFKEY_IDLE_LOCK || pm_state == VCONFKEY_PM_STATE_LCDOFF) + { + DEBUG_SERVER_MSG("polling disabled"); + return FALSE; + } + + return FALSE; +} diff --git a/src/manager/net_nfc_service.c b/src/manager/net_nfc_service.c deleted file mode 100644 index bbea88d..0000000 --- a/src/manager/net_nfc_service.c +++ /dev/null @@ -1,821 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "vconf.h" - -#include "net_nfc_controller_private.h" -#include "net_nfc_util_private.h" -#include "net_nfc_typedef.h" -#include "net_nfc_debug_private.h" -#include "net_nfc_service_private.h" -#include "net_nfc_service_se_private.h" -#include "net_nfc_app_util_private.h" -#include "net_nfc_server_ipc_private.h" -#include "net_nfc_server_dispatcher_private.h" -#include "net_nfc_manager_util_private.h" -#include "net_nfc_service_tag_private.h" -#include "net_nfc_service_llcp_private.h" -#include "net_nfc_util_ndef_message.h" -#include "net_nfc_util_ndef_record.h" -#include "net_nfc_server_context_private.h" - -/* static variable */ - -/* static callback function */ - -/* static function */ - -#ifndef BROADCAST_MESSAGE -extern uint8_t g_se_cur_type; -extern uint8_t g_se_cur_mode; - -static bool _net_nfc_service_check_internal_ese_detected() -{ - if (g_se_cur_type == SECURE_ELEMENT_TYPE_ESE && g_se_cur_mode == SECURE_ELEMENT_WIRED_MODE) - { - return true; - } - - return false; -} -#endif - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -void net_nfc_service_target_detected_cb(void *info, void *user_context) -{ - net_nfc_request_msg_t *req_msg = (net_nfc_request_msg_t *)info; - - if (info == NULL) - return; - - if (req_msg->request_type == NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP) - { - net_nfc_dispatcher_queue_push(req_msg); - } -#ifdef BROADCAST_MESSAGE - else - { - net_nfc_server_set_tag_info(info); - - req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED; - net_nfc_dispatcher_queue_push(req_msg); - } -#else - else if (net_nfc_server_get_current_client_context(&client_context) == true && - net_nfc_server_check_client_is_running(&client_context) == true) - { - net_nfc_request_target_detected_t *detail = (net_nfc_request_target_detected_t *)req_msg; - - /* If target detected, sound should be played. */ - net_nfc_manager_util_play_sound(NET_NFC_TASK_START); - - net_nfc_server_set_tag_info(info); - - if (!_net_nfc_service_check_internal_ese_detected()) - { - req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED; - } - else - { - req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED; - - (detail->handle)->connection_type = NET_NFC_SE_CONNECTION; - } - - net_nfc_server_set_current_client_target_handle(client_context, detail->handle); - - net_nfc_dispatcher_queue_push(req_msg); - - DEBUG_SERVER_MSG("current client is listener. stand alone mode will be activated"); - } - else - { - /* If target detected, sound should be played. */ - net_nfc_manager_util_play_sound(NET_NFC_TASK_START); - - req_msg->request_type = NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED; - net_nfc_dispatcher_queue_push(req_msg); - } -#endif -} - -void net_nfc_service_se_transaction_cb(void *info, void *user_context) -{ - net_nfc_request_se_event_t *req_msg = (net_nfc_request_se_event_t *)info; - - DEBUG_SERVER_MSG("se event [%d]", req_msg->request_type); - - net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)req_msg); -} - -void net_nfc_service_llcp_event_cb(void* info, void* user_context) -{ - net_nfc_request_llcp_msg_t *req_msg = (net_nfc_request_llcp_msg_t *)info; - - if (req_msg == NULL) - { - DEBUG_SERVER_MSG("req msg is null"); - return; - } - - if (req_msg->request_type == NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT) - { - net_nfc_request_accept_socket_t *detail = (net_nfc_request_accept_socket_t *)req_msg; - detail->trans_param = user_context; - } - - req_msg->user_param = (uint32_t)user_context; - - net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)req_msg); -} - -static bool _is_isp_dep_ndef_formatable(net_nfc_target_handle_s *handle, int dev_type) -{ - bool result = false; - uint8_t cmd[] = { 0x90, 0x60, 0x00, 0x00, 0x00 }; - net_nfc_transceive_info_s info; - data_s *response = NULL; - net_nfc_error_e error = NET_NFC_OK; - - info.dev_type = dev_type; - info.trans_data.buffer = cmd; - info.trans_data.length = sizeof(cmd); - - if (net_nfc_controller_transceive(handle, &info, &response, &error) == true) - { - if (response != NULL) - { - if (response->length == 9 && response->buffer[7] == (uint8_t)0x91 && - response->buffer[8] == (uint8_t)0xAF) - { - result = true; - } - else - { - DEBUG_ERR_MSG("Unknown response...."); - DEBUG_MSG_PRINT_BUFFER(response->buffer, response->length); - } - } - else - { - DEBUG_ERR_MSG("net_nfc_controller_transceive response is null"); - } - } - else - { - DEBUG_ERR_MSG("net_nfc_controller_transceive is failed, [%d]", error); - } - - return result; -} - -static net_nfc_error_e _read_ndef_message(net_nfc_target_handle_s *handle, int dev_type, data_s **read_ndef) -{ - net_nfc_error_e result = NET_NFC_OK; - data_s *temp = NULL; - - if (handle == NULL || read_ndef == NULL) - return NET_NFC_INVALID_PARAM; - - *read_ndef = NULL; - - /* Desfire */ - if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC) - { - DEBUG_SERVER_MSG("DESFIRE : check ISO-DEP ndef formatable"); - - if (_is_isp_dep_ndef_formatable(handle, dev_type) == true) - { - DEBUG_SERVER_MSG("DESFIRE : ISO-DEP ndef formatable"); - - if (!net_nfc_controller_connect(handle, &result)) - { - DEBUG_ERR_MSG("net_nfc_controller_connect failed & Retry Polling!!"); - - if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, - NET_NFC_ALL_ENABLE, &result) == false) - { - net_nfc_controller_exception_handler(); - } - - return NET_NFC_TAG_READ_FAILED; - } - } - else - { - DEBUG_ERR_MSG("DESFIRE : ISO-DEP ndef not formatable"); - - return NET_NFC_TAG_READ_FAILED; - } - } - - if (net_nfc_controller_read_ndef(handle, &temp, &result) == true) - { - DEBUG_SERVER_MSG("net_nfc_controller_read_ndef success"); - - if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC) - { - if (!net_nfc_controller_connect(handle, &result)) - { - DEBUG_ERR_MSG("net_nfc_controller_connect failed & Retry Polling!!"); - - if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, NET_NFC_ALL_ENABLE, &result) == false) - { - net_nfc_controller_exception_handler(); - } - - net_nfc_util_free_data(temp); - _net_nfc_util_free_mem(temp); - - return NET_NFC_TAG_READ_FAILED; - } - } - - *read_ndef = temp; - } - else - { - DEBUG_ERR_MSG("net_nfc_controller_read_ndef failed [%d]", result); - } - - return result; -} - -#ifndef BROADCAST_MESSAGE -bool net_nfc_service_standalone_mode_target_detected(net_nfc_request_msg_t* msg) -{ - net_nfc_request_target_detected_t* stand_alone = (net_nfc_request_target_detected_t *)msg; - net_nfc_error_e error_status = NET_NFC_OK; - - data_s *recv_data = NULL; - - DEBUG_SERVER_MSG("*** Detected! type [0x%X)] ***", stand_alone->devType); - - switch (stand_alone->devType) - { - case NET_NFC_NFCIP1_TARGET : - case NET_NFC_NFCIP1_INITIATOR : - { - DEBUG_SERVER_MSG(" LLCP is detected"); - - net_nfc_service_llcp_process(stand_alone->handle, stand_alone->devType, &error_status); - - malloc_trim(0); - return true; - } - break; - - default : - { - DEBUG_SERVER_MSG(" PICC or PCD is detectd."); - recv_data = net_nfc_service_tag_process(stand_alone->handle, stand_alone->devType, &error_status); - } - break; - } - - if (recv_data != NULL) - { - net_nfc_service_msg_processing(recv_data); - } - else - { - if (((stand_alone->devType == NET_NFC_NFCIP1_INITIATOR) || (stand_alone->devType == NET_NFC_NFCIP1_TARGET))) - { - DEBUG_SERVER_MSG("p2p operation. recv data is NULL"); - } - else - { - if (error_status == NET_NFC_NO_NDEF_SUPPORT) - { - DEBUG_SERVER_MSG("device type = [%d], it has null data", stand_alone->devType); - - /* launch empty tag */ - uint8_t empty[] = { 0xd0, 0x00, 0x00 }; /* raw-data of empty ndef-message */ - data_s rawdata = { &empty, sizeof(empty) }; - - net_nfc_service_msg_processing(&rawdata); - } - } - } - - if (stand_alone->devType != NET_NFC_NFCIP1_INITIATOR && stand_alone->devType != NET_NFC_NFCIP1_TARGET) - { - net_nfc_request_watch_dog_t* watch_dog_msg = NULL; - - _net_nfc_util_alloc_mem(watch_dog_msg, sizeof(net_nfc_request_watch_dog_t)); - - if (watch_dog_msg != NULL) - { - watch_dog_msg->length = sizeof(net_nfc_request_watch_dog_t); - watch_dog_msg->request_type = NET_NFC_MESSAGE_SERVICE_WATCH_DOG; - watch_dog_msg->devType = stand_alone->devType; - watch_dog_msg->handle = stand_alone->handle; - - net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)watch_dog_msg); - } - } - - DEBUG_SERVER_MSG("stand alone mode is end"); - malloc_trim(0); - - return true; -} -#endif - -bool net_nfc_service_slave_mode_target_detected(net_nfc_request_msg_t *msg) -{ - net_nfc_request_target_detected_t *detail_msg = (net_nfc_request_target_detected_t *)msg; - net_nfc_error_e result = NET_NFC_OK; - bool success = true; - - DEBUG_SERVER_MSG("target detected callback for client, device type = [%d]", detail_msg->devType); - - if (detail_msg == NULL) - { - return false; - } - - if (detail_msg->devType != NET_NFC_NFCIP1_TARGET && detail_msg->devType != NET_NFC_NFCIP1_INITIATOR) - { - net_nfc_response_tag_discovered_t resp_msg = { 0, }; - int request_type = NET_NFC_MESSAGE_TAG_DISCOVERED; - data_s *recv_data = NULL; - - if (!net_nfc_controller_connect(detail_msg->handle, &result)) - { - DEBUG_ERR_MSG("connect failed & Retry Polling!!"); - - if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, NET_NFC_ALL_ENABLE, &result) == false) - { - net_nfc_controller_exception_handler(); - } - return false; - } - -#ifdef BROADCAST_MESSAGE - net_nfc_server_set_server_state(NET_NFC_TAG_CONNECTED); -#endif - DEBUG_SERVER_MSG("tag is connected"); - - uint8_t ndef_card_state = 0; - int max_data_size = 0; - int real_data_size = 0; - - if (net_nfc_controller_check_ndef(detail_msg->handle, &ndef_card_state, &max_data_size, &real_data_size, &result) == true) - { - resp_msg.ndefCardState = ndef_card_state; - resp_msg.maxDataSize = max_data_size; - resp_msg.actualDataSize = real_data_size; - resp_msg.is_ndef_supported = 1; - } - - resp_msg.devType = detail_msg->devType; - resp_msg.handle = detail_msg->handle; - resp_msg.number_of_keys = detail_msg->number_of_keys; - resp_msg.raw_data.length = 0; - - net_nfc_util_duplicate_data(&resp_msg.target_info_values, &detail_msg->target_info_values); - - if (resp_msg.is_ndef_supported) - { - DEBUG_SERVER_MSG("support NDEF"); - - if ((result = _read_ndef_message(detail_msg->handle, detail_msg->devType, &recv_data)) == NET_NFC_OK && - recv_data != NULL) - { - DEBUG_SERVER_MSG("net_nfc_controller_read_ndef success"); -#ifdef BROADCAST_MESSAGE - net_nfc_service_msg_processing(recv_data); -#endif - resp_msg.raw_data.length = recv_data->length; - success = net_nfc_broadcast_response_msg(request_type, (void *)&resp_msg, sizeof(net_nfc_response_tag_discovered_t), - (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length, - (void *)(recv_data->buffer), recv_data->length, NULL); - - net_nfc_util_free_data(recv_data); - _net_nfc_util_free_mem(recv_data); - } - else - { - DEBUG_ERR_MSG("net_nfc_controller_read_ndef failed"); - - success = net_nfc_broadcast_response_msg(request_type, (void *)&resp_msg, sizeof(net_nfc_response_tag_discovered_t), - (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length, NULL); - } - } - else - { - DEBUG_SERVER_MSG("not support NDEF"); -#ifdef BROADCAST_MESSAGE - /* launch empty tag */ - uint8_t empty[] = { 0xd0, 0x00, 0x00 }; /* raw-data of empty ndef-message */ - data_s rawdata = { empty, sizeof(empty) }; - - net_nfc_service_msg_processing(&rawdata); -#endif - success = net_nfc_broadcast_response_msg(request_type, (void *)&resp_msg, sizeof(net_nfc_response_tag_discovered_t), - (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length, NULL); - } - - net_nfc_util_free_data(&resp_msg.target_info_values); - - DEBUG_SERVER_MSG("turn on watch dog"); - - net_nfc_request_watch_dog_t* watch_dog_msg = NULL; - - _net_nfc_util_alloc_mem(watch_dog_msg, sizeof(net_nfc_request_watch_dog_t)); - if (watch_dog_msg != NULL) - { - watch_dog_msg->length = sizeof(net_nfc_request_watch_dog_t); - watch_dog_msg->request_type = NET_NFC_MESSAGE_SERVICE_WATCH_DOG; - watch_dog_msg->devType = detail_msg->devType; - watch_dog_msg->handle = detail_msg->handle; - - net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)watch_dog_msg); - } - } - else /* LLCP */ - { - net_nfc_error_e error_status = NET_NFC_OK; - - net_nfc_service_llcp_process(detail_msg->handle, detail_msg->devType, &error_status); - } - - /* If target detected, sound should be played. */ - net_nfc_manager_util_play_sound(NET_NFC_TASK_START); - - return success; -} - -bool net_nfc_service_termination(net_nfc_request_msg_t* msg) -{ - net_nfc_error_e result; - - if (net_nfc_controller_is_ready(&result) == true) - { - } - else - { - DEBUG_SERVER_MSG("Not initialized"); - net_nfc_controller_init(&result); - } - - if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, NET_NFC_ALL_DISABLE, &result) != true) - { - DEBUG_SERVER_MSG("failed to discover off %d", result); - } - - if (net_nfc_controller_set_secure_element_mode(NET_NFC_SE_CMD_UICC_ON, SECURE_ELEMENT_VIRTUAL_MODE, &result) != true) - { - DEBUG_SERVER_MSG("failed to set se mode to default mode: %d", result); - } - - return true; -} - -void net_nfc_service_msg_processing(data_s* data) -{ - if (data) - net_nfc_app_util_process_ndef(data); -} - -void net_nfc_service_is_tag_connected(net_nfc_request_msg_t *msg) -{ - net_nfc_request_is_tag_connected_t *detail = (net_nfc_request_is_tag_connected_t *)msg; - net_nfc_current_target_info_s *target_info; - - target_info = net_nfc_server_get_tag_info(); - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_is_tag_connected_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_is_tag_connected_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - - if (target_info != NULL) - { - resp.result = NET_NFC_OK; - resp.devType = target_info->devType; - } - else - { - resp.result = NET_NFC_NOT_CONNECTED; - resp.devType = NET_NFC_UNKNOWN_TARGET; - } - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_is_tag_connected_t), NULL); - } -} - -void net_nfc_service_get_current_tag_info(net_nfc_request_msg_t *msg) -{ - net_nfc_response_get_current_tag_info_t resp = { 0, }; - net_nfc_request_get_current_tag_info_t *detail = (net_nfc_request_get_current_tag_info_t *)msg; - net_nfc_current_target_info_s *target_info = NULL; - net_nfc_error_e result = NET_NFC_OK; - - resp.length = sizeof(net_nfc_response_get_current_tag_info_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - - target_info = net_nfc_server_get_tag_info(); - if (target_info != NULL) - { - bool success = true; - data_s *recv_data = NULL; - - if (target_info->devType != NET_NFC_NFCIP1_TARGET && target_info->devType != NET_NFC_NFCIP1_INITIATOR) - { -#ifdef BROADCAST_MESSAGE - net_nfc_server_set_server_state(NET_NFC_TAG_CONNECTED); -#endif - DEBUG_SERVER_MSG("tag is connected"); - - uint8_t ndef_card_state = 0; - int max_data_size = 0; - int real_data_size = 0; - - if (net_nfc_controller_check_ndef(target_info->handle, - &ndef_card_state, &max_data_size, &real_data_size, &result) == true) - { - resp.ndefCardState = ndef_card_state; - resp.maxDataSize = max_data_size; - resp.actualDataSize = real_data_size; - resp.is_ndef_supported = 1; - } - - resp.devType = target_info->devType; - resp.handle = target_info->handle; - resp.number_of_keys = target_info->number_of_keys; - - net_nfc_util_duplicate_data(&resp.target_info_values, &target_info->target_info_values); - - if (resp.is_ndef_supported) - { - if (net_nfc_controller_read_ndef(target_info->handle, &recv_data, &(resp.result)) == true) - { - DEBUG_SERVER_MSG("net_nfc_controller_read_ndef is success"); - - resp.raw_data.length = recv_data->length; - - success = net_nfc_send_response_msg(msg->client_fd, msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), - (void *)(resp.target_info_values.buffer), resp.target_info_values.length, - (void *)(recv_data->buffer), recv_data->length, NULL); - } - else - { - DEBUG_SERVER_MSG("net_nfc_controller_read_ndef is fail"); - - resp.raw_data.length = 0; - - success = net_nfc_send_response_msg(msg->client_fd, msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), - (void *)(resp.target_info_values.buffer), resp.target_info_values.length, NULL); - } - } - else - { - resp.raw_data.length = 0; - - success = net_nfc_send_response_msg(msg->client_fd, msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), - (void *)(resp.target_info_values.buffer), resp.target_info_values.length, NULL); - } - - net_nfc_util_free_data(&resp.target_info_values); - } - else - { - /* LLCP */ - resp.result = NET_NFC_NOT_CONNECTED; - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), NULL); - } - } - else - { - resp.result = NET_NFC_NOT_CONNECTED; - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), NULL); - } -} - -void net_nfc_service_get_current_target_handle(net_nfc_request_msg_t *msg) -{ - net_nfc_request_get_current_target_handle_t *detail = (net_nfc_request_get_current_target_handle_t *)msg; - net_nfc_current_target_info_s *target_info = NULL; - - target_info = net_nfc_server_get_tag_info(); - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_get_current_target_handle_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_get_current_target_handle_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - - if (target_info != NULL) - { - resp.handle = target_info->handle; - resp.devType = target_info->devType; - resp.result = NET_NFC_OK; - } - else - { - resp.result = NET_NFC_NOT_CONNECTED; - } - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_get_current_target_handle_t), NULL); - } -} - -void net_nfc_service_deinit(net_nfc_request_msg_t *msg) -{ - net_nfc_error_e result; - - result = net_nfc_service_se_change_se(SECURE_ELEMENT_TYPE_INVALID); - - net_nfc_server_free_current_tag_info(); - - if (net_nfc_controller_deinit() == TRUE) - { - DEBUG_SERVER_MSG("net_nfc_controller_deinit success [%d]", result); - - /*vconf off*/ - if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0) - { - DEBUG_ERR_MSG("vconf_set_bool failed"); - } - - net_nfc_response_test_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_test_t); - resp.flags = msg->flags; - resp.result = NET_NFC_OK; - resp.trans_param = (void *)msg->user_param; - - net_nfc_broadcast_response_msg(msg->request_type, (void *)&resp, - sizeof(net_nfc_response_test_t), NULL); - } - else - { - DEBUG_SERVER_MSG("net_nfc_controller_deinit failed"); - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_test_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_test_t); - resp.flags = msg->flags; - resp.result = NET_NFC_UNKNOWN_ERROR; - resp.trans_param = (void *)msg->user_param; - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_test_t), NULL); - } - } -} - -void net_nfc_service_init(net_nfc_request_msg_t *msg) -{ - net_nfc_error_e result; - - if (net_nfc_controller_init(&result) == true) - { - net_nfc_llcp_config_info_s config = { 128, 1, 100, 0 }; - - if (net_nfc_controller_register_listener(net_nfc_service_target_detected_cb, - net_nfc_service_se_transaction_cb, net_nfc_service_llcp_event_cb, &result) == true) - { - DEBUG_SERVER_MSG("net_nfc_controller_register_listener Success!!"); - } - else - { - DEBUG_ERR_MSG("net_nfc_controller_register_listener failed [%d]", result); - } - - if (net_nfc_controller_llcp_config(&config, &result) == true) - { - /*We need to check the stack that supports the llcp or not.*/ - DEBUG_SERVER_MSG("llcp is enabled"); - } - else - { - DEBUG_ERR_MSG("net_nfc_controller_llcp_config failed [%d]", result); - } - - result = net_nfc_service_se_change_se(SECURE_ELEMENT_TYPE_UICC); - - if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, - NET_NFC_ALL_ENABLE, &result) == true) - { - DEBUG_SERVER_MSG("now, nfc is ready"); - } - else - { - DEBUG_ERR_MSG("net_nfc_controller_confiure_discovery failed [%d]", result); - } - - /*Send the Init Success Response Msg*/ - { - net_nfc_response_test_t resp = { 0, }; - - DEBUG_SERVER_MSG("net_nfc_controller_init success [%d]", result); - - resp.length = sizeof(net_nfc_response_test_t); - resp.flags = msg->flags; - resp.result = NET_NFC_OK; - resp.trans_param = (void *)msg->user_param; - - /*vconf on*/ - if (vconf_set_bool(VCONFKEY_NFC_STATE, TRUE) != 0) - { - DEBUG_ERR_MSG("vconf_set_bool failed"); - } - - net_nfc_broadcast_response_msg(msg->request_type, - (void *)&resp, sizeof(net_nfc_response_test_t), NULL); - } - } - else - { - DEBUG_ERR_MSG("net_nfc_controller_init failed [%d]", result); - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_test_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_test_t); - resp.flags = msg->flags; - resp.result = result; - resp.trans_param = (void *)msg->user_param; - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_test_t), NULL); - } - } -} - -void net_nfc_service_restart_polling(net_nfc_request_msg_t *msg) -{ - net_nfc_request_msg_t *discovery_req = (net_nfc_request_msg_t *)msg; - net_nfc_error_e result = NET_NFC_OK; - int pm_state = 0; - int set_config = 0; - - pm_state = discovery_req->user_param; - - DEBUG_SERVER_MSG("NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP PM State = [%d]", pm_state); - - if (pm_state == 1) - { - set_config = NET_NFC_ALL_ENABLE; - } - else if (pm_state == 3) - { - set_config = NET_NFC_ALL_DISABLE; - } - else - { - DEBUG_SERVER_MSG("Do not anything!!"); - } - - if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, set_config, &result) == true) - { - DEBUG_SERVER_MSG("now, nfc polling loop is running again"); - } -} - -void net_nfc_service_get_server_state(net_nfc_request_msg_t *msg) -{ - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_get_server_state_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_get_server_state_t); - resp.flags = msg->flags; - resp.state = net_nfc_server_get_server_state(); - resp.result = NET_NFC_OK; - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_get_server_state_t), NULL); - } -} diff --git a/src/manager/net_nfc_service_se.c b/src/manager/net_nfc_service_se.c deleted file mode 100755 index 2becb17..0000000 --- a/src/manager/net_nfc_service_se.c +++ /dev/null @@ -1,951 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include "vconf.h" -#include "tapi_common.h" -#include "ITapiSim.h" - -#include "net_nfc_controller_private.h" -#include "net_nfc_util_private.h" -#include "net_nfc_typedef.h" -#include "net_nfc_debug_private.h" -#include "net_nfc_service_private.h" -#include "net_nfc_app_util_private.h" -#include "net_nfc_server_ipc_private.h" -#include "net_nfc_server_dispatcher_private.h" -#include "net_nfc_service_se_private.h" -#include "net_nfc_server_context_private.h" - -/* define */ - -/* static variable */ -static uint8_t g_se_prev_type = SECURE_ELEMENT_TYPE_INVALID; -static uint8_t g_se_prev_mode = SECURE_ELEMENT_OFF_MODE; - -/* For ESE*/ -static net_nfc_se_setting_t g_se_setting; - -/* For UICC */ -static struct tapi_handle *uicc_handle = NULL; -static bool net_nfc_service_check_sim_state(void); -static void _uicc_transmit_apdu_cb(TapiHandle *handle, int result, void *data, void *user_data); -static void _uicc_get_atr_cb(TapiHandle *handle, int result, void *data, void *user_data); -static void _uicc_status_noti_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data); - -net_nfc_se_setting_t *net_nfc_service_se_get_se_setting() -{ - return &g_se_setting; -} - -net_nfc_target_handle_s *net_nfc_service_se_get_current_ese_handle() -{ - return g_se_setting.current_ese_handle; -} - -void net_nfc_service_se_set_current_ese_handle(net_nfc_target_handle_s *handle) -{ - g_se_setting.current_ese_handle = handle; -} - -uint8_t net_nfc_service_se_get_se_type() -{ - return g_se_setting.type; -} - -void net_nfc_service_se_set_se_type(uint8_t type) -{ - g_se_setting.return_type = g_se_setting.type; - g_se_setting.type = type; -} - -uint8_t net_nfc_service_se_get_return_se_mode() -{ - return g_se_setting.return_type; -} - -uint8_t net_nfc_service_se_get_se_mode() -{ - return g_se_setting.mode; -} - -void net_nfc_service_se_set_se_mode(uint8_t mode) -{ - g_se_setting.mode = mode; -} - -net_nfc_error_e net_nfc_service_se_disable_card_emulation() -{ - net_nfc_error_e result; - - net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_INVALID); - net_nfc_service_se_set_se_mode(SECURE_ELEMENT_OFF_MODE); - - /*turn off ESE*/ - net_nfc_controller_set_secure_element_mode( - SECURE_ELEMENT_TYPE_ESE, - SECURE_ELEMENT_OFF_MODE, - &result); - - /*turn off UICC*/ - net_nfc_controller_set_secure_element_mode( - SECURE_ELEMENT_TYPE_UICC, - SECURE_ELEMENT_OFF_MODE, - &result); - - return NET_NFC_OK; -} - -net_nfc_error_e net_nfc_service_se_change_se(uint8_t type) -{ - net_nfc_error_e result = NET_NFC_OK; - - switch (type) - { - case SECURE_ELEMENT_TYPE_UICC : - /*turn off ESE*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result); - - /*turn on UICC*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE, &result); - if (result == NET_NFC_OK) - { - DEBUG_SERVER_MSG("changed to SECURE_ELEMENT_TYPE_UICC"); - - net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_UICC); - net_nfc_service_se_set_se_mode(SECURE_ELEMENT_VIRTUAL_MODE); - - if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, VCONFKEY_NFC_SE_TYPE_UICC) != 0) - { - DEBUG_ERR_MSG("vconf_set_int failed"); - } - } - else - { - DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]", result); - } - break; - - case SECURE_ELEMENT_TYPE_ESE : - /*turn off UICC*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result); - - /*turn on ESE*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE, &result); - if (result == NET_NFC_OK) - { - DEBUG_SERVER_MSG("changed to SECURE_ELEMENT_TYPE_ESE"); - - net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_ESE); - net_nfc_service_se_set_se_mode(SECURE_ELEMENT_VIRTUAL_MODE); - - if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, VCONFKEY_NFC_SE_TYPE_ESE) != 0) - { - DEBUG_ERR_MSG("vconf_set_int failed"); - } - } - else - { - DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]", result); - } - break; - - default : - { - net_nfc_error_e result_ese, result_uicc; - - net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_INVALID); - net_nfc_service_se_set_se_mode(SECURE_ELEMENT_OFF_MODE); - - /*turn off ESE*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result_ese); - - /*turn off UICC*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result_uicc); - if (result_ese != NET_NFC_INVALID_HANDLE && result_uicc != NET_NFC_INVALID_HANDLE) - { - DEBUG_SERVER_MSG("SE off all"); - if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, VCONFKEY_NFC_SE_TYPE_NONE) != 0) - { - DEBUG_ERR_MSG("vconf_set_int failed"); - } - result = NET_NFC_OK; - } - else - { - DEBUG_ERR_MSG("ALL OFF failed, ese [%d], uicc [%d]", result_ese, result_uicc); - result = NET_NFC_INVALID_HANDLE; - } - } - break; - } - - return result; -} - -void net_nfc_service_se_detected(net_nfc_request_msg_t *msg) -{ - net_nfc_request_target_detected_t *detail_msg = (net_nfc_request_target_detected_t *)(msg); - net_nfc_target_handle_s *handle = NULL; - net_nfc_error_e state = NET_NFC_OK; - net_nfc_response_open_internal_se_t resp = { 0 }; - - if (detail_msg == NULL) - { - return; - } - - handle = detail_msg->handle; - g_se_setting.current_ese_handle = handle; - - DEBUG_SERVER_MSG("trying to connect to ESE = [0x%p]", handle); - - if (!net_nfc_controller_connect(handle, &state)) - { - DEBUG_SERVER_MSG("connect failed = [%d]", state); - resp.result = state; - } - -#ifdef BROADCAST_MESSAGE - net_nfc_server_set_server_state(NET_NFC_SE_CONNECTED); -#endif - - resp.handle = handle; - resp.trans_param = g_se_setting.open_request_trans_param; - resp.se_type = SECURE_ELEMENT_TYPE_ESE; - - DEBUG_SERVER_MSG("trans param = [%p]", resp.trans_param); - - net_nfc_send_response_msg(detail_msg->client_fd, NET_NFC_MESSAGE_OPEN_INTERNAL_SE, - &resp, sizeof(net_nfc_response_open_internal_se_t), NULL); - - g_se_setting.open_request_trans_param = NULL; -} - -net_nfc_error_e net_nfc_service_se_close_ese() -{ - net_nfc_error_e result = NET_NFC_OK; - - if (g_se_setting.current_ese_handle != NULL) - { - if (net_nfc_controller_secure_element_close(g_se_setting.current_ese_handle, &result) == false) - { - net_nfc_controller_exception_handler(); - } - net_nfc_service_se_set_current_ese_handle(NULL); - } - - return result; -} - -bool net_nfc_service_tapi_init(void) -{ - char **cpList = NULL; - - DEBUG_SERVER_MSG("tapi init"); - - cpList = tel_get_cp_name_list(); - - uicc_handle = tel_init(cpList[0]); - if (uicc_handle == NULL) - { - int error; - - error = tel_register_noti_event(uicc_handle, TAPI_NOTI_SIM_STATUS, _uicc_status_noti_cb, NULL); - } - else - { - DEBUG_SERVER_MSG("tel_init() failed"); - return false; - } - - DEBUG_SERVER_MSG("tel_init() is success"); - - return net_nfc_service_check_sim_state(); -} - -void net_nfc_service_tapi_deinit(void) -{ - DEBUG_SERVER_MSG("deinit tapi"); - - tel_deregister_noti_event(uicc_handle, TAPI_NOTI_SIM_STATUS); - - tel_deinit(uicc_handle); -} - -bool net_nfc_service_transfer_apdu(int client_fd, data_s *apdu, void *trans_param) -{ - net_nfc_request_msg_t *param = NULL; - TelSimApdu_t apdu_data = { 0 }; - int result; - - DEBUG_SERVER_MSG("tranfer apdu"); - - if (apdu == NULL) - return false; - - apdu_data.apdu = apdu->buffer; - apdu_data.apdu_len = apdu->length; - - /* make param */ - _net_nfc_util_alloc_mem(param, sizeof(net_nfc_request_msg_t)); - if (param != NULL) - { - param->client_fd = client_fd; - param->user_param = (uint32_t)trans_param; - - result = tel_req_sim_apdu(uicc_handle, &apdu_data, _uicc_transmit_apdu_cb, param); - if (result == 0) - { - DEBUG_SERVER_MSG("sim apdu request is success"); - } - else - { - DEBUG_ERR_MSG("request sim apdu is failed with error = [%d]", result); - return false; - } - } - else - { - DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed"); - return false; - } - - return true; -} - -bool net_nfc_service_request_atr(int client_fd, void *trans_param) -{ - int result; - net_nfc_request_msg_t *param = NULL; - - /* make param */ - _net_nfc_util_alloc_mem(param, sizeof(net_nfc_request_msg_t)); - if (param != NULL) - { - param->client_fd = client_fd; - param->user_param = (uint32_t)trans_param; - - result = tel_req_sim_atr(uicc_handle, _uicc_get_atr_cb, param); - if (result == 0) - { - DEBUG_SERVER_MSG("request is success"); - } - else - { - DEBUG_SERVER_MSG("failed to request ATR = [%d]", result); - return false; - } - } - else - { - DEBUG_ERR_MSG("_net_nfc_manager_util_alloc_mem failed"); - return false; - } - - return true; -} - -static bool net_nfc_service_check_sim_state(void) -{ - TelSimCardStatus_t state = (TelSimCardStatus_t)0; - int b_card_changed = 0; - int error; - - DEBUG_SERVER_MSG("check sim state"); - - error = tel_get_sim_init_info(uicc_handle, &state, &b_card_changed); - - DEBUG_SERVER_MSG("current sim init state = [%d]", state); - - if (error != 0) - { - DEBUG_SERVER_MSG("error = [%d]", error); - return false; - } - else if (state == TAPI_SIM_STATUS_SIM_INIT_COMPLETED || state == TAPI_SIM_STATUS_SIM_INITIALIZING) - { - DEBUG_SERVER_MSG("sim is initialized"); - } - else - { - DEBUG_SERVER_MSG("sim is not initialized"); - return false; - } - - return true; -} - -void _uicc_transmit_apdu_cb(TapiHandle *handle, int result, void *data, void *user_data) -{ - TelSimApduResp_t *apdu = (TelSimApduResp_t *)data; - net_nfc_response_send_apdu_t resp = { 0 }; - net_nfc_request_msg_t *param = (net_nfc_request_msg_t *)user_data; - - DEBUG_SERVER_MSG("_uicc_transmit_apdu_cb"); - - if (result == 0) - { - resp.result = NET_NFC_OK; - } - else - { - resp.result = NET_NFC_OPERATION_FAIL; - } - - resp.trans_param = (void *)param->user_param; - - if (apdu != NULL && apdu->apdu_resp_len > 0) - { - resp.data.length = apdu->apdu_resp_len; - - DEBUG_MSG("send response send apdu msg"); - net_nfc_send_response_msg(param->client_fd, NET_NFC_MESSAGE_SEND_APDU_SE, - (void *)&resp, sizeof(net_nfc_response_send_apdu_t), apdu->apdu_resp, apdu->apdu_resp_len, NULL); - } - else - { - DEBUG_MSG("send response send apdu msg"); - net_nfc_send_response_msg(param->client_fd, NET_NFC_MESSAGE_SEND_APDU_SE, - (void *)&resp, sizeof(net_nfc_response_send_apdu_t), NULL); - } - - _net_nfc_util_free_mem(param); -} - -void _uicc_get_atr_cb(TapiHandle *handle, int result, void *data, void *user_data) -{ - net_nfc_request_msg_t *param = (net_nfc_request_msg_t *)user_data; - - /* TODO : response message */ - - DEBUG_SERVER_MSG("_uicc_get_atr_cb"); - - _net_nfc_util_free_mem(param); -} - -void _uicc_status_noti_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data) -{ - TelSimCardStatus_t *status = (TelSimCardStatus_t *)data; - - /* TODO : */ - DEBUG_SERVER_MSG("_uicc_status_noti_cb"); - - switch (*status) - { - case TAPI_SIM_STATUS_SIM_INIT_COMPLETED : - DEBUG_SERVER_MSG("TAPI_SIM_STATUS_SIM_INIT_COMPLETED"); - break; - - case TAPI_SIM_STATUS_CARD_REMOVED : - DEBUG_SERVER_MSG("TAPI_SIM_STATUS_CARD_REMOVED"); - break; - - default : - DEBUG_SERVER_MSG("unknown status [%d]", *status); - break; - } -} - -bool net_nfc_service_se_transaction_receive(net_nfc_request_msg_t* msg) -{ - bool res = true; - bool fg_dispatch; - pid_t focus_app_pid; - net_nfc_secure_element_type_e se_type; - net_nfc_request_se_event_t *se_event = (net_nfc_request_se_event_t *)msg; - - if (se_event->request_type == NET_NFC_MESSAGE_SE_START_TRANSACTION) - { - DEBUG_SERVER_MSG("launch se app"); - - se_type = net_nfc_service_se_get_se_type(); - fg_dispatch = net_nfc_app_util_check_launch_state(); - focus_app_pid = net_nfc_app_util_get_focus_app_pid(); - - res = net_nfc_app_util_launch_se_transaction_app(se_type, se_event->aid.buffer, - se_event->aid.length, se_event->param.buffer, se_event->param.length); - - DEBUG_SERVER_MSG("launch se app end"); - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_se_event_t resp = { 0 }; - - resp.length = sizeof(net_nfc_response_se_event_t); - resp.flags = se_event->flags; - resp.result = res; - resp.aid = se_event->aid; - resp.param = se_event->param; - resp.fg_dispatch = fg_dispatch; - resp.focus_app_pid = focus_app_pid; - resp.se_type = se_type; - - net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_SE_START_TRANSACTION, - (void *)&resp, sizeof(net_nfc_response_se_event_t), NULL); - } - } - - return res; -} - -void net_nfc_service_se_send_apdu(net_nfc_request_msg_t *msg) -{ - net_nfc_request_send_apdu_t *detail = (net_nfc_request_send_apdu_t *)msg; - - if (detail->handle == (net_nfc_target_handle_s *)UICC_TARGET_HANDLE) - { - data_s apdu_data = { NULL, 0 }; - - if (net_nfc_util_duplicate_data(&apdu_data, &detail->data) == false) - return; - - net_nfc_service_transfer_apdu(msg->client_fd, &apdu_data, detail->trans_param); - - net_nfc_util_free_data(&apdu_data); - } - else if (detail->handle == net_nfc_service_se_get_current_ese_handle()) - { - bool success; - data_s command; - data_s *response = NULL; - net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; - - if (net_nfc_util_duplicate_data(&command, &detail->data) == false) - { - DEBUG_ERR_MSG("alloc failed"); - return; - } - - if ((success = net_nfc_controller_secure_element_send_apdu(detail->handle, &command, &response, &result)) == true) - { - if (response != NULL) - { - DEBUG_SERVER_MSG("transceive data received, len [%d]", response->length); - } - } - else - { - DEBUG_ERR_MSG("transceive failed = [%d]", result); - } - net_nfc_util_free_data(&command); - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_send_apdu_t resp = { 0, }; - - DEBUG_SERVER_MSG("send response send_apdu"); - - resp.length = sizeof(net_nfc_response_send_apdu_t); - resp.flags = detail->flags; - resp.user_param = detail->user_param; - resp.trans_param = detail->trans_param; - resp.result = result; - - if (response != NULL) - { - resp.data.length = response->length; - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_send_apdu_t), - response->buffer, response->length, NULL); - } - else - { - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_send_apdu_t), NULL); - } - } - } - else - { - DEBUG_SERVER_MSG("invalid se handle"); - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_send_apdu_t resp = { 0 }; - - resp.length = sizeof(net_nfc_response_send_apdu_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - resp.result = NET_NFC_INVALID_PARAM; - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_send_apdu_t), NULL); - } - } -} - -void net_nfc_service_se_get_atr(net_nfc_request_msg_t *msg) -{ - net_nfc_request_get_atr_t *detail = (net_nfc_request_get_atr_t *)msg; - - if (detail->handle == (net_nfc_target_handle_s *)UICC_TARGET_HANDLE) - { - net_nfc_service_request_atr(msg->client_fd, (void *)detail->user_param); - } - else if (detail->handle == net_nfc_service_se_get_current_ese_handle()) - { - net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_get_atr_t resp = { 0, }; - - resp.length = sizeof(net_nfc_response_get_atr_t); - resp.flags = detail->flags; - resp.user_param = detail->user_param; - resp.result = result; - - DEBUG_SERVER_MSG("send response send apdu msg"); - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_get_atr_t), NULL); - } - } - else - { - DEBUG_SERVER_MSG("invalid se handle"); - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_get_atr_t resp = { 0 }; - - resp.length = sizeof(net_nfc_response_get_atr_t); - resp.flags = detail->flags; - resp.user_param = detail->user_param; - resp.result = NET_NFC_INVALID_PARAM; - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_get_atr_t), NULL); - } - } -} - -void net_nfc_service_se_close_se(net_nfc_request_msg_t *msg) -{ - net_nfc_request_close_internal_se_t *detail = (net_nfc_request_close_internal_se_t *)msg; - net_nfc_error_e result = NET_NFC_OK; - - if (detail->handle == (net_nfc_target_handle_s *)UICC_TARGET_HANDLE) - { - /*deinit TAPI*/ - DEBUG_SERVER_MSG("UICC is current secure element"); - net_nfc_service_tapi_deinit(); - - } - else if (detail->handle == net_nfc_service_se_get_current_ese_handle()) - { - result = net_nfc_service_se_close_ese(); -#ifdef BROADCAST_MESSAGE - net_nfc_server_unset_server_state(NET_NFC_SE_CONNECTED); -#endif - } - else - { - DEBUG_ERR_MSG("invalid se handle received handle = [0x%p] and current handle = [0x%p]", - detail->handle, net_nfc_service_se_get_current_ese_handle()); - } - - if ((g_se_prev_type != net_nfc_service_se_get_se_type()) || (g_se_prev_mode != net_nfc_service_se_get_se_mode())) - { - /*return back se mode*/ - net_nfc_controller_set_secure_element_mode(g_se_prev_type, g_se_prev_mode, &result); - - net_nfc_service_se_set_se_type(g_se_prev_type); - net_nfc_service_se_set_se_mode(g_se_prev_mode); - } - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_close_internal_se_t resp = { 0 }; - - resp.length = sizeof(net_nfc_response_close_internal_se_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - resp.result = result; - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_close_internal_se_t), NULL); - } - -} - -void net_nfc_service_se_open_se(net_nfc_request_msg_t *msg) -{ - net_nfc_request_open_internal_se_t *detail = (net_nfc_request_open_internal_se_t *)msg; - net_nfc_target_handle_s *handle = NULL; - net_nfc_error_e result = NET_NFC_OK; - - g_se_prev_type = net_nfc_service_se_get_se_type(); - g_se_prev_mode = net_nfc_service_se_get_se_mode(); - - if (detail->se_type == SECURE_ELEMENT_TYPE_UICC) - { - /*off ESE*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result); - - /*Off UICC. UICC SHOULD not be detected by external reader when being communicated in internal process*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result); - - net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_UICC); - net_nfc_service_se_set_se_mode(SECURE_ELEMENT_OFF_MODE); - - /*Init tapi api and return back response*/ - if (net_nfc_service_tapi_init() != true) - { - net_nfc_service_tapi_deinit(); - result = NET_NFC_INVALID_STATE; - handle = NULL; - } - else - { - result = NET_NFC_OK; - handle = (net_nfc_target_handle_s *)UICC_TARGET_HANDLE; - } - } - else if (detail->se_type == SECURE_ELEMENT_TYPE_ESE) - { - /*off UICC*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result); - - if (net_nfc_controller_secure_element_open(SECURE_ELEMENT_TYPE_ESE, &handle, &result) == true) - { - net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_ESE); - net_nfc_service_se_set_se_mode(SECURE_ELEMENT_WIRED_MODE); - - net_nfc_service_se_get_se_setting()->open_request_trans_param = detail->trans_param; - net_nfc_service_se_set_current_ese_handle(handle); - - DEBUG_ERR_MSG("handle [%p]", handle); - } - else - { - DEBUG_ERR_MSG("net_nfc_controller_secure_element_open failed [%d]", result); - } - } - else - { - result = NET_NFC_INVALID_STATE; - handle = NULL; - } - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_open_internal_se_t resp = { 0 }; - - resp.length = sizeof(net_nfc_response_open_internal_se_t); - resp.flags = detail->flags; - resp.user_param = detail->user_param; - resp.trans_param = detail->trans_param; - resp.result = result; - resp.se_type = detail->se_type; - resp.handle = handle; - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_open_internal_se_t), NULL); - } -} - -void net_nfc_service_se_change_card_emulation_mode(net_nfc_request_msg_t *msg) -{ - bool isModeChange = false; - uint8_t current_mode, return_mode; - net_nfc_error_e result = NET_NFC_OK; - net_nfc_request_se_change_card_emulation_t *detail - = (net_nfc_request_se_change_card_emulation_t *)msg; - - current_mode = net_nfc_service_se_get_se_mode(); - - if(detail->se_mode == SECURE_ELEMENT_ACTIVE_STATE - && current_mode == SECURE_ELEMENT_TYPE_INVALID) - { - return_mode = net_nfc_service_se_get_return_se_mode(); - result = net_nfc_service_se_change_se(return_mode); - isModeChange = true; - } - else if(detail->se_mode == SECURE_ELEMENT_INACTIVE_STATE - && current_mode != SECURE_ELEMENT_TYPE_INVALID) - { - result = net_nfc_service_se_disable_card_emulation(); - isModeChange = true; - } - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_se_change_card_emulation_t resp = { 0 }; - - resp.length = sizeof(net_nfc_response_se_change_card_emulation_t); - resp.flags = detail->flags; - resp.user_param = detail->user_param; - resp.trans_param = detail->trans_param; - resp.result = result; - resp.se_mode = detail->se_mode; - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_se_change_card_emulation_t), NULL); - } - - if(isModeChange) - { - net_nfc_response_notify_t noti_se = { 0, }; - - net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED, - (void *)¬i_se, sizeof(net_nfc_response_notify_t), NULL); - } -} - -void net_nfc_service_se_set_se(net_nfc_request_msg_t *msg) -{ -#if 1 - net_nfc_request_set_se_t *detail = (net_nfc_request_set_se_t *)msg; - net_nfc_error_e result = NET_NFC_OK; - bool isTypeChange = false; - - if (detail->se_type != net_nfc_service_se_get_se_type()) - { - result = net_nfc_service_se_change_se(detail->se_type); - isTypeChange = true; - } - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_set_se_t resp = { 0 }; - - resp.length = sizeof(net_nfc_response_set_se_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - resp.se_type = detail->se_type; - resp.result = result; - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_set_se_t), NULL); - } - - if (isTypeChange) - { - net_nfc_response_notify_t noti_se = { 0, }; - - net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_SE_TYPE_CHANGED, - (void *)¬i_se, sizeof(net_nfc_response_notify_t), NULL); - } - -#else - net_nfc_request_set_se_t *detail = (net_nfc_request_set_se_t *)msg; - net_nfc_error_e result = NET_NFC_OK; - int mode; - - mode = (int)detail->se_type; - - if (mode == NET_NFC_SE_CMD_UICC_ON) - { - /*turn on UICC*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, - SECURE_ELEMENT_VIRTUAL_MODE, &result); - - /*turn off ESE*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, - SECURE_ELEMENT_OFF_MODE, &result); - } - else if (mode == NET_NFC_SE_CMD_ESE_ON) - { - /*turn off UICC*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, - SECURE_ELEMENT_OFF_MODE, &result); - - /*turn on ESE*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, - SECURE_ELEMENT_VIRTUAL_MODE, &result); - } - else if (mode == NET_NFC_SE_CMD_ALL_OFF) - { - /*turn off both*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, - SECURE_ELEMENT_OFF_MODE, &result); - - /*turn on ESE*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, - SECURE_ELEMENT_OFF_MODE, &result); - } - else - { - /*turn off both*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, - SECURE_ELEMENT_VIRTUAL_MODE, &result); - - /*turn on ESE*/ - net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, - SECURE_ELEMENT_VIRTUAL_MODE, &result); - } -#endif -} - -void net_nfc_service_se_get_se(net_nfc_request_msg_t *msg) -{ - net_nfc_request_get_se_t *detail = (net_nfc_request_get_se_t *)msg; - - if (net_nfc_server_check_client_is_running(msg->client_fd)) - { - net_nfc_response_get_se_t resp = { 0 }; - - resp.length = sizeof(net_nfc_request_get_se_t); - resp.flags = detail->flags; - resp.trans_param = detail->trans_param; - resp.result = NET_NFC_OK; - resp.se_type = net_nfc_service_se_get_se_type(); - - net_nfc_send_response_msg(msg->client_fd, msg->request_type, - (void *)&resp, sizeof(net_nfc_response_get_se_t), NULL); - } -} - -void net_nfc_service_se_cleanup() -{ - DEBUG_SERVER_MSG("client is terminated abnormally"); - - if (g_se_prev_type == SECURE_ELEMENT_TYPE_ESE) - { - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *ese_handle = net_nfc_service_se_get_current_ese_handle(); - - if (ese_handle != NULL) - { - DEBUG_SERVER_MSG("ese_handle was not freed and disconnected"); - - net_nfc_service_se_close_ese(); -#ifdef BROADCAST_MESSAGE - net_nfc_server_set_server_state(NET_NFC_SERVER_IDLE); -#endif - } - - if ((g_se_prev_type != net_nfc_service_se_get_se_type()) || (g_se_prev_mode != net_nfc_service_se_get_se_mode())) - { - net_nfc_controller_set_secure_element_mode(g_se_prev_type, g_se_prev_mode, &result); - - net_nfc_service_se_set_se_type(g_se_prev_type); - net_nfc_service_se_set_se_mode(g_se_prev_mode); - } - } - else if (g_se_prev_type == SECURE_ELEMENT_TYPE_UICC) - { - net_nfc_service_tapi_deinit(); - } - else - { - DEBUG_SERVER_MSG("SE type is not valid"); - } -} diff --git a/src/manager/org.tizen.NetNfcService.service b/src/manager/org.tizen.NetNfcService.service new file mode 100755 index 0000000..ae98f33 --- /dev/null +++ b/src/manager/org.tizen.NetNfcService.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=org.tizen.NetNfcService +Exec=/usr/bin/nfc-manager-daemon +User=root diff --git a/src/manager/sounds/Operation_sdk.wav b/src/manager/sounds/Operation_sdk.wav new file mode 100644 index 0000000..5383bdf Binary files /dev/null and b/src/manager/sounds/Operation_sdk.wav differ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index 298b93f..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -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") - -FILE(GLOB TESTS_SRCS *.c) - -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}") - -ADD_EXECUTABLE(${NFC_CLIENT_TEST} ${TESTS_SRCS}) -TARGET_LINK_LIBRARIES(${NFC_CLIENT_TEST} ${tests_pkgs_LDFLAGS} nfc) diff --git a/tests/main.c b/tests/main.c deleted file mode 100644 index 3a0f0d5..0000000 --- a/tests/main.c +++ /dev/null @@ -1,1000 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include "net_nfc.h" - -#include "net_nfc_test_client.h" -#include "net_nfc_test_llcp.h" -#include "net_nfc_test_snep.h" -#include "net_nfc_test_manager.h" -#include "net_nfc_test_tag.h" -#include "net_nfc_test_ndef.h" -#include "net_nfc_test_p2p.h" -#include "net_nfc_test_handover.h" -#include "net_nfc_test_transceive.h" -#include "net_nfc_test_jewel.h" -#include "net_nfc_test_tag_mifare.h" -#include "net_nfc_test_tag_felica.h" -#include "net_nfc_test_se.h" -#include "net_nfc_test_sys_handler.h" - - -typedef struct _TestData TestData; - -struct _TestData -{ - gchar *interface; - gchar *name; - GFunc func; - GFunc func_sync; - gchar *comment; -}; - -static TestData test_data[] = { - { - "Manager", - "SetActive", - net_nfc_test_manager_set_active, - net_nfc_test_manager_set_active_sync, - "Set activation", - }, - - { - "Manager", - "GetServerState", - net_nfc_test_manager_get_server_state, - net_nfc_test_manager_get_server_state_sync, - "Get server state" - }, - - { - "Client", - "ClientInitialize", - net_nfc_test_initialize, - NULL, - "Start Client Initialization" - }, - - { - "Client", - "ClientDeinitialize", - net_nfc_test_deinitialize, - NULL, - "Start Client Deinitialization" - }, - - { - "Client", - "ClientIsNfcSupported", - net_nfc_test_is_nfc_supported, - NULL, - "Get is nfc supported" - }, - - { - "Client", - "ClientGetNfcState", - net_nfc_test_get_nfc_state, - NULL, - "Get nfc state" - }, -#if 0 - { - "Tag", - "IsTagConnected", - net_nfc_test_tag_is_tag_connected, - net_nfc_test_tag_is_tag_connected_sync, - "Get is tag connected" - }, - { - "Tag", - "GetCurrentTagInfo", - net_nfc_test_tag_get_current_tag_info, - net_nfc_test_tag_get_current_tag_info_sync, - "Get current tag info" - }, - - { - "Tag", - "GetCurrentTargetHandle", - net_nfc_test_tag_get_current_target_handle, - net_nfc_test_tag_get_current_target_handle_sync, - "Get current target handle id" - }, -#endif - { - "Tag", - "TagDiscovered", /* waiting for signal */ - net_nfc_test_tag_set_tag_discovered, - NULL, - "Waiting for TagDiscoved signal" - }, - - { - "Tag", - "SetFilter", - net_nfc_test_tag_set_filter, - NULL, - "Set Tag filter" - }, - - { - "Tag", - "GetFilter", - net_nfc_test_tag_get_filter, - NULL, - "Get Tag filter" - }, - - - { - "Tag", - "TagDetached", /* waiting for signal */ - net_nfc_test_tag_set_tag_detached, - NULL, - "Waiting for TagDetached signal" - }, - - { - "Ndef", - "Read", - net_nfc_test_ndef_read, - net_nfc_test_ndef_read_sync, - "Read NDEF", - }, - - { - "Ndef", - "Write", - net_nfc_test_ndef_write, - net_nfc_test_ndef_write_sync, - "Write NDEF" - }, - - { - "Ndef", - "Format", - net_nfc_test_ndef_format, - net_nfc_test_ndef_format_sync, - "Format NDEF" - }, - - { - "Ndef", - "MakeReadOnly", - net_nfc_test_ndef_make_read_only, - net_nfc_test_ndef_make_read_only_sync, - "Make Tag Read only" - }, - - { - "p2p", - "Send", - net_nfc_test_p2p_send, - net_nfc_test_p2p_send_sync, - "P2P Send" - - }, - - { - "p2p", - "Discovered", /* waiting for signal*/ - net_nfc_test_p2p_set_device_discovered, - NULL, - "Waiting for Device Discovered Signal" - }, - - { - "p2p", - "Detached", /* waiting for signal*/ - net_nfc_test_p2p_set_device_detached, - NULL, - "Waiting for Device Detached Signal" - }, - - { - "p2p", - "Received", /* waiting for signal*/ - net_nfc_test_p2p_set_data_received, - NULL, - "Waiting for Device Data Received Signal" - }, - - { - "Transceive", - "TransceiveData", - net_nfc_test_transceive_data, - net_nfc_test_transceive_data_sync, - "Tansceive data method call " - }, - - { - "Transceive", - "Transceive", - net_nfc_test_transceive, - net_nfc_test_transceive_sync, - "Tansceive method call" - }, - - { - "Handover", - "BTRequest", - net_nfc_test_p2p_connection_handover_with_BT, - net_nfc_test_p2p_connection_handover_with_BT_sync, - "Handover Request Call" - - }, - - { - "Handover", - "WIFIRequest", - net_nfc_test_p2p_connection_handover_with_WIFI, - net_nfc_test_p2p_connection_handover_with_WIFI_sync, - "Handover Request Call" - - }, - - { - "Handover", - "GetCarrierType", - net_nfc_test_handover_get_alternative_carrier_type, - NULL, - "Get Handover Carrier Type" - - }, - - { - "Handover", - "HandleCarrierData", - net_nfc_test_handover_handle_alternative_carrier_data, - NULL, - "Create/Free Handover Carrier Data" - - }, - - { - "JewelTag", - "ReadId", - net_nfc_test_tag_jewel_read_id, - NULL, - "Jewel Read id" - - }, - - { - "JewelTag", - "ReadByte", - net_nfc_test_tag_jewel_read_byte, - NULL, - "Jewel Read Byte" - - }, - - { - "JewelTag", - "ReadAll", - net_nfc_test_tag_jewel_read_all, - NULL, - "Jewel Read All" - - }, - - { - "JewelTag", - "WriteWithErase", - net_nfc_test_tag_jewel_write_with_erase, - NULL, - "Jewel Write With Erase" - - }, - - { - "JewelTag", - "WriteWithNoErase", - net_nfc_test_tag_jewel_write_with_no_erase, - NULL, - "Jewel Write With No Erase" - - }, - - { - "MifareTag", - "Read", - net_nfc_test_tag_mifare_read, - NULL, - "Read Mifare Tag" - }, - - { - "MifareTag", - "WriteBlock", - net_nfc_test_tag_mifare_write_block, - NULL, - "Write data block" - }, - - { - "MifareTag", - "WritePage", - net_nfc_test_tag_mifare_write_page, - NULL, - "Write Page Data" - }, - - { - "MifareTag", - "Increment", - net_nfc_test_tag_mifare_increment, - NULL, - "Increment block value" - }, - - { - "MifareTag", - "Decrement", - net_nfc_test_tag_mifare_decrement, - NULL, - "Decrement block value" - }, - - { - "MifareTag", - "Transfer", - net_nfc_test_tag_mifare_transfer, - NULL, - " Data Transfer" - }, - - { - "MifareTag", - "Restore", - net_nfc_test_tag_mifare_restore, - NULL, - "Data Restore" - }, - - { - "MifareTag", - "AuthKeyA", - net_nfc_test_tag_mifare_authenticate_with_keyA, - NULL, - "Authenticate with key A" - }, - - { - "MifareTag", - "AuthKeyB", - net_nfc_test_tag_mifare_authenticate_with_keyB, - NULL, - "Authenticate with key B" - }, - - { - "FelicaTag", - "FelicaPoll", - net_nfc_test_felica_poll, - NULL, - "Felica Poll" - }, - - { - "FelicaTag", - "FelicaRequestService", - net_nfc_test_felica_request_service, - NULL, - "Felica Request Service" - }, - - { - "FelicaTag", - "FelicaRequestResponse", - net_nfc_test_felica_request_response, - NULL, - "Felica Request Response" - }, - - { - "FelicaTag", - "FelicaReadWithoutEncryption", - net_nfc_test_felica_read_without_encryption, - NULL, - "Felica Read Without Encryption" - }, - - { - "FelicaTag", - "FelicaWriteWithoutEncryption", - net_nfc_test_felica_write_without_encryption, - NULL, - "Felica Write Without Encryption" - }, - - { - "FelicaTag", - "FelicaRequestSystemCode", - net_nfc_test_felica_request_system_code, - NULL, - "Felica Request System Code" - }, - - { - "llcp", - "SetDefaultConfig", - net_nfc_test_llcp_default_config, - net_nfc_test_llcp_default_config_sync, - "Set the Default Config Options" - }, - - { - "llcp", - "SetCustomConfig", - net_nfc_test_llcp_custom_config, - net_nfc_test_llcp_custom_config_sync, - "Set the Customised Config Options" - }, - - { - "llcp", - "GetConfigWKS", - net_nfc_test_llcp_get_config_wks, - NULL, - "Get the Config of WKS" - }, - - - { - "llcp", - "GetConfigLTO", - net_nfc_test_llcp_get_config_lto, - NULL, - "Get the Config of LTO" - }, - - - { - "llcp", - "GetConfigMIU", - net_nfc_test_llcp_get_config_miu, - NULL, - "Get the Config of MIU" - }, - - { - "llcp", - "GetConfigOption", - net_nfc_test_llcp_get_config_option, - NULL, - "Get the Config Option Type" - }, - - { - "llcp", - "SetConfigWKS", - net_nfc_test_llcp_set_config_wks, - NULL, - "Set the Config for WKS" - }, - - - { - "llcp", - "SetConfigLTO", - net_nfc_test_llcp_set_config_lto, - NULL, - "Set the Config for LTO" - }, - - - { - "llcp", - "SetConfigMIU", - net_nfc_test_llcp_set_config_miu, - NULL, - "Set the Config for MIU" - }, - - { - "llcp", - "SetConfigOption", - net_nfc_test_llcp_set_config_option, - NULL, - "Set the Config Option Type" - }, - - { - "llcp", - "FreeConfig", - net_nfc_test_llcp_free_config, - NULL, - "Clear the llcp configuration options" - }, - - - { - "llcp", - "CreateCustomSocketOption", - net_nfc_test_llcp_create_custom_socket_option, - NULL, - "Create Custom Socket Option" - }, - - { - "llcp", - "CreateDefaultSocketOption", - net_nfc_test_llcp_create_default_socket_option, - NULL, - "Create Default Socket Option" - }, - - - { - "llcp", - "GetLocalSocketOption", - net_nfc_test_llcp_get_local_socket_option, - NULL, - "Get Local Socket Option" - }, - - - { - "llcp", - "GetLocalSocketMIU", - net_nfc_test_llcp_get_socket_option_miu, - NULL, - "Get Local Socket MIU" - }, - - - { - "llcp", - "GetLocalSocketRW", - net_nfc_test_llcp_get_socket_option_rw, - NULL, - "Get Local Socket RW" - }, - - - { - "llcp", - "GetLocalSocketOptionType", - net_nfc_test_llcp_get_socket_option_type, - NULL, - "Get Local Socket Option Type" - }, - - { - "llcp", - "SetLocalSocketMIU", - net_nfc_test_llcp_set_socket_option_miu, - NULL, - "Set Local Socket MIU" - }, - - - { - "llcp", - "SetLocalSocketRW", - net_nfc_test_llcp_set_socket_option_rw, - NULL, - "Set Local Socket RW" - }, - - - { - "llcp", - "SetLocalSocketOptionType", - net_nfc_test_llcp_set_socket_option_type, - NULL, - "Set Local Socket Option Type" - }, - - { - "llcp", - "FreeSocketOption", - net_nfc_test_llcp_free_socket_option, - NULL, - "Free Socket Option" - }, - - { - "llcp", - "ListenToSocket", - net_nfc_test_llcp_listen, - net_nfc_test_llcp_listen_sync, - "Listen To Server Socket" - }, - - { - "llcp", - "ReceiveSocket", - net_nfc_test_llcp_receive, - net_nfc_test_llcp_receive_sync, - "Receive data from socket " - }, - - { - "llcp", - "ReceiveFromSocket", - net_nfc_test_llcp_receive_from, - net_nfc_test_llcp_receive_from_sync, - "Receive data from socket (sap data also included)" - }, - - { - "llcp", - "ConnectToSocket", - net_nfc_test_llcp_connect, - net_nfc_test_llcp_connect_sync, - "Connect to a socket" - }, - - { - "llcp", - "ConnectToSapSocket", - net_nfc_test_llcp_connect_sap, - net_nfc_test_llcp_connect_sap_sync, - "Connect to a specific SAP on the socket" - }, - - { - "llcp", - "SendToSocket", - net_nfc_test_llcp_send, - net_nfc_test_llcp_send_sync, - "Send Data to a socket" - }, - - { - "llcp", - "SendToSapSocket", - net_nfc_test_llcp_send_to, - net_nfc_test_llcp_send_to_sync, - "Send data to a specific SAP on the socket" - }, - - { - "llcp", - "DisconnectSocket", - net_nfc_test_llcp_disconnect, - net_nfc_test_llcp_disconnect_sync, - "Disconnects the client socket" - }, - - { - "llcp", - "DisconnectOtherSockets", - net_nfc_test_llcp_disconnect_server, - NULL, - "Disconnects the Server and Accepted sockets" - }, - - { - "snep", - "SNEPTagDiscovery", - net_nfc_test_snep_set_tag_discovered, - NULL, - "Discovers the tag/target before starting SNEP operation" - }, - - { - "snep", - "SNEPP2PDeviceDiscovery", - net_nfc_test_snep_set_p2p_device_discovered, - NULL, - "Discover the P2P device for snep operation" - }, - - { - "snep", - "StartSNEPServer", - net_nfc_test_snep_start_server, - net_nfc_test_snep_start_server_sync, - "Starts the SNEP server" - }, - - { - "snep", - "StartSNEPClient", - net_nfc_test_snep_start_client, - NULL, - "Starts the SNEP client" - }, - - { - "snep", - "SendClientRequest", - net_nfc_test_snep_send_client_request, - NULL, - "Sends the SNEP client Request" - }, - - { - "snep", - "RegisterServer", - net_nfc_test_snep_register_server, - NULL, - "Registers the SNEP server" - }, - - { - "snep", - "UnRegisterServer", - net_nfc_test_snep_unregister_server, - NULL, - "UnRegisters the SNEP server" - }, - - { - "snep", - "ServerRegisterUnregister", - net_nfc_test_snep_register_unregister_server, - NULL, - "Registers and UnRegisters the SNEP server" - }, - - { - "snep", - "StopService", - net_nfc_test_snep_stop_service_sync, - NULL, - "Registers and UnRegisters the SNEP server" - }, - - { - "SE", - "SendApdu", - net_nfc_test_se_send_apdu, - net_nfc_test_se_send_apdu_sync, - "Secure element send apdu data" - }, - - { - "SE", - "SetType", - net_nfc_test_se_set_secure_element_type, - net_nfc_test_se_set_secure_element_type_sync, - "Set secure element type" - }, - - { - "SE", - "Open", - net_nfc_test_se_open_internal_secure_element, - net_nfc_test_se_open_internal_secure_element_sync, - "Open internal secure element" - }, - - { - "SE", - "Close", - net_nfc_test_se_close_internal_secure_element, - net_nfc_test_se_close_internal_secure_element_sync, - "Close internal secure element" - }, - - { - "SE", - "GetAtr", - net_nfc_test_se_get_atr, - net_nfc_test_se_get_atr_sync, - "Get secure element attribute" - }, - - { - "SE", - "SetEventCallback", - net_nfc_test_se_set_event_cb, - NULL, - "Set event callback" - }, - - { - "SE", - "UnsetEventCallback", - net_nfc_test_se_unset_event_cb, - NULL, - "Unset event callback" - }, - - { - "SE", - "SetDetectionCallback", - net_nfc_test_se_set_ese_detection_cb, - NULL, - "Set detection callback" - }, - - { - "SE", - "UnsetDetectionCallback", - net_nfc_test_se_unset_ese_detection_cb, - NULL, - "Unset detection callback" - }, - - { - "SE", - "SetTransactionCallback", - net_nfc_test_se_set_transaction_event_cb, - NULL, - "Set transaction callback" - }, - - { - "SE", - "UnsetTransactionCallback", - net_nfc_test_se_unset_transaction_event_cb, - NULL, - "Unset transaction callback" - }, - - { - "SystemHandler", - "SetLaunchPopState", - net_nfc_test_sys_handler_set_launch_popup_state, - net_nfc_test_sys_handler_set_launch_popup_state_sync, - "Set launch popup state" - }, - - { - "SystemHandler", - "SetLaunchPopStateForce", - net_nfc_test_sys_handler_set_launch_popup_state_force, - net_nfc_test_sys_handler_set_launch_popup_state_force_sync, - "Set launch popup state" - }, - - { - "SystemHandler", - "GetLaunchPopState", - net_nfc_test_sys_handler_get_launch_popup_state, - NULL, - "Get launch popup state" - }, - - { NULL } -}; - - -static GMainLoop *loop = NULL; - -static GList *pos = NULL; - -static void test_string_free(gpointer data); - -static void run_test(void); - -static void test_string_free(gpointer data) -{ - gchar **strv; - - if (data) - { - strv = data; - g_strfreev(strv); - } -} - -static void run_test(void) -{ - gchar **strv; - gint i = 0; - - if (pos == NULL) - return; - - strv = pos->data; - - for (i = 0; test_data[i].interface != NULL; i++) - { - if (strv[0] == NULL) - continue; - - if (strv[1] == NULL) - continue; - - if ((strcmp(strv[0], test_data[i].interface) == 0) && - (strcmp(strv[1], test_data[i].name) == 0)) - { - pos = pos->next; - - - if (strv[2] && strcmp(strv[2], "Sync") == 0) - { - g_print("run %s.%s(Sync)\n", strv[0], strv[1]); - test_data[i].func_sync(NULL, - (gpointer)run_test); - } - else - { - g_print("run %s.%s\n", strv[0], strv[1]); - test_data[i].func(NULL, - (gpointer)run_test); - } - - break; - } - } -} - -int main(int argc, char *argv[]) -{ - gint i; - - if (argc == 2 && strcmp(argv[1], "--help") == 0) - { - g_print("nfc-client-test: nfc-client-test [inteface.name]\n"); - g_print("\n"); - - for (i = 0; i < G_N_ELEMENTS(test_data) - 1; i++) - { - g_print("\t%s - %s : %s\n", test_data[i].interface, - test_data[i].name, - test_data[i].comment); - } - return 0; - } - - for (i = 1 ; i < argc ; i++) - { - gchar **strv; - - strv = g_strsplit(argv[i], ".", 3); - pos = g_list_append(pos, strv); - } - - if (pos == NULL) - { - gchar **strv; - - strv = g_strsplit("Manager.SetActive", ".", 3); - pos = g_list_append(pos, strv); - } - else - { - gchar **strv; - - strv = pos->data; - - if (strcmp(strv[0], "Manager") != 0 || - strcmp(strv[1], "SetActive") != 0) - { - gchar **manager_strv; - - manager_strv = g_strsplit("Manager.SetActive", ".", 3); - pos = g_list_prepend(pos, manager_strv); - } - } - - net_nfc_client_initialize(); - - run_test(); - - loop = g_main_loop_new(NULL, FALSE); - - g_main_loop_run(loop); - - net_nfc_client_deinitialize(); - - if (pos) - g_list_free_full(pos, test_string_free); - - return 0; -} diff --git a/tests/net_nfc_test_client.c b/tests/net_nfc_test_client.c deleted file mode 100644 index 9b37667..0000000 --- a/tests/net_nfc_test_client.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "net_nfc_test_client.h" -#include "net_nfc_client_context.h" -#include "net_nfc_test_client.h" -#include "net_nfc_typedef_internal.h" - - -static void run_next_callback(gpointer user_data); - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - callback(); - } -} - -void net_nfc_test_initialize(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - - result = net_nfc_client_initialize(); - - if(result != NET_NFC_OK) - { - g_print("Client Initialization failed & Result is %d\n", result); - return; - } - - g_print("Client Initialization Completed & Result is %d\n", result); - - run_next_callback(user_data); -} - -void net_nfc_test_deinitialize(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - - result = net_nfc_client_deinitialize(); - - g_print("Client Deinitialization Completed & Result is %d\n", result); -} - -void net_nfc_test_is_nfc_supported(gpointer data, gpointer user_data) -{ - int feature = 0; - net_nfc_error_e result = NET_NFC_OK; - - result = net_nfc_client_is_nfc_supported(&feature); - - if((result != NET_NFC_OK) || (feature != 1)) - { - g_print("Client is_nfc_supported failed & result is %d\n", result); - g_print("Client is_nfc_supported failed & feature value is %d\n", feature); - return; - } - - g_print("Client is_nfc_supported completed & feature value is %d\n", feature); - g_print("Client is_nfc_supported completed & result is %d\n", result); - - run_next_callback(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; - - result = net_nfc_client_get_nfc_state(&state); - - if((result != NET_NFC_OK) || (state != 1)) - { - g_print("Client get_nfc_state failed & result is %d\n", result); - g_print("Client get_nfc_state failed & state value is %d\n", state); - return; - } - - g_print("Client get_nfc_state completed & state value is %d\n", state); - g_print("Client get_nfc_state completed & result is %d\n", result); - - run_next_callback(user_data); -} diff --git a/tests/net_nfc_test_client.h b/tests/net_nfc_test_client.h deleted file mode 100644 index bc78d45..0000000 --- a/tests/net_nfc_test_client.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -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__ - diff --git a/tests/net_nfc_test_handover.c b/tests/net_nfc_test_handover.c deleted file mode 100644 index 7593dea..0000000 --- a/tests/net_nfc_test_handover.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_client_handover.h" -#include "net_nfc_test_handover.h" -#include "net_nfc_test_util.h" -#include "net_nfc_target_info.h" -#include "net_nfc_typedef_internal.h" -#include "net_nfc_typedef.h" -#include "net_nfc_test_p2p.h" -#include "net_nfc_util_internal.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_s *data, - void *user_data); - -static net_nfc_connection_handover_info_s *global_info = NULL; - - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - callback = (GCallback)(user_data); - callback(); - } -} - -static void p2p_connection_handover_cb(net_nfc_error_e result, - net_nfc_conn_handover_carrier_type_e type, - data_s *data, - void *user_data) -{ - g_print("Connection handover completed\n"); - - print_received_data(data); - - global_info->type = type; - - if(data->length > 0) - { - g_print("Callback has valid data \n"); - global_info->data.buffer = data->buffer; - global_info->data.length = data->length; - print_received_data(&global_info->data); - } - - run_next_callback(user_data); -} - -static void _p2p_connection_handover( - net_nfc_conn_handover_carrier_type_e type, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - - handle = net_nfc_test_device_get_target_handle(); - - g_print("handle for handover : %p \n", handle); - - result = net_nfc_client_p2p_connection_handover( - handle, - type, - p2p_connection_handover_cb, - user_data); - g_print("net_nfc_client_p2p_connection_handover() : %d\n", result); -} - -static void _p2p_connection_handover_sync( - net_nfc_conn_handover_carrier_type_e type, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_conn_handover_carrier_type_e out_carrier; - data_s *out_data = NULL; - net_nfc_target_handle_s *handle = NULL; - - handle = net_nfc_test_device_get_target_handle(); - - result = net_nfc_client_p2p_connection_handover_sync( - handle, - type, - &out_carrier, - &out_data); - g_print("net_nfc_client_p2p_connection_handover_sync() : %d\n", result); - - 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_p2p_connection_handover_with_BT(gpointer data, - gpointer user_data) -{ - _p2p_connection_handover(NET_NFC_CONN_HANDOVER_CARRIER_BT, user_data); -} - -void net_nfc_test_p2p_connection_handover_with_WIFI(gpointer data, - gpointer user_data) -{ - _p2p_connection_handover(NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS, user_data); -} - -void net_nfc_test_p2p_connection_handover_with_BT_sync(gpointer data, - gpointer user_data) -{ - _p2p_connection_handover_sync(NET_NFC_CONN_HANDOVER_CARRIER_BT, user_data); -} - -void net_nfc_test_p2p_connection_handover_with_WIFI_sync(gpointer data, - gpointer user_data) -{ - _p2p_connection_handover_sync(NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS, user_data); -} - -void net_nfc_test_handover_get_alternative_carrier_type(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_conn_handover_carrier_type_e type; - - result = net_nfc_client_handover_get_alternative_carrier_type(global_info, &type); - g_print("net_nfc_client_handover_get_alternative_carrier_type() : %d\n", result); - g_print("Handover alternative carrier type -> %d", type); -} - -void net_nfc_test_handover_handle_alternative_carrier_data(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - data_s *out_data = NULL; - net_nfc_connection_handover_info_s *hand_info = NULL; - - result = net_nfc_client_handover_get_alternative_carrier_data(global_info, &out_data); - g_print(" Get alternative carrier data %d", result); - print_received_data(out_data); - - hand_info = global_info; - - result = net_nfc_client_handover_free_alternative_carrier_data(hand_info); - g_print("Free alternative carrier data %d", result); -} diff --git a/tests/net_nfc_test_handover.h b/tests/net_nfc_test_handover.h deleted file mode 100644 index bacd7f0..0000000 --- a/tests/net_nfc_test_handover.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - - -void net_nfc_test_p2p_connection_handover_with_BT(gpointer data, - gpointer user_data); - -void net_nfc_test_p2p_connection_handover_with_BT_sync(gpointer data, - gpointer user_data); - -void net_nfc_test_p2p_connection_handover_with_WIFI(gpointer data, - gpointer user_data); - -void net_nfc_test_p2p_connection_handover_with_WIFI_sync(gpointer data, - gpointer user_data); - -void net_nfc_test_handover_handle_alternative_carrier_data(gpointer data, - gpointer user_data); - -void net_nfc_test_handover_get_alternative_carrier_type(gpointer data, - gpointer user_data); - - -#endif //__NET_NFC_TEST_HANDOVER_H__ - diff --git a/tests/net_nfc_test_jewel.c b/tests/net_nfc_test_jewel.c deleted file mode 100644 index 0562f26..0000000 --- a/tests/net_nfc_test_jewel.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" -#include "net_nfc_test_util.h" -#include "net_nfc_client_tag_jewel.h" -#include "net_nfc_target_info.h" -#include "net_nfc_test_tag.h" - - -static net_nfc_target_handle_s* get_handle() -{ - net_nfc_target_info_s *info = NULL; - net_nfc_target_handle_s *handle = NULL; - - info = net_nfc_test_tag_get_target_info(); - - net_nfc_get_tag_handle(info, &handle); - - return handle; -} - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - - callback(); - } -} - - -/*********************************** Callbacks *************************************/ - -static void jewel_read_cb(net_nfc_error_e result, - data_s *resp_data, - void *user_data) -{ - - g_print("jewel_read_cb Completed %d\n", result); - - print_received_data(resp_data); - - run_next_callback(user_data); -} - -static void jewel_write_cb(net_nfc_error_e result, - void* user_data) -{ - g_print("jewel_write_cb Completed %d\n", result); - - run_next_callback(user_data); -} - - -/*********************************** Function Calls *************************************/ - - -void net_nfc_test_tag_jewel_read_id(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - - handle = get_handle(); - - result = net_nfc_client_jewel_read_id(handle, - jewel_read_cb, - user_data); - g_print("net_nfc_client_jewel_read_id() : %d\n", result); -} - -void net_nfc_test_tag_jewel_read_byte(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - uint8_t block = 0x01; - uint8_t byte = 1; - - handle = get_handle(); - - result = net_nfc_client_jewel_read_byte(handle, - block, - byte, - jewel_read_cb, - user_data); - g_print("net_nfc_client_jewel_read_byte() : %d\n", result); -} - -void net_nfc_test_tag_jewel_read_all(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - - handle = get_handle(); - - result = net_nfc_client_jewel_read_all(handle, - jewel_read_cb, - user_data); - g_print("net_nfc_client_jewel_read_all() : %d\n", result); -} - -void net_nfc_test_tag_jewel_write_with_erase(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - uint8_t block = 0x01; - uint8_t byte = 1; - uint8_t data_to_write = 'A'; - - handle = get_handle(); - - result = net_nfc_client_jewel_write_with_erase(handle, - block, - byte, - data_to_write, - jewel_write_cb, - user_data); - g_print("net_nfc_client_jewel_write_with_erase() : %d\n", result); -} - -void net_nfc_test_tag_jewel_write_with_no_erase(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - uint8_t block = 0x01; - uint8_t byte = 1; - uint8_t data_to_write = 'A'; - - handle = get_handle(); - - result = net_nfc_client_jewel_write_with_erase(handle, - block, - byte, - data_to_write, - jewel_write_cb, - user_data); - g_print("net_nfc_client_jewel_write_with_erase() : %d\n", result); -} diff --git a/tests/net_nfc_test_jewel.h b/tests/net_nfc_test_jewel.h deleted file mode 100644 index d3c89c5..0000000 --- a/tests/net_nfc_test_jewel.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - - -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 //__NET_NFC_TEST_JEWEL_TAG_H__ \ No newline at end of file diff --git a/tests/net_nfc_test_llcp.c b/tests/net_nfc_test_llcp.c deleted file mode 100755 index 3318e5f..0000000 --- a/tests/net_nfc_test_llcp.c +++ /dev/null @@ -1,1050 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_util.h" -#include "net_nfc_client_llcp.h" -#include "net_nfc_test_llcp.h" -#include "net_nfc_data.h" -#include "net_nfc_target_info.h" -#include "net_nfc_typedef_internal.h" - - -static net_nfc_llcp_socket_t server_test_socket; -static net_nfc_llcp_socket_t client_test_socket; - -static net_nfc_llcp_config_info_s *llcp_config = NULL; -static net_nfc_llcp_config_info_s *llcp_config_sync = NULL; -static net_nfc_llcp_config_info_s *llcp_config_default = NULL; -static net_nfc_llcp_config_info_s *llcp_config_default_sync = NULL; - - -/*********************************** utility Calls *************************************/ - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - callback(); - } -} - -/*********************************** Callbacks *************************************/ - -static void llcp_default_config_cb(net_nfc_error_e result, void *user_data) -{ - g_print(" llcp_default_config_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void llcp_custom_config_cb(net_nfc_error_e result, void *user_data) -{ - g_print("llcp_custom_config_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void llcp_listen_socket_cb(net_nfc_error_e result, - net_nfc_llcp_socket_t client_socket, void *user_data) -{ - - g_print("llcp_listen_socket_cb Completed %d\n", client_socket); - g_print("llcp_listen_socket_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void llcp_receive_socket_cb(net_nfc_error_e result, data_s *data, - void *user_data) -{ - data_s *received_data = data; - - print_received_data(received_data); - - g_print("llcp_listen_socket_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void llcp_receive_from_socket_cb(net_nfc_error_e result, - sap_t sap, - data_s *data, - void *user_data) -{ - data_s *received_data = data; - - print_received_data(received_data); - - g_print("llcp_receive_from_socket_cb Completed %d\n", sap); - - g_print("llcp_receive_from_socket_cb Completed %d\n", result); - - run_next_callback(user_data); -} - - -static void llcp_connect_socket_cb(net_nfc_error_e result, - 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); - - run_next_callback(user_data); -} - - -static void llcp_connect_sap_cb(net_nfc_error_e result, - 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); - - run_next_callback(user_data); -} - - -static void llcp_send_socket_cb(net_nfc_error_e result, void *user_data) -{ - g_print("llcp_send_socket_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void llcp_send_to_socket_cb(net_nfc_error_e result, void *user_data) -{ - g_print("llcp_send_to_socket_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void llcp_disconnect_socket_cb(net_nfc_error_e result, void *user_data) -{ - g_print("llcp_send_to_socket_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -/*********************************** Function Calls *************************************/ - -void net_nfc_test_llcp_default_config(gpointer data, gpointer user_data) -{ - net_nfc_error_e result; - - result = net_nfc_client_llcp_create_config_default(&llcp_config_default); - - if(result != NET_NFC_OK) - { - g_print(" llcp create default config failed: %d\n", result); - run_next_callback(user_data); - return; - - } - result = net_nfc_client_llcp_config(llcp_config_default, - llcp_default_config_cb, - user_data); - -} - -void net_nfc_test_llcp_default_config_sync(gpointer data, gpointer user_data) -{ - net_nfc_error_e result; - - result = net_nfc_client_llcp_create_config_default(&llcp_config_default_sync); - - if(result != NET_NFC_OK) - { - g_print(" llcp create default config failed: %d\n", result); - run_next_callback(user_data); - return; - } - - result = net_nfc_client_llcp_config_sync(llcp_config_default_sync); - if(result == NET_NFC_OK) - { - g_print(" llcp create default config (sync) success: %d\n", result); - } -} - - -void net_nfc_test_llcp_custom_config(gpointer data, gpointer user_data) -{ - net_nfc_error_e result; - - result = net_nfc_client_llcp_create_config(&llcp_config,128, 1, 10, 0); - - if(result != NET_NFC_OK) - { - g_print(" llcp create custom config failed: %d\n", result); - run_next_callback(user_data); - return; - } - result = net_nfc_client_llcp_config(llcp_config, llcp_custom_config_cb, user_data); -} - - - -void net_nfc_test_llcp_custom_config_sync(gpointer data, gpointer user_data) -{ - - net_nfc_error_e result; - - result = net_nfc_client_llcp_create_config(&llcp_config_sync,128, 1, 10, 0); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_custom_config_sync failed: %d\n", result); - run_next_callback(user_data); - return; - } - result = net_nfc_client_llcp_config_sync(llcp_config_sync); - - if(result == NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_custom_config_sync (sync) success: %d\n", result); - } - -} - -void net_nfc_test_llcp_get_local_config(gpointer data, gpointer user_data) -{ - net_nfc_llcp_config_info_s *local_config; - net_nfc_error_e result; - - result = net_nfc_client_llcp_get_local_config(&local_config); - - if(result != NET_NFC_OK) - { - 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->miu); - g_print("net_nfc_test_llcp_get_local_config: %d\n", local_config->wks); - 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); -} - - -/*commented because remote config API is not available*/ -#if 0 -void net_nfc_test_llcp_get_remote_config(gpointer data, - gpointer user_data) -{ - net_nfc_llcp_config_info_s *local_config; - net_nfc_error_e result; - - result = net_nfc_client_llcp_get_local_config(&local_config); - - if(result != NET_NFC_OK) - { - 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->miu); - g_print("net_nfc_test_llcp_get_local_config: %d\n", local_config->wks); - 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); - -} -#endif - -void net_nfc_test_llcp_get_config_miu(gpointer data, - gpointer user_data) -{ - - net_nfc_error_e result; - uint16_t miu; - - result = net_nfc_client_llcp_get_config_miu(llcp_config,&miu); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_get_config_miu failed: %d\n", result); - run_next_callback(user_data); - return; - } - - if(result == NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_get_config_miu ->: %d\n", miu); - } - - run_next_callback(user_data); - -} - - -void net_nfc_test_llcp_get_config_wks(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - uint16_t wks; - - result = net_nfc_client_llcp_get_config_wks(llcp_config,&wks); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_get_config_wks failed: %d\n", result); - run_next_callback(user_data); - return; - } - - if(result == NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_get_config_wks -> %d\n",wks); - } - - run_next_callback(user_data); -} - -void net_nfc_test_llcp_get_config_lto(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - uint8_t lto; - - result = net_nfc_client_llcp_get_config_lto(llcp_config,<o); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_client_llcp_get_config_lto failed: %d\n", result); - run_next_callback(user_data); - return; - } - - if(result == NET_NFC_OK) - { - g_print(" net_nfc_client_llcp_get_config_lto -> %d\n",lto); - } - - run_next_callback(user_data); - -} - - -void net_nfc_test_llcp_get_config_option(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - uint8_t option; - - result = net_nfc_client_llcp_get_config_option(llcp_config,&option); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_get_config_option failed: %d\n", result); - run_next_callback(user_data); - return; - } - - if(result == NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_get_config_option -> %d\n",option); - } - - run_next_callback(user_data); - -} - - -void net_nfc_test_llcp_set_config_miu(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - uint16_t miu = 128; - - result = net_nfc_client_llcp_set_config_miu(llcp_config,miu); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_get_config_miu failed: %d\n", result); - run_next_callback(user_data); - return; - } - - if(result == NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_set_config_miu successfull \n"); - } - - run_next_callback(user_data); - -} - - -void net_nfc_test_llcp_set_config_wks(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - uint16_t wks = 1; - - result = net_nfc_client_llcp_set_config_wks(llcp_config,wks); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_set_config_wks failed: %d\n", result); - run_next_callback(user_data); - return; - } - - if(result == NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_set_config_wks successfull \n"); - } - - run_next_callback(user_data); - -} - - -void net_nfc_test_llcp_set_config_lto(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - uint16_t lto = 10; - - result = net_nfc_client_llcp_set_config_lto(llcp_config,lto); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_set_config_lto failed: %d\n", result); - run_next_callback(user_data); - return; - } - - if(result == NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_set_config_lto successfull \n"); - } - run_next_callback(user_data); - -} - - -void net_nfc_test_llcp_set_config_option(gpointer data, - gpointer user_data) -{ - - net_nfc_error_e result; - uint8_t option = 0; - - result = net_nfc_client_llcp_set_config_lto(llcp_config,option); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_set_config_option failed: %d\n", result); - run_next_callback(user_data); - return; - } - - if(result == NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_set_config_option successfull \n"); - } - run_next_callback(user_data); -} - - -void net_nfc_test_llcp_free_config(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - - result = net_nfc_client_llcp_free_config(llcp_config); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_free_config failed: %d\n", result); - run_next_callback(user_data); - return; - } - - if(result == NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_free_config successfull \n"); - } - run_next_callback(user_data); -} - - -void net_nfc_test_llcp_create_custom_socket_option(gpointer data, - gpointer user_data) -{ - net_nfc_llcp_socket_option_s *option; - net_nfc_error_e result; - - result = net_nfc_client_llcp_create_socket_option(&option, - 128, - 1, - NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_client_llcp_create_socket_option failed: %d\n", result); - run_next_callback(user_data); - - return; - } - - g_print(" net_nfc_client_llcp_create_socket_option : %d\n", result); - run_next_callback(user_data); - -} - -void net_nfc_test_llcp_create_default_socket_option(gpointer data, - gpointer user_data) -{ - net_nfc_llcp_socket_option_s *option; - net_nfc_error_e result; - - result = net_nfc_client_llcp_create_socket_option_default(&option); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_create_default_socket_option failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_create_default_socket_option : %d\n", result); - run_next_callback(user_data); - -} - -void net_nfc_test_llcp_get_local_socket_option(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - net_nfc_llcp_socket_option_s *option; - - result = net_nfc_client_llcp_get_local_socket_option(client_test_socket,&option); - - 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->miu); - g_print("net_nfc_test_llcp_get_local_socket_option: %d\n", option->rw); - g_print(" net_nfc_test_llcp_get_local_socket_option: %d\n", option->type); - - run_next_callback(user_data); -} - -void net_nfc_test_llcp_get_socket_option_miu(gpointer data, - gpointer user_data) -{ - net_nfc_llcp_socket_option_s option; - net_nfc_error_e result; - uint16_t miu; - - result = net_nfc_client_llcp_get_socket_option_miu(&option,&miu); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_client_llcp_get_socket_option_miu failed: %d\n", result); - run_next_callback(user_data); - - return; - } - - g_print(" net_nfc_test_llcp_get_socket_option_miu : %d\n", miu); - run_next_callback(user_data); -} - - -void net_nfc_test_llcp_set_socket_option_miu(gpointer data, - gpointer user_data) -{ - net_nfc_llcp_socket_option_s option; - net_nfc_error_e result; - uint16_t miu = 128; - - result = net_nfc_client_llcp_set_socket_option_miu(&option,miu); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_set_socket_option_miu failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_set_socket_option_miu : %d\n", miu); - run_next_callback(user_data); -} - -void net_nfc_test_llcp_get_socket_option_rw(gpointer data, - gpointer user_data) -{ - net_nfc_llcp_socket_option_s option; - net_nfc_error_e result; - uint8_t rw; - - result = net_nfc_client_llcp_get_socket_option_rw(&option,&rw); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_get_socket_option_rw failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_get_socket_option_rw : %d\n", rw); - run_next_callback(user_data); -} - - -void net_nfc_test_llcp_set_socket_option_rw(gpointer data, - gpointer user_data) -{ - net_nfc_llcp_socket_option_s option; - net_nfc_error_e result; - uint8_t rw = 1; - - result = net_nfc_client_llcp_set_socket_option_rw(&option,rw); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_set_socket_option_rw failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_set_socket_option_rw : %d\n", rw); - run_next_callback(user_data); -} - -void net_nfc_test_llcp_get_socket_option_type(gpointer data, - gpointer user_data) -{ - net_nfc_llcp_socket_option_s option; - net_nfc_error_e result; - net_nfc_socket_type_e type; - - result = net_nfc_client_llcp_get_socket_option_type(&option,&type); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_get_socket_option_type failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_get_socket_option_type : %d\n", type); - run_next_callback(user_data); -} - - -void net_nfc_test_llcp_set_socket_option_type(gpointer data, - gpointer user_data) -{ - net_nfc_llcp_socket_option_s option; - net_nfc_error_e result; - net_nfc_socket_type_e type = NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED; - - result = net_nfc_client_llcp_set_socket_option_type(&option,type); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_set_socket_option_type failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_set_socket_option_type : %d\n", type); - run_next_callback(user_data); -} - -void net_nfc_test_llcp_free_socket_option(gpointer data, - gpointer user_data) -{ - net_nfc_llcp_socket_option_s option; - net_nfc_error_e result; - - result = net_nfc_client_llcp_free_socket_option(&option); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_free_socket_option failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_free_socket_option : %d\n", result); - run_next_callback(user_data); -} - - -void net_nfc_test_llcp_listen(gpointer 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); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_client_llcp_listen failed: %d\n", result); - return; - } -} - -void net_nfc_test_llcp_listen_sync(gpointer 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); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_listen_sync failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_listen_sync : out_socket %d\n", out_socket); - run_next_callback(user_data); - -} - - -void net_nfc_test_llcp_receive(gpointer data, - gpointer user_data) -{ - - net_nfc_error_e result; - - - result = net_nfc_client_llcp_receive(server_test_socket, - 512, - llcp_receive_socket_cb, - NULL); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_client_llcp_listen failed: %d\n", result); - return; - } -} - - -void net_nfc_test_llcp_receive_sync(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - data_s *out_data; - - - result = net_nfc_client_llcp_receive_sync(server_test_socket, - 512, - &out_data); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_client_llcp_listen failed: %d\n", result); - run_next_callback(user_data); - return; - } - - print_received_data(out_data); - run_next_callback(user_data); -} - - - -void net_nfc_test_llcp_receive_from(gpointer 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); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_receive_from failed: %d\n", result); - return; - } -} - -void net_nfc_test_llcp_receive_from_sync(gpointer data, gpointer user_data) -{ - net_nfc_error_e result; - data_s *out_data = NULL; - sap_t sap_data = 0; - - result = net_nfc_client_llcp_receive_from_sync(server_test_socket, - 512, - &sap_data, - &out_data); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_client_llcp_listen failed: %d\n", result); - return; - } - - print_received_data(out_data); - g_print(" net_nfc_test_llcp_receive_from_sync : %d\n", result); - g_print(" net_nfc_test_llcp_receive_from_sync : %d\n", sap_data); - run_next_callback(user_data); -} - -void net_nfc_test_llcp_connect(gpointer 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); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_connect failed: %d\n", result); - return; - } - -} - -void net_nfc_test_llcp_connect_sync(gpointer 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); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_connect_sync failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_connect_sync : out_socket %d\n", out_socket); - run_next_callback(user_data); -} - -void net_nfc_test_llcp_connect_sap(gpointer 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); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_connect_sap failed: %d\n", result); - return; - } - -} - -void net_nfc_test_llcp_connect_sap_sync(gpointer 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); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_connect_sap_sync failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_connect_sap_sync : out_socket %d\n", out_socket); - run_next_callback(user_data); -} - -void net_nfc_test_llcp_send(gpointer func_data, gpointer user_data) -{ - net_nfc_error_e result; - data_s *data; - char * str = "Client message: Hello, server!"; - - 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); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_send failed: %d\n", result); - return; - } - -} - -void net_nfc_test_llcp_send_sync(gpointer func_data, gpointer user_data) -{ - net_nfc_error_e result; - data_s *data; - char * str = "Client message: Hello, server!"; - - net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1); - - result = net_nfc_client_llcp_send_sync(client_test_socket, data); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_connect failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_send_sync success\n"); - run_next_callback(user_data); - -} - - -void net_nfc_test_llcp_send_to(gpointer func_data, gpointer user_data) -{ - net_nfc_error_e result; - data_s *data; - char * str = "Client message: Hello, server!"; - - 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); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_send_to failed: %d\n", result); - return; - } - -} - - -void net_nfc_test_llcp_send_to_sync(gpointer func_data, gpointer user_data) -{ - net_nfc_error_e result; - data_s *data; - char * str = "Client message: Hello, server!"; - - 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); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_send_to_sync failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_send_to_sync success\n"); - run_next_callback(user_data); - -} - - -void net_nfc_test_llcp_disconnect(gpointer func_data, gpointer user_data) -{ - net_nfc_error_e result; - - result = net_nfc_client_llcp_disconnect(client_test_socket, - llcp_disconnect_socket_cb, - user_data); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_disconnect failed: %d\n", result); - return; - } - -} - -void net_nfc_test_llcp_disconnect_server(gpointer func_data, gpointer user_data) -{ - net_nfc_error_e result; - - result = net_nfc_client_llcp_disconnect(server_test_socket, - llcp_disconnect_socket_cb, - user_data); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_disconnect accepted_socket failed: %d\n", result); - return; - } -} - -void net_nfc_test_llcp_disconnect_sync(gpointer func_data, gpointer user_data) -{ - net_nfc_error_e result; - - result = net_nfc_client_llcp_disconnect_sync(client_test_socket); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_llcp_disconnect_sync failed: %d\n", result); - run_next_callback(user_data); - return; - } - - g_print(" net_nfc_test_llcp_disconnect_sync success\n"); - run_next_callback(user_data); -} diff --git a/tests/net_nfc_test_llcp.h b/tests/net_nfc_test_llcp.h deleted file mode 100644 index a945c34..0000000 --- a/tests/net_nfc_test_llcp.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - - -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 diff --git a/tests/net_nfc_test_manager.c b/tests/net_nfc_test_manager.c deleted file mode 100644 index 93b1e7e..0000000 --- a/tests/net_nfc_test_manager.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "net_nfc_client_manager.h" -#include "net_nfc_typedef_internal.h" - - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - callback = (GCallback)(user_data); - callback(); - } -} - -static void print_server_state(gint state) -{ - if (state == 0) - g_print(" --- state : Unknown(%d)\n", state); - else - { - g_print(" --- state :\n"); - if (state & NET_NFC_SERVER_DISCOVERY) - g_print("\tNET_NFC_SERVER_DISCOVERY(%d)\n", state); - if (state & NET_NFC_TAG_CONNECTED) - g_print("\tNET_NFC_TAG_CONNECTED(%d)\n", state); - if (state & NET_NFC_SE_CONNECTION) - g_print("\tNET_NFC_SE_CONNECTED(%d)\n", state); - if (state & NET_NFC_SNEP_CLIENT_CONNECTED) - { - g_print("\tNET_NFC_SNEP_CLIENT_CONNECTED(%d)\n", - state); - } - if (state & NET_NFC_NPP_CLIENT_CONNECTED) - g_print("\tNET_NFC_NPP_CLIENT_CONNECTED(%d)\n", state); - if (state & NET_NFC_SNEP_SERVER_CONNECTED) - g_print("\tNET_NFC_SNEP_SERVER_CONNECTED(%d)\n", state); - if (state & NET_NFC_NPP_SERVER_CONNECTED) - g_print("\tNET_NFC_NPP_SERVER_CONNECTED(%d)\n", state); - } -} - -static void set_activated_cb(bool state, - void *user_data) -{ - g_print("Activated state %d\n", state); -} - -static void set_active_completed_cb(net_nfc_error_e result, 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) -{ - g_print("GetServerState Completed %d\n", result); - - print_server_state(state); - - run_next_callback(user_data); -} - -void net_nfc_test_manager_set_active(gpointer 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); -} - -void net_nfc_test_manager_get_server_state(gpointer data, gpointer user_data) -{ - net_nfc_client_manager_get_server_state(get_server_state_completed_cb, - user_data); -} - -void net_nfc_test_manager_set_active_sync(gpointer data, gpointer user_data) -{ - gint i; - - i = net_nfc_client_manager_set_active_sync(1); - - g_print("Return %d\n", i); - - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - - callback(); - } -} - -void net_nfc_test_manager_get_server_state_sync(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - guint state = 0; - - result = net_nfc_client_manager_get_server_state_sync(&state); - - g_print("GetServerState: %d\n", result); - - print_server_state(state); - - run_next_callback(user_data); -} diff --git a/tests/net_nfc_test_manager.h b/tests/net_nfc_test_manager.h deleted file mode 100644 index 9b989f9..0000000 --- a/tests/net_nfc_test_manager.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -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__ diff --git a/tests/net_nfc_test_ndef.c b/tests/net_nfc_test_ndef.c deleted file mode 100644 index d1c1291..0000000 --- a/tests/net_nfc_test_ndef.c +++ /dev/null @@ -1,574 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_client_ndef.h" - -#include "net_nfc_test_tag.h" -#include "net_nfc_test_ndef.h" -#include "net_nfc_test_util.h" -#include "net_nfc_ndef_message.h" -#include "net_nfc_target_info.h" -#include "net_nfc_ndef_record.h" -#include "net_nfc_test_util.h" - -static gchar *ndef_str = NULL; -static gint ndef_count = 0; - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - - callback(); - } -} - -static void set_string(const gchar *str) -{ - gint count = 0; - - if (str == NULL) - return; - - sscanf(str, "Count: %d", &count); - - if (count == 0) - ndef_str = g_strdup(str); - else - { - gchar *tmp; - gchar *pos; - - pos = (gchar *)str; - tmp = g_strdup_printf("Count: %d", count); - if (strncmp(pos, tmp, strlen(tmp)) == 0) - { - if (*pos == ' ') - pos++; - - ndef_str = g_strdup(pos + strlen(tmp)); - } - - g_free(tmp); - } - - ndef_count = count; -} - -static void print_record_well_known_type(ndef_record_s *record) -{ - gchar *uri = NULL; - gchar *lang = NULL; - gchar *text = NULL; - - net_nfc_encode_type_e enc; - - net_nfc_create_uri_string_from_uri_record(record, &uri); - if (uri) - { - g_print("URI: %s\n", uri); - g_free(uri); - } - - net_nfc_create_text_string_from_text_record(record, &text); - if(text) - { - g_print("Text:\n%s\n", text); - set_string(text); - g_free(text); - - } - - net_nfc_get_languange_code_string_from_text_record(record, &lang); - if(lang) - { - g_print("Language: %s\n", lang); - g_free(lang); - } - - 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"); - } -} - -static void print_record(ndef_record_s *record) -{ - guint8 flag; - gchar *str = NULL; - - gchar *tnf_str[] = { - "Empty", - "Well-known type", - "Media-type", - "Absolute URI", - "External type", - "Unknown", - "Unchanged" - }; - - net_nfc_record_tnf_e tnf; - - data_s *type = NULL; - data_s *id = NULL; - data_s *payload = NULL; - - net_nfc_get_record_flags(record, &flag); - net_nfc_get_record_tnf(record, &tnf); - - g_print("MB: %d ME: %d CF: %d SR: %d IL: %d TNF: %s\n", - net_nfc_get_record_mb(flag), - net_nfc_get_record_me(flag), - net_nfc_get_record_cf(flag), - net_nfc_get_record_sr(flag), - net_nfc_get_record_il(flag), - tnf_str[tnf]); - - if (net_nfc_get_record_type(record, &type) == NET_NFC_OK) - { - str = g_strndup((gchar *)net_nfc_get_data_buffer(type), - net_nfc_get_data_length(type)); - g_print("Type : %s\n", str); - g_free(str); - } - - net_nfc_get_record_id(record, &id); - - str = g_strndup((gchar *)net_nfc_get_data_buffer(id), - net_nfc_get_data_length(id)); - g_print("ID : %s\n", str); - g_free(str); - - if (net_nfc_get_record_payload(record, &payload) == NET_NFC_OK) - { - print_received_data(payload); - } - - 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; - } -} - -static void print_ndef_message(ndef_message_s *message) -{ - gint count = 0; - gint i; - - if (message == NULL) - { - g_print("Empty ndef message\n"); - return; - } - - if (net_nfc_get_ndef_message_record_count(message, - &count) != NET_NFC_OK) - { - g_print("can not get count of record\n"); - return; - } - - for (i = 0; i < count; i++) - { - ndef_record_s *record = NULL; - - g_print("Record count : %d\n", i+1); - - if (net_nfc_get_record_by_index(message, i, &record) != NET_NFC_OK) - { - g_print("can not get record from index %d\n", i); - continue; - } - - print_record(record); - } - - g_print("\n"); -} - -static net_nfc_target_handle_s* ndef_get_handle(void) -{ - net_nfc_target_info_s *info; - net_nfc_target_handle_s *handle; - - bool is_ndef = false; - - info = net_nfc_test_tag_get_target_info(); - if (info == NULL) - { - g_print("net_nfc_target_info_s *is NULL\n"); - return NULL; - } - - net_nfc_get_tag_ndef_support(info, &is_ndef); - - if (is_ndef == false) - { - g_print("Tag does not support NDEF\n"); - return NULL; - } - - net_nfc_get_tag_handle(info, &handle); - - return handle; -} - -static ndef_message_s *create_ndef_message_text(const gchar *str, - const gchar *lang, - net_nfc_encode_type_e encode) -{ - ndef_record_s *record = NULL; - ndef_message_s *message = NULL; - - if (net_nfc_create_ndef_message(&message) != NET_NFC_OK) - { - g_printerr("Can not create ndef message\n"); - return NULL; - } - - if (net_nfc_create_text_type_record(&record, - str, - lang, - encode) != NET_NFC_OK) - { - g_printerr("Can not create text record(%s, %d): %s\n", - lang, encode, str); - - net_nfc_free_ndef_message(message); - return NULL; - } - - if (net_nfc_append_record_to_ndef_message(message, - record) != NET_NFC_OK) - { - g_printerr("Can not append record to message\n"); - net_nfc_free_ndef_message(message); - } - - return message; -} - -static gchar *get_write_string(void) -{ - gchar *str = NULL; - - ndef_count++; - - if (ndef_str == NULL) - str = g_strdup_printf("Count: %d", ndef_count); - else - str = g_strdup_printf("Count: %d %s", ndef_count, ndef_str); - - return str; -} - -static void ndef_read_cb(net_nfc_error_e result, ndef_message_s *message, - void *user_data) -{ - g_print("Read NDEF Completed %d\n", result); - - print_ndef_message(message); - - run_next_callback(user_data); -} - -static void ndef_write_cb(net_nfc_error_e result, void *user_data) -{ - g_print("Write NDEF Completed %d\n", result); - - run_next_callback(user_data); -} - - -static void ndef_make_read_only_cb(net_nfc_error_e result, void *user_data) -{ - g_print("Make Read only Completed %d\n", result); - - run_next_callback(user_data); -} - -static void ndef_format_cb(net_nfc_error_e result, void *user_data) - -{ - g_print("NDEF Format Completed: %d\n", result); - - run_next_callback(user_data); -} - - - -void net_nfc_test_ndef_read(gpointer data, gpointer user_data) -{ - net_nfc_target_handle_s *handle; - - handle = ndef_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - - return; - } - - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - - net_nfc_client_ndef_read(handle, ndef_read_cb, user_data); -} - -void net_nfc_test_ndef_write(gpointer data, gpointer user_data) -{ - net_nfc_target_handle_s *handle; - ndef_message_s *message; - - gchar *str = NULL; - - handle = ndef_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - return; - } - - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - - str = get_write_string(); - if(str == NULL) - { - g_printerr("Can not get write string\n"); - - run_next_callback(user_data); - return; - } - - message = create_ndef_message_text(str, "en-US", NET_NFC_ENCODE_UTF_8); - - g_free(str); - - if (message == NULL) - { - g_printerr("message is NULL\n"); - - run_next_callback(user_data); - return; - } - - net_nfc_client_ndef_write(handle, message, ndef_write_cb, user_data); - -} - -void net_nfc_test_ndef_make_read_only(gpointer data, gpointer user_data) -{ - net_nfc_target_handle_s *handle; - - handle = ndef_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - return; - } - - 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); -} - -void net_nfc_test_ndef_format(gpointer data, gpointer user_data) -{ - net_nfc_target_handle_s *handle; - data_s *key; - guint8 format_data[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - - handle = ndef_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - return; - } - - net_nfc_create_data(&key, format_data, 6); - - net_nfc_client_ndef_format(handle, key, ndef_format_cb, user_data); - - net_nfc_free_data(key); - - return; -} - -void net_nfc_test_ndef_read_sync(gpointer data, gpointer user_data) -{ - net_nfc_target_handle_s *handle; - ndef_message_s *message = NULL; - net_nfc_error_e result; - - handle = ndef_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - return; - } - - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - - result = net_nfc_client_ndef_read_sync(handle, - &message); - - g_print("Read Ndef: %d\n", result); - - print_ndef_message(message); - - net_nfc_free_ndef_message(message); - - run_next_callback(user_data); -} - -void net_nfc_test_ndef_write_sync(gpointer data, gpointer user_data) -{ - gchar *str = NULL; - - net_nfc_target_handle_s *handle; - ndef_message_s *message; - net_nfc_error_e result; - - handle = ndef_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - return; - } - - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - - str = get_write_string(); - if(str == NULL) - { - g_printerr("Can not get write string\n"); - - run_next_callback(user_data); - return; - } - - message = create_ndef_message_text(str, "en-US", NET_NFC_ENCODE_UTF_8); - - g_free(str); - - if (message == NULL) - { - g_printerr("message is NULL\n"); - - run_next_callback(user_data); - - return; - } - - result = net_nfc_client_ndef_write_sync(handle, message); - - g_print("Write Ndef: %d\n", result); - - run_next_callback(user_data); -} - -void net_nfc_test_ndef_make_read_only_sync(gpointer data, gpointer user_data) -{ - net_nfc_target_handle_s *handle; - net_nfc_error_e result; - - handle = ndef_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - - return; - } - - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - - result = net_nfc_client_ndef_make_read_only_sync(handle); - - g_print("Make Read Only: %d\n", result); - - run_next_callback(user_data); -} - -void net_nfc_test_ndef_format_sync(gpointer data, gpointer user_data) -{ - net_nfc_target_handle_s *handle; - net_nfc_error_e result; - data_s *key; - guint8 format_data[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - - handle = ndef_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - - return; - } - - net_nfc_create_data(&key, format_data, 6); - - result = net_nfc_client_ndef_format_sync(handle, key); - - net_nfc_free_data(key); - - g_print("NDEF Format %d\n", result); - - run_next_callback(user_data); -} diff --git a/tests/net_nfc_test_ndef.h b/tests/net_nfc_test_ndef.h deleted file mode 100644 index 0a1dcac..0000000 --- a/tests/net_nfc_test_ndef.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -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__ diff --git a/tests/net_nfc_test_p2p.c b/tests/net_nfc_test_p2p.c deleted file mode 100644 index 97a098c..0000000 --- a/tests/net_nfc_test_p2p.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_client_p2p.h" -#include "net_nfc_test_p2p.h" -#include "net_nfc_test_util.h" -#include "net_nfc_target_info.h" -#include "net_nfc_typedef_internal.h" -#include "net_nfc_ndef_message.h" -#include "net_nfc_ndef_record.h" -#include "net_nfc_util_internal.h" -#include "net_nfc_typedef.h" - - -static net_nfc_target_handle_s *global_handle = NULL; - -static void run_next_callback(gpointer user_data); -static void p2p_send(net_nfc_error_e result, void *user_data); -static void p2p_device_discovered(net_nfc_target_handle_s *handle, - void *user_data); - -static void p2p_device_detached(void * user_data); -static void p2p_device_data_received(data_s *p2p_data, void *user_data); - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - callback(); - } -} - -static void p2p_send(net_nfc_error_e result, void *user_data) -{ - g_print("P2P send Completed %d\n", result); - - run_next_callback(user_data); -} - -static void p2p_device_discovered(net_nfc_target_handle_s *handle, void *user_data) -{ - g_print("Target is Discovered\n"); - global_handle = handle; - - g_print("Handle is %#x\n", GPOINTER_TO_UINT(global_handle)); - run_next_callback(user_data); -} - -static void p2p_device_detached(void * user_data) -{ - g_print("Target is detached\n"); - - run_next_callback(user_data); -} - -static void p2p_device_data_received(data_s *p2p_data, void *user_data) -{ - g_print("P2P data is received\n"); - - print_received_data(p2p_data); - - run_next_callback(user_data); -} - -void net_nfc_test_p2p_send(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - ndef_message_s *msg = NULL; - ndef_record_s *record = NULL; - data_s *rawdata = 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); - net_nfc_create_rawdata_from_ndef_message(msg, &rawdata); - - g_print("Handle is %#x\n", GPOINTER_TO_UINT(global_handle)); - - result = net_nfc_client_p2p_send(global_handle, - rawdata, - p2p_send, - user_data); - - g_print("net_nfc_client_p2p_send() Return(%d)\n", result); - - net_nfc_free_data(rawdata); -} - -void net_nfc_test_p2p_send_sync(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - ndef_message_s *msg = NULL; - ndef_record_s *record = NULL; - data_s *rawdata = 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); - net_nfc_create_rawdata_from_ndef_message(msg, &rawdata); - - result = net_nfc_client_p2p_send_sync(global_handle, rawdata); - - g_print(" P2P send sync result: %d\n", result); - - net_nfc_free_data(rawdata); - - run_next_callback(user_data); -} - -void net_nfc_test_p2p_set_device_discovered(gpointer data, gpointer user_data) -{ - g_print("Waiting for Device Discovered Singal\n"); - - net_nfc_client_p2p_set_device_discovered(p2p_device_discovered, user_data); - - g_print("Device Discovered set\n"); -} - -void net_nfc_test_p2p_set_device_detached(gpointer data, gpointer user_data) -{ - net_nfc_client_p2p_set_device_detached(p2p_device_detached, user_data); -} - -void net_nfc_test_p2p_set_data_received(gpointer data, gpointer user_data) -{ - net_nfc_client_p2p_set_data_received(p2p_device_data_received, user_data); -} - -net_nfc_target_handle_s *net_nfc_test_device_get_target_handle(void) -{ - return global_handle; -} diff --git a/tests/net_nfc_test_p2p.h b/tests/net_nfc_test_p2p.h deleted file mode 100644 index 4299aa4..0000000 --- a/tests/net_nfc_test_p2p.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 -#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_s* net_nfc_test_device_get_target_handle(void); - -#endif //__NET_NFC_TEST_P2P_H__ - diff --git a/tests/net_nfc_test_se.c b/tests/net_nfc_test_se.c deleted file mode 100644 index 9cce74f..0000000 --- a/tests/net_nfc_test_se.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -#include "net_nfc_target_info.h" -#include "net_nfc_data.h" -#include "net_nfc_client_se.h" -#include "net_nfc_test_se.h" -#include "net_nfc_typedef.h" -#include "net_nfc_typedef_internal.h" -#include "net_nfc_test_util.h" - - -static void run_next_callback(gpointer user_data); - -static void send_apdu_cb(net_nfc_error_e result, data_s *data, void *user_data); - -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_s *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_s *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_s *handle, int dev_type, - data_s *data, void *user_data); - -static void se_set_transaction_cb(data_s *aid, data_s *param, void *user_data); - -/*This handle would be intialized by open secure element callback function*/ -static net_nfc_target_handle_s *global_handle = NULL; - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - callback(); - } -} - -static void send_apdu_cb(net_nfc_error_e result, data_s *data, void *user_data) -{ - g_print(" Send apdu data completed \n"); - print_received_data(data); - run_next_callback(user_data); -} - -static void set_secure_element_cb(net_nfc_error_e result, void* user_data) -{ - g_print("Set Secure Element completed : %d\n", result); - run_next_callback(user_data); -} - -static void open_secure_element_cb(net_nfc_error_e result, - net_nfc_target_handle_s *handle, void* user_data) -{ - g_print("Open secure element completed\n"); - // assigning received handle - global_handle = handle; - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - run_next_callback(user_data); -} - -static void close_secure_element_cb(net_nfc_error_e result, void* user_data) -{ - g_print("close secure element completed %d\n", result); - run_next_callback(user_data); -} - -static void get_atr_secure_element_cb(net_nfc_error_e result, data_s *data, - void* user_data) -{ - g_print("get atr completed\n"); - print_received_data(data); - run_next_callback(user_data); -} - -static void se_set_event_cb(net_nfc_message_e event, void *user_data) -{ - g_print("Event callback set successfully\n"); - g_print(" Event received %d", event); - run_next_callback(user_data); -} - -static void se_ese_detection_cb(net_nfc_target_handle_s *handle, int dev_type, - data_s *data, void *user_data) -{ - g_print("Set ese detection callback successfully\n"); - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - g_print(" dev type %d\n", dev_type); - print_received_data(data); -} - -static void se_set_transaction_cb(data_s *aid, data_s *param, void *user_data) -{ - g_print("Set transaction callback successfully\n"); - g_print("*****displaying Aid data****\n"); - print_received_data(aid); - g_print("*****displaying param data ****\n"); - print_received_data(param); - run_next_callback(user_data); -} - -void net_nfc_test_se_send_apdu(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - data_s *apdu_data = NULL; - uint8_t apdu_cmd[4] = {0x00, 0xA4, 0x00, 0x0C}; - - 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); - g_print("net_nfc_client_se_send_apdu() : %d\n", result); -} - -void net_nfc_test_se_send_apdu_sync(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - data_s *apdu_data = NULL; - uint8_t apdu_cmd[4] = {0x00, 0xA4, 0x00, 0x0C}; - data_s *response = NULL; - - net_nfc_create_data(&apdu_data, apdu_cmd, 4); - result = net_nfc_client_se_send_apdu_sync(global_handle, apdu_data, &response); - - g_print(" Send apdu data sync completed %d\n", result); - print_received_data(response); - run_next_callback(user_data); -} - -void net_nfc_test_se_set_secure_element_type(gpointer 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); - g_print("net_nfc_client_se_set_secure_element_type() : %d\n", result); -} - -void net_nfc_test_se_set_secure_element_type_sync(gpointer 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_sync(se_type); - g_print(" Set Secure element type completed %d\n", result); - run_next_callback(user_data); -} - -void net_nfc_test_se_open_internal_secure_element(gpointer 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); - g_print("net_nfc_client_se_open_internal_secure_element() : %d\n", result); -} - -void net_nfc_test_se_open_internal_secure_element_sync(gpointer 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); - - g_print("Handle is %#x\n", GPOINTER_TO_UINT(global_handle)); - g_print("open secure element completed %d\n", result); - run_next_callback(user_data); -} - -void net_nfc_test_se_close_internal_secure_element(gpointer 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); - g_print("net_nfc_client_se_close_internal_secure_element() : %d\n", result); -} - -void net_nfc_test_se_close_internal_secure_element_sync(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - - result = net_nfc_client_se_close_internal_secure_element_sync(global_handle); - g_print("close secure element completed %d\n", result); - run_next_callback(user_data); -} - -void net_nfc_test_se_get_atr(gpointer 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); - g_print("net_nfc_client_se_get_atr() : %d\n", result); -} - -void net_nfc_test_se_get_atr_sync(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - data_s *attr_data = NULL; - - result = net_nfc_client_se_get_atr_sync(global_handle, &attr_data); - - g_print("Get atr data sync completed %d\n", result); - print_received_data(attr_data); - run_next_callback(user_data); -} - -void net_nfc_test_se_set_event_cb(gpointer data, gpointer user_data) -{ - net_nfc_client_se_set_event_cb(se_set_event_cb, user_data); -} - -void net_nfc_test_se_unset_event_cb(gpointer 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) -{ - net_nfc_client_se_set_ese_detection_cb(se_ese_detection_cb, user_data); -} - -void net_nfc_test_se_unset_ese_detection_cb(gpointer 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) -{ - net_nfc_client_se_set_transaction_event_cb(NET_NFC_SE_TYPE_UICC, se_set_transaction_cb, - user_data); -} - -void net_nfc_test_se_unset_transaction_event_cb(gpointer data, - gpointer user_data) -{ - net_nfc_client_se_unset_transaction_event_cb(NET_NFC_SE_TYPE_UICC); - g_print("Transaction unset callback successfully\n"); -} diff --git a/tests/net_nfc_test_se.h b/tests/net_nfc_test_se.h deleted file mode 100644 index 66681f5..0000000 --- a/tests/net_nfc_test_se.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - - -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 diff --git a/tests/net_nfc_test_snep.c b/tests/net_nfc_test_snep.c deleted file mode 100644 index a4721eb..0000000 --- a/tests/net_nfc_test_snep.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include"net_nfc_test_snep.h" -#include"net_nfc_typedef.h" -#include"net_nfc_target_info.h" -#include"net_nfc_client_snep.h" -#include "net_nfc_util_ndef_message.h" -#include "net_nfc_ndef_message.h" -#include "net_nfc_client_tag.h" -#include "net_nfc_ndef_record.h" -#include "net_nfc_client_p2p.h" - -#define TEST_SAN "urn:nfc:sn:testsnep" -#define TEST_SAP 30 - -static net_nfc_target_info_s *target_info = NULL; -static net_nfc_snep_handle_h snep_handle = NULL; -static net_nfc_target_handle_s *target_handle = NULL; - -static void run_next_callback(gpointer user_data); - -static void snep_tag_discovered_cb(net_nfc_target_info_s *info, - void *user_data); - -static void snep_p2p_device_discovered_cb(net_nfc_target_handle_s *handle, - 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_s *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_s *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_s *msg, - void *user_data); - - -/******************************Callbacks*********************************************/ - - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - callback(); - } -} - -static void snep_tag_detached_cb(void *user_data) -{ - g_print("TagDetached\n"); -} - -static void snep_tag_discovered_cb(net_nfc_target_info_s *info, void *user_data) -{ - g_print("TagDiscovered\n"); - - net_nfc_duplicate_target_info(info, &target_info); - target_handle = target_info->handle; - - run_next_callback(user_data); -} - -static void snep_p2p_device_discovered_cb(net_nfc_target_handle_s *handle, - void *user_data) -{ - g_print("Target is Discovered\n"); - target_handle = handle; - - g_print("Handle is %#x\n", GPOINTER_TO_UINT(target_handle)); - run_next_callback(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_s *msg, - void *user_data) -{ - - snep_handle = target; - - g_print("snep_start_server_cb Completed %d\n", event); - g_print("snep_start_server_cb Completed %d\n", result); - - net_nfc_util_print_ndef_message (msg); - - run_next_callback(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_s *msg, - void *user_data) -{ - - g_print("snep_start_client_cb Completed %d\n", event); - g_print("snep_send_request_cb Completed %d\n", result); - - run_next_callback(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_s *msg, - void *user_data) -{ - - g_print("snep_send_request_cb Completed %d\n", event); - g_print("snep_start_server_cb Completed %d\n", result); - - net_nfc_util_print_ndef_message (msg); - - run_next_callback(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_s *msg, - void *user_data) -{ - net_nfc_llcp_state_t state = event; - - g_print("snep_register_server_cb Completed %d\n", state); - g_print("snep_register_server_cb Completed %d\n", result); - - net_nfc_util_print_ndef_message (msg); - - run_next_callback(user_data); -} - -#if 0 -static void snep_unregister_server_cb(net_nfc_snep_handle_h target, - net_nfc_snep_type_t event, - net_nfc_error_e result, - ndef_message_s *msg, - void *user_data) -{ - - 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); - - run_next_callback(user_data); -} -#endif - -/******************************API Calls*********************************************/ - -void net_nfc_test_snep_set_tag_discovered(gpointer data, gpointer user_data) -{ - g_print("Waiting for TagDiscovered Singal\n"); - - net_nfc_client_tag_unset_tag_detached(); - net_nfc_client_tag_set_tag_detached(snep_tag_detached_cb, NULL); - - net_nfc_client_tag_unset_tag_discovered(); - net_nfc_client_tag_set_tag_discovered(snep_tag_discovered_cb, user_data); -} - -void net_nfc_test_snep_set_p2p_device_discovered(gpointer data, - gpointer user_data) -{ - g_print("Waiting for Device Discovered signal\n"); - net_nfc_client_p2p_set_device_discovered(snep_p2p_device_discovered_cb, user_data); - g_print("Device Discovered\n"); -} - -void net_nfc_test_snep_start_server(gpointer data, gpointer user_data) -{ - net_nfc_error_e result= NET_NFC_OK; - - result = net_nfc_client_snep_start_server(target_handle, - TEST_SAN, - TEST_SAP, - snep_start_server_cb, - user_data); - - g_print(" net_nfc_test_snep_start_server result: %d\n", result); -} - -void net_nfc_test_snep_server(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result= NET_NFC_OK; - - result = net_nfc_client_snep_register_server( - TEST_SAN, - TEST_SAP, - snep_register_server_cb, - user_data); - - g_print(" net_nfc_test_snep_register_server result: %d\n", result); - - result = net_nfc_client_snep_start_server(target_handle, - TEST_SAN, - TEST_SAP, - snep_start_server_cb, - user_data); - - g_print(" net_nfc_test_snep_start_server result: %d\n", result); -} - - -void net_nfc_test_snep_start_server_sync(gpointer data, gpointer user_data) -{ -#if 0 - net_nfc_error_e result; - guint out_result; - ndef_message_s *msg=NULL; - - result = net_nfc_client_snep_start_server_sync(target_info->handle, - "urn:nfc:xsn:samsung.com:testllcp", - 16, - &out_result, - msg); - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_snep_start_server failed: %d\n", result); - run_next_callback(user_data); - return; - } - - net_nfc_util_print_ndef_message (msg); - run_next_callback(user_data); -#endif -} - - -void net_nfc_test_snep_start_client(gpointer data, gpointer user_data) -{ - net_nfc_error_e result; - - result = net_nfc_client_snep_start_client(target_handle, - TEST_SAN, - TEST_SAP, - snep_start_client_cb, - user_data); - - g_print(" net_nfc_test_snep_start_client result: %d\n", result); -} - -void net_nfc_test_snep_send_client_request(gpointer data, gpointer user_data) -{ - net_nfc_error_e result= NET_NFC_OK; - net_nfc_error_e error = NET_NFC_OK; - ndef_message_s *msg = NULL; - ndef_record_s *record = NULL; - - if( (error = net_nfc_create_uri_type_record(&record, - "http://www.samsung.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) - { - result = net_nfc_client_snep_send_client_request( - target_handle, - NET_NFC_SNEP_GET, - msg, - snep_send_request_cb, - user_data); - } - } - } - - if(result != NET_NFC_OK) - { - g_print(" net_nfc_test_snep_send_client_request failed: %d\n", result); - return; - } -} - -void net_nfc_test_snep_register_server(gpointer data, gpointer user_data) -{ - net_nfc_error_e result= NET_NFC_OK; - - result = net_nfc_client_snep_register_server( - TEST_SAN, - TEST_SAP, - snep_register_server_cb, - user_data); - - g_print(" net_nfc_test_snep_register_server result: %d\n", result); - - run_next_callback(user_data); -} - -void net_nfc_test_snep_unregister_server(gpointer data, gpointer user_data) -{ - net_nfc_error_e result= NET_NFC_OK; - - result = net_nfc_client_snep_unregister_server( - TEST_SAN, - TEST_SAP); - - g_print(" net_nfc_test_snep_unregister_server result: %d\n", result); -} - -void net_nfc_test_snep_register_unregister_server(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result= NET_NFC_OK; - - result = net_nfc_client_snep_register_server( - TEST_SAN, - TEST_SAP, - snep_register_server_cb, - user_data); - - g_print(" net_nfc_test_snep_register_server result: %d\n", result); - - result = net_nfc_client_snep_unregister_server( - TEST_SAN, - TEST_SAP); - - g_print(" net_nfc_test_snep_unregister_server result: %d\n", result); -} - - -void net_nfc_test_snep_stop_service_sync(gpointer data, gpointer user_data) -{ - net_nfc_error_e result= NET_NFC_OK; - - snep_handle = target_handle; - - result = net_nfc_client_snep_stop_service_sync( - target_handle, - snep_handle); - - g_print(" net_nfc_test_snep_register_server result: %d\n", result); -} diff --git a/tests/net_nfc_test_snep.h b/tests/net_nfc_test_snep.h deleted file mode 100644 index 8350f9d..0000000 --- a/tests/net_nfc_test_snep.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - - -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_server(gpointer data, - gpointer user_data); - -void net_nfc_test_snep_set_p2p_device_discovered(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_send_client_request(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_register_unregister_server(gpointer data, - gpointer user_data); - -void net_nfc_test_snep_stop_service_sync(gpointer data, - gpointer user_data); -#endif - diff --git a/tests/net_nfc_test_sys_handler.c b/tests/net_nfc_test_sys_handler.c deleted file mode 100644 index 8aaa989..0000000 --- a/tests/net_nfc_test_sys_handler.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "net_nfc_test_sys_handler.h" -#include "net_nfc_typedef_internal.h" -#include "net_nfc_client_system_handler.h" -#include "net_nfc_target_info.h" - - -/*************************** utility Calls ******************************/ - -static void run_next_callback(gpointer user_data); - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - callback(); - } -} - -static void sys_handler_cb(net_nfc_error_e result, - void *user_data) -{ - g_print("sys_handler_cb Set popup state completed %d\n", result); - - run_next_callback(user_data); -} - -/********************** Function Calls ******************************/ -void net_nfc_test_sys_handler_set_launch_popup_state(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - int enable = 1; - - result = net_nfc_client_sys_handler_set_state(enable,sys_handler_cb,user_data); - - if(result != NET_NFC_OK) - { - g_print("System handler set launch popup state failed: %d\n", result); - return; - } - - g_print("System handler set launch popup state success: %d\n", result); -} - - -void net_nfc_test_sys_handler_set_launch_popup_state_sync(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - - result = net_nfc_client_sys_handler_set_state_sync(NET_NFC_LAUNCH_APP_SELECT); - - if(result != NET_NFC_OK) - { - g_print("System handler set launch popup state failed: %d\n", result); - return; - } - else - { - g_print("System handler set launch popup state success: %d\n", result); - } - - run_next_callback(user_data); -} - -void net_nfc_test_sys_handler_set_launch_popup_state_force(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - int enable = 1; - - result = net_nfc_client_sys_handler_set_state_force(enable,sys_handler_cb,user_data); - - if(result != NET_NFC_OK) - { - g_print("net_nfc_test_sys_handler_set_launch_popup_state_force failed: %d\n", result); - return; - } - - g_print("net_nfc_test_sys_handler_set_launch_popup_state_force success: %d\n", result); -} - - -void net_nfc_test_sys_handler_set_launch_popup_state_force_sync(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - - result = net_nfc_client_sys_handler_set_state_force_sync(NET_NFC_LAUNCH_APP_SELECT); - - if(result != NET_NFC_OK) - { - g_print("System handler set launch popup state failed: %d\n", result); - return; - } - else - { - g_print("System handler set launch popup state success: %d\n", result); - } - - run_next_callback(user_data); -} - - -void net_nfc_test_sys_handler_get_launch_popup_state(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - int state = 0; - - result = net_nfc_client_sys_handler_get_launch_popup_state(&state); - - if(result != NET_NFC_OK) - { - g_print("System handler get launch popup state failed: %d\n", result); - } - else - { - g_print("System handler get launch popup state success: %d\n", result); - g_print("System handler get launch popup state value: %d\n", state); - } - - run_next_callback(user_data); -} diff --git a/tests/net_nfc_test_sys_handler.h b/tests/net_nfc_test_sys_handler.h deleted file mode 100644 index 89a0dae..0000000 --- a/tests/net_nfc_test_sys_handler.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -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); - -void net_nfc_test_sys_handler_set_launch_popup_state_sync(gpointer data, - gpointer user_data); - -void net_nfc_test_sys_handler_set_launch_popup_state_force(gpointer data, - gpointer user_data); - -void net_nfc_test_sys_handler_set_launch_popup_state_force_sync(gpointer data, - gpointer user_data); - -#endif//__NET_NFC_TEST_SYS_HANDLER_H__ diff --git a/tests/net_nfc_test_tag.c b/tests/net_nfc_test_tag.c deleted file mode 100644 index 1df0286..0000000 --- a/tests/net_nfc_test_tag.c +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "net_nfc_typedef_internal.h" -#include "net_nfc_client_tag.h" -#include "net_nfc_test_tag.h" - -static net_nfc_target_info_s *global_info = NULL; - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - - callback(); - } -} -#if 0 -static gchar *tag_type_to_string(net_nfc_target_type_e dev_type) -{ - 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; - } - return "Invalid Target"; -} -#endif -static void print_is_tag_connected(net_nfc_target_type_e dev_type) -{ - if (global_info) - { - net_nfc_target_type_e type; - - net_nfc_get_tag_type(global_info, &type); - - if(dev_type == type) - g_print("DevType is same as Discovered tag\n"); - } -} - -static void print_get_current_target_handle(net_nfc_target_handle_s *handle) -{ - net_nfc_target_handle_s *global_handle; - guint global_handle_id; - guint handle_id; - - net_nfc_get_tag_handle(global_info, &global_handle); - - global_handle_id = GPOINTER_TO_UINT(global_handle); - handle_id = GPOINTER_TO_UINT(handle); - - g_print("Tag handle %x, Current Tag handle %x\n", - global_handle_id, - handle_id); - if (global_handle_id == handle_id) - g_print("Current Tag is matched discovered Tag\n"); -} - -static void print_get_current_tag_info(net_nfc_target_info_s *info) -{ - net_nfc_target_handle_s *handle; - - if (global_info == NULL) - { - g_print("Discovered tag info does not exist\n"); - return; - } - - if (info == NULL) - { - g_print("Current tag info does not exist\n"); - return; - } - - net_nfc_get_tag_handle(info, &handle); - print_get_current_target_handle(handle); - - return; -} - -static void tag_detached(void *user_data) -{ - g_print("TagDetached\n"); -} -#if 0 -static void is_tag_connected_completed(net_nfc_error_e result, - 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); - - if (result == NET_NFC_OK) - print_is_tag_connected(dev_type); - else if (result == NET_NFC_NOT_CONNECTED) - g_print("NET_NFC_NOT_CONNECTED\n"); - - run_next_callback(user_data); -} - -static void get_current_tag_info_completed(net_nfc_error_e result, - net_nfc_target_info_s *info, void *user_data) -{ - g_print("GetCurrentTagInfo Completed %d\n", result); - - if (result == NET_NFC_OK) - print_get_current_tag_info(info); - - run_next_callback(user_data); -} - -static void get_current_target_handle_completed(net_nfc_error_e result, - net_nfc_target_handle_s *handle, void *user_data) -{ - g_print("GetCurrentTargetHandle Completed %d\n", result); - - if (result == NET_NFC_OK) - print_get_current_target_handle(handle); - - run_next_callback(user_data); -} -#endif - - -static void tag_discovered(net_nfc_target_info_s *info, void *user_data) -{ - g_print("TagDiscovered\n"); - - net_nfc_duplicate_target_info(info, &global_info); - - run_next_callback(user_data); -} - - -#if 0 -void net_nfc_test_tag_is_tag_connected(gpointer data, gpointer user_data) -{ - net_nfc_client_tag_is_tag_connected(is_tag_connected_completed, - user_data); -} - -void net_nfc_test_tag_get_current_tag_info(gpointer data, gpointer user_data) -{ - net_nfc_client_tag_get_current_tag_info(get_current_tag_info_completed, - user_data); -} - -void net_nfc_test_tag_get_current_target_handle(gpointer data, - gpointer user_data) -{ - net_nfc_client_tag_get_current_target_handle( - get_current_target_handle_completed, - user_data); -} -#endif -void net_nfc_test_tag_is_tag_connected_sync(gpointer data, gpointer user_data) -{ - net_nfc_error_e result; - net_nfc_target_type_e dev_type; - - result = net_nfc_client_tag_is_tag_connected_sync(&dev_type); - - if (result == NET_NFC_OK) - print_is_tag_connected(dev_type); - else if (result == NET_NFC_NOT_CONNECTED) - g_print("NET_NFC_NOT_CONNECTED\n"); - - run_next_callback(user_data); -} - -void net_nfc_test_tag_get_current_tag_info_sync(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - net_nfc_target_info_s *info; - - result = net_nfc_client_tag_get_current_tag_info_sync(&info); - - if (result == NET_NFC_OK) - print_get_current_tag_info(info); - - run_next_callback(user_data); -} - -void net_nfc_test_tag_get_current_target_handle_sync(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result; - net_nfc_target_handle_s *handle; - - result = net_nfc_client_tag_get_current_target_handle_sync(&handle); - - if (result == NET_NFC_OK) - print_get_current_target_handle(handle); - - run_next_callback(user_data); -} - -void net_nfc_test_tag_set_tag_discovered(gpointer data, gpointer user_data) -{ - g_print("Waiting for TagDiscovered Signal\n"); - - net_nfc_client_tag_unset_tag_detached(); - - net_nfc_client_tag_set_tag_detached(tag_detached, NULL); - - net_nfc_client_tag_unset_tag_discovered(); - - net_nfc_client_tag_set_tag_discovered(tag_discovered, user_data); -} - -net_nfc_target_info_s* net_nfc_test_tag_get_target_info(void) -{ - return global_info; -} - -void net_nfc_test_tag_set_tag_detached(gpointer data, gpointer user_data) -{ - g_print("Waiting for TagDetached Singal\n"); - - net_nfc_client_tag_set_tag_detached(tag_detached, NULL); -} - -void net_nfc_test_tag_set_filter(gpointer data, gpointer user_data) -{ - net_nfc_event_filter_e filter = NET_NFC_ALL_ENABLE; - - net_nfc_client_tag_set_filter(filter); -} - -void net_nfc_test_tag_get_filter(gpointer data, gpointer user_data) -{ - net_nfc_event_filter_e filter = NET_NFC_ALL_DISABLE; - - filter = net_nfc_client_tag_get_filter(); - - g_print(" NFC tag filter = %d", filter); -} diff --git a/tests/net_nfc_test_tag.h b/tests/net_nfc_test_tag.h deleted file mode 100644 index 61bbc4d..0000000 --- a/tests/net_nfc_test_tag.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - -#include "net_nfc_target_info.h" -#if 0 -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); -#endif -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_s* 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__ diff --git a/tests/net_nfc_test_tag_felica.c b/tests/net_nfc_test_tag_felica.c deleted file mode 100755 index 8a2d352..0000000 --- a/tests/net_nfc_test_tag_felica.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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" -#include "net_nfc_test_tag.h" -#include "net_nfc_target_info.h" -#include "net_nfc_test_util.h" -#include "net_nfc_client_tag_felica.h" - - -static net_nfc_target_handle_s* get_handle() -{ - net_nfc_target_info_s *info = NULL; - net_nfc_target_handle_s *handle = NULL; - - info = net_nfc_test_tag_get_target_info(); - - net_nfc_get_tag_handle(info, &handle); - - return handle; -} - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - - callback(); - } -} - -static void felica_cb(net_nfc_error_e result, data_s *resp_data, void *user_data) -{ - g_print("felica_cb Completed %d\n", result); - - print_received_data(resp_data); - - run_next_callback(user_data); -} - -void net_nfc_test_felica_poll(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - net_nfc_felica_poll_request_code_e req_code = 0x00; - uint8_t time_slot = 2; - - handle = get_handle(); - if (handle == NULL) - return ; - - result = net_nfc_client_felica_poll(handle, req_code, time_slot, felica_cb, user_data); - - g_print("net_nfc_client_felica_poll() : %d\n", result); -} - -void net_nfc_test_felica_request_service(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - uint8_t number_of_area_service = 4; - uint16_t area_service_list[10] = { 0,}; - uint8_t number_of_services = 5; - - handle = get_handle(); - if (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); - g_print("net_nfc_client_felica_request_service() : %d\n", result); -} - -void net_nfc_test_felica_request_response(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - - handle = get_handle(); - if (handle == NULL) - return ; - - result = net_nfc_client_felica_request_response(handle, felica_cb, user_data); - g_print("net_nfc_client_felica_request_response() : %d\n", result); -} - -void net_nfc_test_felica_read_without_encryption(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - uint8_t number_of_services = 10; - uint16_t service_list[10] = {0,}; - uint8_t number_of_blocks = 1; - uint8_t block_list[3] = {0,}; - - handle = get_handle(); - if (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); - g_print("net_nfc_client_felica_read_without_encryption() : %d\n", result); -} - -void net_nfc_test_felica_write_without_encryption(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - uint8_t number_of_services = 10; - uint16_t service_list[10] = {0,}; - uint8_t number_of_blocks = 1; - uint8_t block_list[3] = {0,}; - data_s *data_to_write = NULL; - - handle = get_handle(); - if (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); - g_print("net_nfc_client_felica_write_without_encryption() : %d\n", result); -} - -void net_nfc_test_felica_request_system_code(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - - handle = get_handle(); - if (handle == NULL) - return ; - - result = net_nfc_client_felica_request_system_code(handle, felica_cb, user_data); - g_print("net_nfc_client_felica_request_system_code() : %d\n", result); -} diff --git a/tests/net_nfc_test_tag_felica.h b/tests/net_nfc_test_tag_felica.h deleted file mode 100644 index 67cee4d..0000000 --- a/tests/net_nfc_test_tag_felica.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - - -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 diff --git a/tests/net_nfc_test_tag_mifare.c b/tests/net_nfc_test_tag_mifare.c deleted file mode 100644 index 69d1da7..0000000 --- a/tests/net_nfc_test_tag_mifare.c +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_client_tag_mifare.h" -#include "net_nfc_test_tag_mifare.h" -#include "net_nfc_target_info.h" -#include "net_nfc_typedef_internal.h" -#include "net_nfc_test_tag.h" -#include "net_nfc_test_util.h" - - -static net_nfc_target_handle_s* tag_get_handle(void); - -static void mifare_read_cb(net_nfc_error_e result, data_s *resp_data, void *user_data); - -static void mifare_write_block_cb(net_nfc_error_e result, void* user_data); - -static void mifare_write_page_cb(net_nfc_error_e result, void* user_data); - -static void mifare_write_mifare_incr_cb(net_nfc_error_e result, void* user_data); - -static void mifare_write_mifare_decr_cb(net_nfc_error_e result, void* user_data); - -static void mifare_write_mifare_transfer_cb(net_nfc_error_e result, void* user_data); - -static void mifare_write_mifare_restore_cb(net_nfc_error_e result, void* user_data); - -static void mifare_write_auth_keyA_cb(net_nfc_error_e result, void* user_data); - -static void mifare_write_auth_keyB_cb(net_nfc_error_e result, void* user_data); - - -static net_nfc_target_handle_s* tag_get_handle(void) -{ - net_nfc_target_info_s *info = NULL; - net_nfc_target_handle_s *handle = NULL; - - info = net_nfc_test_tag_get_target_info(); - - net_nfc_get_tag_handle(info, &handle); - - return handle; -} - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - callback(); - } -} - -static void mifare_read_cb(net_nfc_error_e result, - data_s *resp_data, - void *user_data) -{ - g_print("mifare_read_cb Completed %d\n", result); - print_received_data(resp_data); - - run_next_callback(user_data); -} - -static void mifare_write_block_cb(net_nfc_error_e result, void* user_data) -{ - g_print("mifare_write_block_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void mifare_write_page_cb(net_nfc_error_e result, void* user_data) -{ - g_print("mifare_write_page_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void mifare_write_mifare_incr_cb(net_nfc_error_e result, void* user_data) -{ - g_print("mifare_write_mifare_incr_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void mifare_write_mifare_decr_cb(net_nfc_error_e result, void* user_data) -{ - g_print("mifare_write_mifare_decr_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void mifare_write_mifare_transfer_cb(net_nfc_error_e result, void* user_data) -{ - g_print("mifare_write_mifare_transfer_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void mifare_write_mifare_restore_cb(net_nfc_error_e result, void* user_data) -{ - g_print("mifare_write_mifare_restore_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void mifare_write_auth_keyA_cb(net_nfc_error_e result, void* user_data) -{ - g_print("mifare_write_auth_keyA_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void mifare_write_auth_keyB_cb(net_nfc_error_e result, void* user_data) -{ - g_print("mifare_write_auth_keyB_cb Completed %d\n", result); - - run_next_callback(user_data); -} - - -void net_nfc_test_tag_mifare_read(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - uint8_t block_index = 0x0; - - handle = tag_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - return; - } - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - - result = net_nfc_client_mifare_read(handle, block_index, mifare_read_cb, user_data); - - g_print("net_nfc_client_mifare_read() : %d\n", result); -} - -void net_nfc_test_tag_mifare_write_block(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - data_s *write_data = NULL; - // create 4 bytes data mifare page size is 4 bytes - uint8_t buffer_data [17] = "aaaabbbbccccdddd"; - - net_nfc_create_data(&write_data, buffer_data, 16); - - uint8_t block_index = 0x04; - - handle = tag_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - return; - } - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - - result = net_nfc_client_mifare_write_block(handle, - block_index, - write_data, - mifare_write_block_cb, - user_data); - - g_print("net_nfc_client_mifare_write_block() : %d\n", result); -} - -void net_nfc_test_tag_mifare_write_page(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - data_s *write_data = NULL; - // create 4 bytes data mifare page size is 4 bytes - uint8_t buffer_data [5] = "aaaa"; - - net_nfc_create_data(&write_data, buffer_data, 4); - - uint8_t block_index = 0x04; - - handle = tag_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - return; - } - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - - result = net_nfc_client_mifare_write_page(handle, - block_index, - write_data, - mifare_write_page_cb, - user_data); - - g_print("net_nfc_client_mifare_write_page() : %d\n", result); -} - -void net_nfc_test_tag_mifare_increment(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - int value = 1; - uint8_t block_index = 0x05; - - handle = tag_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - 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); - - g_print("net_nfc_client_mifare_increment() : %d\n", result); -} - -void net_nfc_test_tag_mifare_decrement(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - int value = 1; - uint8_t block_index = 0x05; - - handle = tag_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - 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); - - g_print("net_nfc_client_mifare_decrement() : %d\n", result); -} - -void net_nfc_test_tag_mifare_transfer(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - uint8_t block_index = 0x08; - - handle = tag_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - 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); - - g_print("net_nfc_client_mifare_transfer() : %d\n", result); -} - -void net_nfc_test_tag_mifare_restore(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - uint8_t block_index = 0x08; - - handle = tag_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - return; - } - 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); - - g_print("net_nfc_client_mifare_restore() : %d\n", result); -} - -void net_nfc_test_tag_mifare_authenticate_with_keyA(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - data_s *auth_key = NULL; - uint8_t sector_index = 0x02; - - handle = tag_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - return; - } - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - - result = net_nfc_client_mifare_create_default_key(&auth_key); - 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); - - g_print("net_nfc_client_mifare_authenticate_with_keyA() : %d\n", result); -} - -void net_nfc_test_tag_mifare_authenticate_with_keyB(gpointer data, - gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - net_nfc_target_handle_s *handle = NULL; - data_s *auth_key = NULL; - uint8_t sector_index = 0x02; - - handle = tag_get_handle(); - if (handle == NULL) - { - g_printerr("Handle is NULL\n"); - - run_next_callback(user_data); - return; - } - g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle)); - - result = net_nfc_client_mifare_create_default_key(&auth_key); - 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); - - g_print("net_nfc_client_mifare_authenticate_with_keyB() : %d\n", result); -} diff --git a/tests/net_nfc_test_tag_mifare.h b/tests/net_nfc_test_tag_mifare.h deleted file mode 100644 index cdb246d..0000000 --- a/tests/net_nfc_test_tag_mifare.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - - -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 - diff --git a/tests/net_nfc_test_transceive.c b/tests/net_nfc_test_transceive.c deleted file mode 100644 index 043774c..0000000 --- a/tests/net_nfc_test_transceive.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_client_transceive.h" -#include "net_nfc_test_transceive.h" -#include "net_nfc_test_util.h" -#include "net_nfc_target_info.h" -#include "net_nfc_typedef_internal.h" -#include "net_nfc_test_tag.h" - - -static void call_transceive_data_cb(net_nfc_error_e result, - data_s *resp_data, - void *user_data); - -static void call_transceive_cb(net_nfc_error_e result, - void* user_data); - -static void run_next_callback(gpointer user_data); - - -static void run_next_callback(gpointer user_data) -{ - if (user_data) - { - GCallback callback; - - callback = (GCallback)(user_data); - callback(); - } -} - - -static void call_transceive_cb(net_nfc_error_e result, - void* user_data) -{ - g_print("call_transceive_cb Completed %d\n", result); - - run_next_callback(user_data); -} - -static void call_transceive_data_cb(net_nfc_error_e result, - data_s *resp_data, - void *user_data) -{ - g_print("call_transceive_data_cb Completed %d\n", result); - print_received_data(resp_data); - - run_next_callback(user_data); -} - -void net_nfc_test_transceive(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - data_s raw_data = {NULL,}; - net_nfc_target_info_s *info = NULL; - net_nfc_target_handle_s *handle = NULL; - - info = net_nfc_test_tag_get_target_info(); - - net_nfc_get_tag_handle(info, &handle); - - result =net_nfc_client_transceive(handle, - &raw_data, - call_transceive_cb, - user_data); - g_print("net_nfc_client_transceive() : %d\n", result); -} - -void net_nfc_test_transceive_sync(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - data_s raw_data = {NULL,}; - net_nfc_target_info_s *info = NULL; - net_nfc_target_handle_s *handle = NULL; - - info = net_nfc_test_tag_get_target_info(); - - net_nfc_get_tag_handle(info, &handle); - - result = net_nfc_client_transceive_sync(handle, &raw_data); - - g_print("Transceive Sync is completed(%d)\n", result); -} - -void net_nfc_test_transceive_data(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - data_s raw_data = {NULL,}; - net_nfc_target_info_s *info = NULL; - net_nfc_target_handle_s *handle = NULL; - - info = net_nfc_test_tag_get_target_info(); - - net_nfc_get_tag_handle(info, &handle); - - result = net_nfc_client_transceive_data(handle, - &raw_data, - call_transceive_data_cb, - user_data); - g_print("net_nfc_client_transceive_data() : %d\n", result); -} - -void net_nfc_test_transceive_data_sync(gpointer data, gpointer user_data) -{ - net_nfc_error_e result = NET_NFC_OK; - data_s raw_data = {NULL}; - data_s *response = NULL; - net_nfc_target_info_s *info = NULL; - net_nfc_target_handle_s *handle = NULL; - - info = net_nfc_test_tag_get_target_info(); - - net_nfc_get_tag_handle(info, &handle); - - result = net_nfc_client_transceive_data_sync(handle, &raw_data, &response); - g_print("net_nfc_client_transceive_data_sync() : %d\n", result); - - if (NET_NFC_OK == result) - print_received_data(response); -} diff --git a/tests/net_nfc_test_transceive.h b/tests/net_nfc_test_transceive.h deleted file mode 100644 index bcfb98f..0000000 --- a/tests/net_nfc_test_transceive.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 - - -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 - diff --git a/tests/net_nfc_test_util.c b/tests/net_nfc_test_util.c deleted file mode 100644 index c3a708b..0000000 --- a/tests/net_nfc_test_util.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_util.h" - - -void print_received_data(data_s *data) -{ - guint8 *buffer = NULL; - gint i; - gint len = 0; - - buffer = (guint8 *)net_nfc_get_data_buffer(data); - if (buffer == NULL) - { - g_print("Payload: Empty\n"); - return; - } - - len = net_nfc_get_data_length(data); - - g_print ("Payload:\n"); - - for (i = 0; i < len; i++) - { - g_print("%02x", buffer[i]); - if ((i + 1) % 16 == 0) - g_print("\n"); - else - g_print(" "); - } - - g_print("\n"); -} - diff --git a/tests/net_nfc_test_util.h b/tests/net_nfc_test_util.h deleted file mode 100644 index a439aff..0000000 --- a/tests/net_nfc_test_util.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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 -#include -#include "net_nfc_data.h" - - -void print_received_data(data_s *data); - - -#endif diff --git a/tools/bt-paring/CMakeLists.txt b/tools/bt-paring/CMakeLists.txt deleted file mode 100644 index 3eb1c6a..0000000 --- a/tools/bt-paring/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -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) diff --git a/tools/bt-paring/bt_paring.c b/tools/bt-paring/bt_paring.c deleted file mode 100644 index eb5d425..0000000 --- a/tools/bt-paring/bt_paring.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include - -#include -#include - -#include - -#include - -void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data); -void bt_test_bond_device(bluetooth_device_address_t* bt_address); -GMainLoop* main_loop = NULL; - -void initialize() -{ - if(!g_thread_supported()) - { - g_thread_init(NULL); - } - - dbus_g_thread_init(); - g_type_init(); -} - - -int main() -{ - initialize(); - - //bluetooth_enable_adapter(); - - //main_loop = g_main_loop_new(NULL, FALSE); - //g_main_loop_run(main_loop); - -#if 1 - - ndef_message_s *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_s *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_s *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_s *configuration = NULL; - net_nfc_get_carrier_configuration(carrier_info, &configuration); - - if(configuration != NULL) - { - uint8_t* buffer = net_nfc_get_data_buffer(configuration); - if(buffer != NULL) - { - printf("bt addr [%X][%X][%X][%X][%X][%X] \n", buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]); - bluetooth_device_address_t bt_address = {{buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]}}; - bt_test_bond_device(&bt_address); - } - else - printf("buffer is NULL"); - } - } - } - } - } - } - } - } - - } - -#endif - return 0; -} - -void bt_test_bond_device(bluetooth_device_address_t* bt_address) -{ - int ret_val; - - ret_val = bluetooth_register_callback(bt_event_callback, NULL); - - if (ret_val >= BLUETOOTH_ERROR_NONE) - { - printf("bluetooth_register_callback returned Success"); - } - else - { - printf("bluetooth_register_callback returned failiure [0x%04x]", ret_val); - return ; - } - - ret_val = bluetooth_check_adapter(); - - if (ret_val < BLUETOOTH_ERROR_NONE) - { - printf("bluetooth_check_adapter returned failiure [0x%04x]", ret_val); - } - else - { - printf("BT state [0x%04x]", ret_val); - } - - int error = 0; - - if((error = bluetooth_bond_device(bt_address)) < 0) - { - printf("Api failed: %d", error); - } - else - { - main_loop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(main_loop); - } - -} - -void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data) -{ - switch(event) - { - case BLUETOOTH_EVENT_ENABLED: - printf("BLUETOOTH_EVENT_ENABLED:\n"); - break; - case BLUETOOTH_EVENT_DISABLED: - printf("BLUETOOTH_EVENT_DISABLED:\n"); - break; - case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED: - printf("BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:\n"); - break; - case BLUETOOTH_EVENT_DISCOVERY_STARTED: - printf("BLUETOOTH_EVENT_DISCOVERY_STARTED:\n"); - break; - case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND: - printf("BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:\n"); - break; - case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED: - printf("BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:\n"); - break; - case BLUETOOTH_EVENT_DISCOVERY_FINISHED: - printf("BLUETOOTH_EVENT_DISCOVERY_FINISHED:\n"); - break; - case BLUETOOTH_EVENT_BONDING_FINISHED: - printf("BLUETOOTH_EVENT_BONDING_FINISHED:\n"); - - if (param->result >= BLUETOOTH_ERROR_NONE) - { - bluetooth_device_info_t *device_info = NULL; - device_info = (bluetooth_device_info_t *)param->param_data; - printf("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X] mjr[%#x] min[%#x] srv[%#x] \n", device_info->device_name.name, \ - device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \ - device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5], \ - device_info->device_class.major_class, device_info->device_class.minor_class, device_info->device_class.service_class); - } - - g_main_loop_quit (main_loop); - - break; - default: - printf("BLUETOOTH_EVENT = [%d]:\n", event); - break; - } -} diff --git a/tools/ndef-tool/CMakeLists.txt b/tools/ndef-tool/CMakeLists.txt deleted file mode 100644 index 5e5649e..0000000 --- a/tools/ndef-tool/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -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) - - diff --git a/tools/ndef-tool/ndef-tool-display.c b/tools/ndef-tool/ndef-tool-display.c deleted file mode 100644 index cecf9ca..0000000 --- a/tools/ndef-tool/ndef-tool-display.c +++ /dev/null @@ -1,943 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include - -#include "net_nfc.h" -#include "net_nfc_sign_record.h" -#include "ndef-tool.h" - -typedef struct _net_nfc_sub_field_s -{ - uint16_t length; - uint8_t value[0]; -} -__attribute__((packed)) net_nfc_sub_field_s; - -typedef struct _net_nfc_signature_record_s -{ - uint8_t version; - uint8_t sign_type : 7; - uint8_t uri_present : 1; - net_nfc_sub_field_s signature; -} -__attribute__((packed)) net_nfc_signature_record_s; - -typedef struct _net_nfc_certificate_chain_s -{ - uint8_t num_of_certs : 4; - uint8_t cert_format : 3; - uint8_t uri_present : 1; - uint8_t cert_store[0]; -} -__attribute__((packed)) net_nfc_certificate_chain_s; - -void _display_ndef_message(ndef_message_s *msg); - -static void _display_buffer(char *title, uint8_t *buffer, uint32_t length) -{ - int32_t i; - - if (0 < length) - { - 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_s *record) -{ - data_s *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_s *record) -{ - data_s *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_s *record) -{ - data_s *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_s *record) -{ - data_s *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_s *record) -{ - data_s *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_s *record) -{ - data_s *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_s *msg; - data_s *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_s *record) -{ - data_s *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_s *msg; - data_s *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_s *record) -{ - data_s *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_s *record) -{ - data_s *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_s *record) -{ - data_s *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_s *record) -{ - data_s *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_s *record) -{ - data_s *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_s *record) -{ - data_s *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_s *record) -{ - data_s *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 (0 < length) - { - 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_s *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_s *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_s *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_s *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_s *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_s *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_s *msg) -{ - uint32_t length; - int count = 0; - int32_t i = 0; - ndef_record_s *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_s *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_s *target) -{ - int count, i; - char **keys; - data_s *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_s *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_s *handle) -{ - if (handle == NULL) - return; - - fprintf(stdout, "\n************* Target discovered *************\n"); - fprintf(stdout, "Target Type : P2P Target (NFCIP1) (%d)\n", NET_NFC_NFCIP1_TARGET); - fprintf(stdout, "*********************************************\n"); -} - diff --git a/tools/ndef-tool/ndef-tool-sign.c b/tools/ndef-tool/ndef-tool-sign.c deleted file mode 100644 index b8befee..0000000 --- a/tools/ndef-tool/ndef-tool-sign.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include - -#include "net_nfc.h" -#include "net_nfc_sign_record.h" -#include "ndef-tool.h" - -bool ndef_tool_sign_message_from_file(const char *file_name, int begin_index, int end_index, char *cert_file, char *password) -{ - bool result = false; - ndef_message_s *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_s *msg = NULL; - - if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0) - { - result = (net_nfc_verify_signature_ndef_message(msg) == 0); - - net_nfc_free_ndef_message(msg); - } - - return result; -} diff --git a/tools/ndef-tool/ndef-tool-tag.c b/tools/ndef-tool/ndef-tool-tag.c deleted file mode 100644 index 417958d..0000000 --- a/tools/ndef-tool/ndef-tool-tag.c +++ /dev/null @@ -1,535 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include -#include - -#include "net_nfc.h" -#include "net_nfc_exchanger.h" -#include "ndef-tool.h" - -typedef struct _response_context_t -{ - int type; - void *user_param; -} response_context_t; - -static GMainLoop *main_loop = NULL; -static response_context_t response_context = { 0, }; - -static void _tag_read_completed_cb(ndef_message_s *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_s *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_s *handle, void *user_data) -{ - response_context_t *context = (response_context_t *)user_data; - - fprintf(stdout, "\nwriting...\n\n"); - - net_nfc_client_ndef_write(handle, (ndef_message_s*)context->user_param, user_data); -} - -static void _p2p_receive_completed_cb(data_s *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_s *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_s *handle, void *user_data) -{ - response_context_t *context = (response_context_t *)user_data; - - fprintf(stdout, "\nsending...\n\n"); - - data_s *rawdata; - - net_nfc_create_rawdata_from_ndef_message((ndef_message_s*)context->user_param, &rawdata); - /* FIXME */ - net_nfc_free_data(rawdata); -} - -static void _handover_completed_cb(net_nfc_error_e result, - data_s *data, void *user_data) -{ - // response_context_t *context = (response_context_t *)user_data; - // data_s *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_s*)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_s *handle, - void *user_data) -{ - response_context_t *context = (response_context_t *)user_data; - - if (result == NET_NFC_OK) - { - data_s *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_s *handle, void *user_data) -{ - // response_context_t *context = (response_context_t *)user_data; - // data_s *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_s *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_s *handle = NULL; - bool is_ndef = false; - - net_nfc_get_tag_handle((net_nfc_target_info_s*)data, &handle); - net_nfc_get_tag_ndef_support((net_nfc_target_info_s*)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_s*)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_s*)data, user_param); - } - else if (context->type == 2) /* handover */ - { - _handover_cb((net_nfc_target_handle_s*)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_client_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_client_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_s *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_s *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_s **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_s *data; - - net_nfc_create_data(&data, NULL, file_size); - if (data != NULL) - { - ndef_record_s *record; - data_s *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_s *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 (0 < length) - { - 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; -} diff --git a/tools/ndef-tool/ndef-tool.c b/tools/ndef-tool/ndef-tool.c deleted file mode 100644 index 8cdccfd..0000000 --- a/tools/ndef-tool/ndef-tool.c +++ /dev/null @@ -1,721 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include -#include - -#include "net_nfc.h" -#include "ndef-tool.h" - -static GMainLoop *main_loop = NULL; - -void _activation_complete_cb(net_nfc_message_e message, net_nfc_error_e result, - void *data, void *user_param, void *trans_data) -{ - switch (message) - { - case NET_NFC_MESSAGE_INIT : - if (result == NET_NFC_OK) - fprintf(stdout, "power on success\n\n"); - else - fprintf(stdout, "failed to power on (%d)\n\n", result); - - net_nfc_unset_response_callback(); - net_nfc_client_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_client_deinitialize(); - g_main_loop_quit(main_loop); - break; - - default : - break; - } -} - -int ndef_tool_read_ndef_message_from_file(const char *file_name, ndef_message_s **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_s *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_s *msg) -{ - int result = -1; - FILE *file = NULL; - data_s *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_s *record) -{ - int result = -1; - ndef_message_s *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_s* _create_record(net_nfc_record_tnf_e tnf, data_s *type, data_s *id , data_s *payload, char *encoding) -{ - ndef_record_s *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_s *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_s *type = NULL; - data_s *id = NULL; - data_s *payload = NULL; - char *file_name = NULL; - char *cert_file = NULL; - char *password = NULL; - char *encoding = NULL; - ndef_record_s *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_client_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_client_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_client_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; -} diff --git a/tools/ndef-tool/ndef-tool.h b/tools/ndef-tool/ndef-tool.h deleted file mode 100644 index 42b15c9..0000000 --- a/tools/ndef-tool/ndef-tool.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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_s **msg); -int ndef_tool_write_ndef_message_to_file(const char *file_name, ndef_message_s *msg); - -void ndef_tool_display_ndef_message_from_file(const char *file_name); -void ndef_tool_display_discovered_tag(net_nfc_target_info_s *target); -void ndef_tool_display_discovered_target(net_nfc_target_handle_s *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__ diff --git a/tools/nfc-client/CMakeLists.txt b/tools/nfc-client/CMakeLists.txt deleted file mode 100644 index ccc6bab..0000000 --- a/tools/nfc-client/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -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) - - diff --git a/tools/nfc-client/main.c b/tools/nfc-client/main.c deleted file mode 100644 index 9a8372e..0000000 --- a/tools/nfc-client/main.c +++ /dev/null @@ -1,3459 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include "nfc_api_test.h" - -#include - -/* Function definition list*/ -int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2); -int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2); -int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2); -int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2); -int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2); -int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2); -int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2); -int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2); -int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2); -int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2); -int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2); -int nfcTestStressLLCP(uint8_t testNumber,void* arg_ptr2); -int nfcTestExchanger(uint8_t testNumber,void* arg_ptr2); -int nfcConnHandover(uint8_t testNumber,void* arg_ptr2); -int nfcTestAPIException (uint8_t testNumber,void* arg_ptr); -int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr); -int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr); -int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr); -int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2); -int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2); -int nfcTestSnep(uint8_t testNumber,void* arg_ptr); - - -void print_test_result (char * str, net_nfc_test_result_e result); - -#define NET_NFC_TAG_DISCOVERED 1 -#define NET_NFC_TAG_CONNECT (1 << 1) -#define NET_NFC_TAG_CHECK_NDEF (1 << 2) -#define NET_NFC_TAG_NDEF_READ (1 << 3) -#define NET_NFC_TAG_NDEF_WRITE (1 << 4) -#define NET_NFC_TAG_NDEF_READ_BIG (1 << 5) -#define NET_NFC_TAG_NDEF_WRITE_BIG (1 << 6) -#define NET_NFC_TAG_DISCONNECT (1 << 7) -#define NET_NFC_MAX_TAG_TYPE 20 - -static nfcTestType nfcTestMatrix[] = -{ - // {"API STRESS_WRITE_READ TEST", nfcTestReadWriteMode, NET_NFC_TEST_NOT_YET}, // OK - // {"Remove tag while writing", nfcTestWriteMode, NET_NFC_TEST_NOT_YET}, //OK - // {"Remove tag while reading", nfcTestAPIBasicTest2, NET_NFC_TEST_NOT_YET}, // OK - //{"API BASIC TEST3", nfcTestAPIBasicTest3, NET_NFC_TEST_NOT_YET}, - // {"API MUTIPLE REQUEST", nfcTestAPIMultipleRequest, NET_NFC_TEST_NOT_YET}, // OK - // {"API BASIC TEST1", nfcTestAPIBasicTest1, NET_NFC_TEST_NOT_YET}, // OK - // {"Check NDEF message", nfcTestNdefParser, NET_NFC_TEST_NOT_YET}, // OK - // {"write mode", nfcTestWriteMode, NET_NFC_TEST_NOT_YET}, - // {"reader mode", nfcTestReaderMode, NET_NFC_TEST_NOT_YET}, - // {"format ndef", nfcTestFormatNdef, NET_NFC_TEST_NOT_YET}, - // {"internal_se_test", nfcTestInternalSe, NET_NFC_TEST_NOT_YET}, - // {"exchange mode", nfcTestExchanger, NET_NFC_TEST_NOT_YET}, - // {"Transceive Test", nfcTestTransceive, NET_NFC_TEST_NOT_YET}, - // {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET}, - // {"connection handover msg test", nfcConnHandover, NET_NFC_TEST_NOT_YET}, - // {"API Exception Test", nfcTestAPIException, NET_NFC_TEST_NOT_YET}, - // {"API Exception Test2", nfcTestAPIException_tagAPI, NET_NFC_TEST_NOT_YET}, - /// {"API Exception Test3", nfcTestAPIException_targetInfo, NET_NFC_TEST_NOT_YET}, - // {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET}, - // {"LLCP Test", nfcTestStressLLCP, NET_NFC_TEST_NOT_YET}, - // {"Handover Message", nfcConnHandoverMessageTest , NET_NFC_TEST_NOT_YET}, - {"snep test", nfcTestSnep, NET_NFC_TEST_NOT_YET}, - {NULL, NULL, NET_NFC_TEST_NOT_YET}, -}; - -//static uint32_t testDevType = 0; -//static uint32_t testCardMaxNdefLength = 0; -//static uint8_t tagTestResult[NET_NFC_MAX_TAG_TYPE]; - -static int read_count = 0; -static int write_count = 0; -static int detect_count = 0; - -static net_nfc_target_handle_s *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 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_s*)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_s*)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_s *id; - bool is_ndef; - net_nfc_target_info_s *target_info = (net_nfc_target_info_s*)data; - net_nfc_carrier_config_s *config; - ndef_record_s *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_s *ndef = NULL; - data_s *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_client_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_client_deinitialize (); - CHECK_RESULT(result); - */ -#else - -/* - ndef_message_s *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_s *ndef = NULL; - data_s *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_s *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_s *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_s *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_client_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_client_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_client_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_client_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_client_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_s *handle; - bool is_ndef; - net_nfc_target_info_s *target_info = (net_nfc_target_info_s*)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_s *msg = NULL; - ndef_record_s *record = NULL; - - if( (error = net_nfc_create_uri_type_record(&record, "http://www.samsung.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_s *msg = NULL; - ndef_record_s *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_client_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_client_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_client_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_client_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_s *id; - bool is_ndef; - net_nfc_target_info_s *target_info = (net_nfc_target_info_s*)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_s *mad_key = NULL; - data_s *net_nfc_forum_key = NULL; - data_s *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_s *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_s *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_s *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_s *r_data = (data_s*)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_s *r_data = (data_s*)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_s *r_data = (data_s*)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_s *r_data = (data_s*)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_s *r_data = (data_s*)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_s *target_handle = (net_nfc_target_handle_s*)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_s *handle; - bool is_ndef; - net_nfc_target_info_s *target_info = (net_nfc_target_info_s*)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_s *ndef = (ndef_message_s*)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_s *id; - bool is_ndef; - net_nfc_target_info_s *target_info = (net_nfc_target_info_s*)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_s *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_s *target_handle = (net_nfc_target_handle_s*)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_s *handle; - bool is_ndef; - net_nfc_target_info_s *target_info = (net_nfc_target_info_s*)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_s *ndef = (ndef_message_s*)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_s *handle; - bool is_ndef; - net_nfc_target_info_s *target_info = (net_nfc_target_info_s*)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_s *ndef = (ndef_message_s*)data; - - ////net_nfc_ndef_print_message(ndef); - - test_case_result = NET_NFC_TEST_OK; - - net_nfc_error_e error = NET_NFC_OK; - ndef_message_s *msg = NULL; - ndef_record_s *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_client_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_client_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_client_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_client_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_client_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_client_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_s *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_s *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_s *type = NULL; - data_s *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_client_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_client_deinitialize (); - CHECK_RESULT(result); - */ - - return test_case_result; -} - -/*=================================================================================*/ - - -int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2) -{ - net_nfc_error_e result; - - ndef_message_s *uriMsg = NULL; - ndef_message_s *spMsg = NULL; - ndef_record_s *uriRecord = NULL; - ndef_record_s *spRecord = NULL; - data_s *type_data = NULL; - data_s *raw_data = NULL; - char smart_poster_type[] = "Sp"; - ndef_record_s *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.samsung.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_s *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_s *received_data = (data_s*)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_s *received_data = (data_s*)data; - PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data)); - - data_s *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_s *snep_handle; -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_s*) data; - //= (net_nfc_target_handle_s*) 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_s *received_data = (data_s*)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_s *config = (net_nfc_llcp_config_info_s*)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_client_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_s *config; - result = net_nfc_client_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_client_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_s *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_s *received_data = (data_s*)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_s *received_data = (data_s*)data; - PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data)); - - data_s *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_s *config = (net_nfc_llcp_config_info_s*)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_s *config; - result = net_nfc_client_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_client_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_client_initialize() == NET_NFC_OK); - CHECK_ASSULT(net_nfc_client_initialize() == NET_NFC_ALREADY_INITIALIZED); - CHECK_ASSULT(net_nfc_client_deinitialize () == NET_NFC_OK); - - int count_try = 0; - for (count_try = 0; count_try < 20; count_try ++) - { - CHECK_ASSULT(net_nfc_client_initialize() == NET_NFC_OK); - CHECK_ASSULT(net_nfc_client_deinitialize () == NET_NFC_OK); - } - - CHECK_ASSULT(net_nfc_client_deinitialize () == NET_NFC_NOT_INITIALIZED); - CHECK_ASSULT(net_nfc_client_deinitialize () == NET_NFC_NOT_INITIALIZED); - - - CHECK_ASSULT(net_nfc_client_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_client_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_client_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_s *id; - bool is_ndef; - net_nfc_target_info_s *target_info = (net_nfc_target_info_s*)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_client_deinitialize (); // Before calling transceive - - } - break; - case 1: - { - net_nfc_target_info_s *target_info = (net_nfc_target_info_s*)data; - net_nfc_target_handle_s *id; - net_nfc_get_tag_handle (target_info, &id); - net_nfc_client_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_s *target_info = (net_nfc_target_info_s*)data; - net_nfc_target_handle_s *id; - ndef_message_s *message = NULL; - ndef_record_s *record = NULL; - - net_nfc_get_tag_handle (target_info, &id); - net_nfc_client_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_s *target_info = (net_nfc_target_info_s*)data; - net_nfc_target_handle_s *id; - data_s *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_client_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_s *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_s*) 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_s*) 0x302023, NULL, NULL)) - ||(NET_NFC_OK == net_nfc_read_tag ((net_nfc_target_handle_s*) 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_s*) 0x302023, NULL, NULL)); - - CHECK_ASSULT (NET_NFC_OK != net_nfc_read_tag ((net_nfc_target_handle_s*) 0x302023 ,NULL)); - CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_read_tag (NULL ,NULL)); - net_nfc_free_data(key); - - ndef_message_s *message = NULL; - ndef_record_s *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_s*)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_s*)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_s*)0x302023 ,NULL,NULL)); - net_nfc_free_ndef_message (message); - - - for (test_case = 0 ; test_case < 4; test_case++){ - CHECK_ASSULT(net_nfc_client_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_client_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_s *value; - - switch(message) - { - case NET_NFC_MESSAGE_TAG_DISCOVERED: - { - - if (NET_NFC_OK != net_nfc_get_tag_info_keys((net_nfc_target_info_s*)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_s*)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_s*)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_s *target_id; - bool is_support; - unsigned int size; - CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_type ((net_nfc_target_info_s*)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_s*)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_s*)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_s*)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_s*)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_s*)0x302023, NULL, &length)); - CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys((net_nfc_target_info_s*)0x302023, &keys, NULL)); - CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys(NULL, &keys, &length)); - - const char* key = "hello"; - data_s *value; - - CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_s*)0x302023, key , NULL)); - CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_s*)0x302023, NULL, &value)); - CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value(NULL, key, &value)); - - CHECK_ASSULT(net_nfc_client_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_client_deinitialize() == NET_NFC_OK); - return NET_NFC_TEST_OK; -} - -/*=================================================================================*/ - - -int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr) -{ - net_nfc_carrier_config_s *carrier; - net_nfc_carrier_property_s *group; - ndef_record_s *carrier_record; - ndef_message_s *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; - -} - -/*=================================================================================*/ - - diff --git a/tools/nfc-client/nfc_api_test.h b/tools/nfc-client/nfc_api_test.h deleted file mode 100644 index 16254e5..0000000 --- a/tools/nfc-client/nfc_api_test.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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__