From ed9eba3b4dbe891c329a4669bf7dff5a7d861eac Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Thu, 22 Sep 2016 12:04:32 +0900 Subject: [PATCH 01/16] Fix Svace issue Signed-off-by: Jihoon Jung Change-Id: I92fa8349ab3ffb9b7246416dc4e565c296fb3b3c --- src/oem/oem_emul.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/oem/oem_emul.c b/src/oem/oem_emul.c index 22612d0..0bd94a9 100644 --- a/src/oem/oem_emul.c +++ b/src/oem/oem_emul.c @@ -513,20 +513,21 @@ static void _net_nfc_deinitialize_llcp(void) { DEBUG_EMUL_BEGIN(); - if (Snep_Server_msg->data->buffer != NULL) + if (Snep_Server_msg != NULL) { - free(Snep_Server_msg->data->buffer); - Snep_Server_msg->data->buffer = NULL; - } + if (Snep_Server_msg->data != NULL) + { - if (Snep_Server_msg->data != NULL) - { - free(Snep_Server_msg->data); - Snep_Server_msg->data = NULL; - } + if (Snep_Server_msg->data->buffer != NULL) + { + free(Snep_Server_msg->data->buffer); + Snep_Server_msg->data->buffer = NULL; + } + + free(Snep_Server_msg->data); + Snep_Server_msg->data = NULL; + } - if(Snep_Server_msg != NULL) - { free(Snep_Server_msg); Snep_Server_msg = NULL; } @@ -1655,11 +1656,15 @@ static void emul_ReaderThread(void * pArg) if((emulMsg_poll_fd = epoll_create1(EPOLL_CLOEXEC)) == -1) { DEBUG_MSG("epoll_create1 is occured"); + close(emulMsg_file_fd); + return; } if((emulMsg_poll_events = (struct epoll_event *)calloc(1, sizeof(struct epoll_event) * EPOLL_SIZE)) == NULL) { DEBUG_MSG("calloc is occured"); + close(emulMsg_file_fd); + return; } /* set event */ -- 2.7.4 From 2fd19a043c8037620122c17db345bb086d1dda8f Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Tue, 1 Nov 2016 19:57:31 +0900 Subject: [PATCH 02/16] Change path for x86_64 emulator binary Signed-off-by: Jihoon Jung Change-Id: Icf904d687cc67041fab288d4574043c2fe059cd0 --- CMakeLists.txt | 6 +----- packaging/nfc-plugin-emul.spec | 8 ++++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6de5f1..c5d34c1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,10 +37,6 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} pthread "-ldl") -IF (TIZEN_ARCH_64) - INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib64/nfc) -ELSE (TIZEN_ARCH_64) - INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib/nfc) -ENDIF(TIZEN_ARCH_64) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib/nfc) diff --git a/packaging/nfc-plugin-emul.spec b/packaging/nfc-plugin-emul.spec index 9a11b55..b606f95 100644 --- a/packaging/nfc-plugin-emul.spec +++ b/packaging/nfc-plugin-emul.spec @@ -34,8 +34,8 @@ rm -rf %{buildroot} install -D -m 0644 LICENSE.Apache-2.0 %{buildroot}/%{_datadir}/license/nfc-plugin-emul -mkdir -p %{buildroot}%{_libdir}/udev/rules.d -cp 98-nfc-plugin-emul.rules %{buildroot}%{_libdir}/udev/rules.d/98-nfc-plugin-emul.rules +mkdir -p %{buildroot}/usr/lib/udev/rules.d +cp 98-nfc-plugin-emul.rules %{buildroot}/usr/lib/udev/rules.d/98-nfc-plugin-emul.rules %postun -p /sbin/ldconfig @@ -43,6 +43,6 @@ cp 98-nfc-plugin-emul.rules %{buildroot}%{_libdir}/udev/rules.d/98-nfc-plugin-em %files %defattr(-,root,root,-) -%{_libdir}/nfc/libnfc-plugin.so +/usr/lib/nfc/libnfc-plugin.so %{_datadir}/license/nfc-plugin-emul -%{_libdir}/udev/rules.d/98-nfc-plugin-emul.rules +/usr/lib/udev/rules.d/98-nfc-plugin-emul.rules -- 2.7.4 From 1f1b2dcd0d8ee42d4276dba0b1c5f5e3c0f46f57 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Wed, 7 Dec 2016 15:21:03 +0900 Subject: [PATCH 03/16] Fix Svace issue : 150354, 150355 Signed-off-by: Jihoon Jung Change-Id: I6a09b8a2adcf7e1ede0c1dd5257b70905be1100c --- packaging/nfc-plugin-emul.spec | 2 +- src/oem/oem_emul.c | 21 ++++----------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/packaging/nfc-plugin-emul.spec b/packaging/nfc-plugin-emul.spec index 9a11b55..fe9def6 100644 --- a/packaging/nfc-plugin-emul.spec +++ b/packaging/nfc-plugin-emul.spec @@ -1,6 +1,6 @@ Name: nfc-plugin-emul Summary: NFC emul plugin -Version: 0.0.19 +Version: 0.0.20 Release: 0 Group: TO_BE/FILLED_IN License: Apache-2.0 diff --git a/src/oem/oem_emul.c b/src/oem/oem_emul.c index 0bd94a9..69bd0e9 100644 --- a/src/oem/oem_emul.c +++ b/src/oem/oem_emul.c @@ -1692,15 +1692,8 @@ static void emul_ReaderThread(void * pArg) condition = 0; } - while((num_of_files = epoll_wait(emulMsg_poll_fd, emulMsg_poll_events, EPOLL_SIZE, -1)) == 0){ - if(emulMsg_poll_fd == -1){ - DEBUG_MSG("client ipc thread is terminated"); - condition = 0; - } - else{ - DEBUG_MSG("no data is changed "); - } - + while((num_of_files = epoll_wait(emulMsg_poll_fd, emulMsg_poll_events, EPOLL_SIZE, -1)) == 0) { + DEBUG_MSG("no data is changed "); } for(index = 0; index < num_of_files; index++) @@ -2873,14 +2866,8 @@ static bool net_nfc_emul_controller_llcp_recv(net_nfc_target_handle_s* handle, n else { /* In here, we dosen't call _net_nfc_llcp_data_receive_cb. just wait event from emulator */ /*After copying data address, we will return it, immediately */ - if(data != NULL) { - DEBUG_MSG("data address is set"); - llcp_server_data = data; - } - else { - DEBUG_ERR_MSG("data address is NULL"); - return false; - } + DEBUG_MSG("data address is set"); + llcp_server_data = data; } } else { -- 2.7.4 From 7dfb1ffc30fdadcc7ae0e9c8c52e2c0cbacfb7f4 Mon Sep 17 00:00:00 2001 From: Hyihong Chae Date: Fri, 13 Jan 2017 10:53:51 +0900 Subject: [PATCH 04/16] Sync code with Tizen 3.0 branch Change-Id: I703aa80403a3283c768931a5ad90df7b1cfd2877 Signed-off-by: HyiHong Chae --- src/oem/oem_emul.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) mode change 100644 => 100755 src/oem/oem_emul.c diff --git a/src/oem/oem_emul.c b/src/oem/oem_emul.c old mode 100644 new mode 100755 index 69bd0e9..e7a223e --- a/src/oem/oem_emul.c +++ b/src/oem/oem_emul.c @@ -216,7 +216,7 @@ static net_nfc_target_handle_s * current_working_handle = NULL; static bool g_stack_init_successful = 0; static bool g_tag_attached = 0; static bool g_p2p_attached = 0; - +static int current_connection_id = 1; /* for llcp functionality */ socket_info_s socket_info_array[LLCP_NB_SOCKET_MAX] = {{0,}}; @@ -1349,6 +1349,8 @@ static void _net_nfc_target_discovered_cb(emulMsg_s *emul_msg) return; } + target_detected->handle->connection_id = current_connection_id++; + if(target_detected->devType == NET_NFC_NFCIP1_TARGET ){ DEBUG_MSG("set llcp connection type. remote device is target"); handle->connection_type = NET_NFC_P2P_CONNECTION_TARGET; -- 2.7.4 From 6a45008ff81283c9b26db58d4b434a15430f9b19 Mon Sep 17 00:00:00 2001 From: "jh8801.jung" Date: Wed, 29 Mar 2017 19:13:22 +0900 Subject: [PATCH 05/16] Sync with 3.0 : Ver. 0.0.20 to 0.0.23 Change-Id: I051e6bf90b32357be0c08b8953782347dc477dea --- CMakeLists.txt | 2 -- packaging/nfc-plugin-emul.spec | 6 ++---- src/oem/oem_emul.c | 25 +++++++++++++++++-------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5d34c1..a83b598 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,5 +38,3 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} pthread "-ldl") INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib/nfc) - - diff --git a/packaging/nfc-plugin-emul.spec b/packaging/nfc-plugin-emul.spec index c8baaa8..531e400 100644 --- a/packaging/nfc-plugin-emul.spec +++ b/packaging/nfc-plugin-emul.spec @@ -1,6 +1,6 @@ Name: nfc-plugin-emul Summary: NFC emul plugin -Version: 0.0.20 +Version: 0.0.23 Release: 0 Group: TO_BE/FILLED_IN License: Apache-2.0 @@ -32,8 +32,6 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install -install -D -m 0644 LICENSE.Apache-2.0 %{buildroot}/%{_datadir}/license/nfc-plugin-emul - mkdir -p %{buildroot}/usr/lib/udev/rules.d cp 98-nfc-plugin-emul.rules %{buildroot}/usr/lib/udev/rules.d/98-nfc-plugin-emul.rules @@ -42,7 +40,7 @@ cp 98-nfc-plugin-emul.rules %{buildroot}/usr/lib/udev/rules.d/98-nfc-plugin-emul %post -p /sbin/ldconfig %files +%license LICENSE.Apache-2.0 %defattr(-,root,root,-) /usr/lib/nfc/libnfc-plugin.so -%{_datadir}/license/nfc-plugin-emul /usr/lib/udev/rules.d/98-nfc-plugin-emul.rules diff --git a/src/oem/oem_emul.c b/src/oem/oem_emul.c index e7a223e..c4890b0 100755 --- a/src/oem/oem_emul.c +++ b/src/oem/oem_emul.c @@ -1140,6 +1140,8 @@ static bool _net_nfc_create_ndef_from_emulMsg(emulMsg_s *emul_msg) _net_nfc_store_ndef_message(&rawdata); + _nfc_emul_util_free_mem(rawdata.buffer); + DEBUG_EMUL_END(); return retval; @@ -1257,9 +1259,11 @@ static void _net_nfc_destroy_emulMsg(emulMsg_s *emul_msg) { DEBUG_EMUL_BEGIN(); - if(emul_msg != NULL && emul_msg->file_data != NULL) + if(emul_msg != NULL) { - free(emul_msg->file_data); + if(emul_msg->file_data != NULL) + free(emul_msg->file_data); + free(emul_msg); } @@ -1485,6 +1489,8 @@ static void _net_nfc_llcp_create_snep_server_msg(snep_command_field_e resp_field if(rawdata.length > 0) memcpy(temp, rawdata.buffer, rawdata.length); + _nfc_emul_util_free_mem(rawdata.buffer); + DEBUG_EMUL_END(); } @@ -1506,6 +1512,7 @@ static bool _net_nfc_make_llcp_data(emulMsg_s *emul_msg) data_s rawdata = { NULL, 0 }; _net_nfc_retrieve_ndef_message(&rawdata); + _nfc_emul_util_free_mem(rawdata.buffer); if (emul_msg->record_count == 0 || rawdata.length == 0) { @@ -1688,12 +1695,6 @@ static void emul_ReaderThread(void * pArg) DEBUG_MSG("epoll wait >>>>"); - if(emulMsg_poll_fd == -1 || emulMsg_file_fd == -1) - { - DEBUG_MSG("client is deinitialized. "); - condition = 0; - } - while((num_of_files = epoll_wait(emulMsg_poll_fd, emulMsg_poll_events, EPOLL_SIZE, -1)) == 0) { DEBUG_MSG("no data is changed "); } @@ -2201,6 +2202,7 @@ static bool net_nfc_emul_controller_check_ndef(net_nfc_target_handle_s* handle, DEBUG_EMUL_BEGIN(); _net_nfc_retrieve_ndef_message(&rawdata); + _nfc_emul_util_free_mem(rawdata.buffer); if (_net_nfc_emul_get_is_tag_attached()) { @@ -2273,7 +2275,10 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d *result = _net_nfc_retrieve_ndef_message(&rawdata); if(*result != NET_NFC_OK) + { + _nfc_emul_util_free_mem(rawdata.buffer); return false; + } real_data_size = rawdata.length; @@ -2281,6 +2286,7 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d { DEBUG_ERR_MSG("read ndef_msg is failed >>> real_data_size is zero"); *result = NET_NFC_NO_NDEF_MESSAGE; + _nfc_emul_util_free_mem(rawdata.buffer); return false; } @@ -2289,6 +2295,7 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d if(*data == NULL) { *result = NET_NFC_ALLOC_FAIL; + _nfc_emul_util_free_mem(rawdata.buffer); return false; } @@ -2299,11 +2306,13 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d { free(*data); *result = NET_NFC_ALLOC_FAIL; + _nfc_emul_util_free_mem(rawdata.buffer); return false; } /* copy rawdata to data->buffer */ memcpy((*data)->buffer, rawdata.buffer, real_data_size); + _nfc_emul_util_free_mem(rawdata.buffer); DEBUG_EMUL_END(); -- 2.7.4 From a2de5dc4f9e72cb5c9793dd1edfa81bac2b96202 Mon Sep 17 00:00:00 2001 From: "jh8801.jung" Date: Tue, 25 Apr 2017 19:57:16 +0900 Subject: [PATCH 06/16] Fix the Svace issue and coding rule Signed-off-by: jh8801.jung Change-Id: I8001bbc3ecf8834154683fdf82ea26ba017c1ecb --- packaging/nfc-plugin-emul.spec | 2 +- src/nfc_debug_private.h | 63 ++- src/oem/oem_emul.c | 1032 ++++++++++++++++------------------------ 3 files changed, 441 insertions(+), 656 deletions(-) diff --git a/packaging/nfc-plugin-emul.spec b/packaging/nfc-plugin-emul.spec index 531e400..65fb8f4 100644 --- a/packaging/nfc-plugin-emul.spec +++ b/packaging/nfc-plugin-emul.spec @@ -1,6 +1,6 @@ Name: nfc-plugin-emul Summary: NFC emul plugin -Version: 0.0.23 +Version: 0.0.24 Release: 0 Group: TO_BE/FILLED_IN License: Apache-2.0 diff --git a/src/nfc_debug_private.h b/src/nfc_debug_private.h index 022504b..ade279f 100755 --- a/src/nfc_debug_private.h +++ b/src/nfc_debug_private.h @@ -29,71 +29,64 @@ #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_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 LOG_COLOR_END "\033[0;m" -#define DEBUG_MSG_PRINT_BUFFER(buffer,length) \ +#define DEBUG_MSG_PRINT_BUFFER(buffer, length) \ do {\ int i = 0;\ LOGE(LOG_COLOR_BLUE"BUFFER =>"LOG_COLOR_END);\ - for(; i < length; i++)\ - {\ - LOGE(LOG_COLOR_BLUE" [0x%x] "LOG_COLOR_END,buffer[i]);\ - }\ + for (; i < length; i++)\ + LOGE(LOG_COLOR_BLUE" [0x%x] "LOG_COLOR_END, buffer[i]);\ LOGE(LOG_COLOR_BLUE""LOG_COLOR_END);\ -}while(0) +} while (0) -#define DEBUG_MSG_PRINT_BUFFER_CHAR(buffer,length) \ +#define DEBUG_MSG_PRINT_BUFFER_CHAR(buffer, length) \ do {\ int i = 0;\ LOGE(LOG_COLOR_BLUE"BUFFER =>"LOG_COLOR_END);\ - for(; i < length; i++)\ - {\ - LOGE(LOG_COLOR_BLUE" [%c] "LOG_COLOR_END,buffer[i]);\ - }\ + for (; i < length; i++)\ + LOGE(LOG_COLOR_BLUE" [%c] "LOG_COLOR_END, buffer[i]);\ LOGE(LOG_COLOR_BLUE""LOG_COLOR_END);\ -}while(0) +} while (0) -#define DEBUG_MSG(format,args...) \ +#define DEBUG_MSG(format, args...) \ do {\ LOGE(LOG_COLOR_CYAN" "format""LOG_COLOR_END, ##args);\ -}while(0) +} while (0) -#define DEBUG_ERR_MSG(format,args...) \ +#define DEBUG_ERR_MSG(format, args...) \ do {\ LOGE(LOG_COLOR_RED" "format""LOG_COLOR_END, ##args);\ -}while(0) +} while (0) #define DEBUG_EMUL_BEGIN() \ - do\ - {\ - LOGE(LOG_COLOR_CYAN" BEGIN >>>>"LOG_COLOR_END); \ - } while( 0 ) +do {\ + LOGE(LOG_COLOR_CYAN" BEGIN >>>>"LOG_COLOR_END);\ +} while (0) #define DEBUG_EMUL_END() \ - do\ - {\ - LOGE(LOG_COLOR_CYAN" END >>>>"LOG_COLOR_END); \ - } \ - while( 0 ) +do {\ + LOGE(LOG_COLOR_CYAN" END >>>>"LOG_COLOR_END);\ +} while (0) #define PROFILING(str) \ -do{ \ +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);\ - LOGE(str); \ + LOGE(str);\ LOGE("\t time = [%s]", time_string);\ -}while(0) +} while (0) #endif diff --git a/src/oem/oem_emul.c b/src/oem/oem_emul.c index c4890b0..1b7e8cd 100755 --- a/src/oem/oem_emul.c +++ b/src/oem/oem_emul.c @@ -60,7 +60,7 @@ typedef enum { } emul_message_id; typedef enum { - EMUL_TAG_TOPAZ_JEWEL =1, + EMUL_TAG_TOPAZ_JEWEL = 1, EMUL_TAG_MIFARE_UL, EMUL_TAG_FELICA, EMUL_TAG_MIFARE_DESFIRE, @@ -87,7 +87,7 @@ typedef enum { NET_NFC_STATE_UNKNOWN } llcp_state_e; -typedef enum{ +typedef enum { SNEP_REQ_CONTINUE = 0x00, SNEP_REQ_GET = 0x01, SNEP_REQ_PUT = 0x02, @@ -100,15 +100,15 @@ typedef enum{ SNEP_RESP_NOT_IMPLEMENT = 0xE0, SNEP_RESP_UNSUPPORTED_VER = 0xE1, SNEP_RESP_REJECT = 0xFF, -}snep_command_field_e; +} snep_command_field_e; typedef struct _socket_info_s { net_nfc_llcp_socket_t socket_handle; bool isValid; void* user_context; -}socket_info_s; +} socket_info_s; -typedef struct _net_nfc_oem_llcp_state_t{ +typedef struct _net_nfc_oem_llcp_state_t { int client_fd; unsigned int step; unsigned int fragment_offset; @@ -129,7 +129,7 @@ typedef struct _net_nfc_oem_llcp_state_t{ } net_nfc_oem_llcp_state_t; -typedef struct _snep_msg_s{ +typedef struct _snep_msg_s { data_s *data; int offset; bool isSegment; @@ -137,23 +137,23 @@ typedef struct _snep_msg_s{ /* Members below are used for snep msg of client */ bool firstTime; bool RespContinue; -}snep_msg_s; +} snep_msg_s; -typedef struct _emulMsg_data_s{ +typedef struct _emulMsg_data_s { net_nfc_record_tnf_e tnf; data_s typeName; data_s id; data_s payload; bool realRecord; -}emulMsg_data_s; +} emulMsg_data_s; -typedef struct _emulMsg_s{ +typedef struct _emulMsg_s { emul_message_id message_id; emul_target_type target_type; int record_count; uint8_t* file_data; -}emulMsg_s; +} emulMsg_s; typedef void * (*emul_Nfc_thread_handler_t) (void * pParam); @@ -203,26 +203,26 @@ typedef void * (*emul_Nfc_thread_handler_t) (void * pParam); /****************************** VARIABLE START *******************************************/ /* listener callback */ -static target_detection_listener_cb g_emul_controller_target_cb ; -static se_transaction_listener_cb g_emul_controller_se_cb ; -static llcp_event_listener_cb g_emul_controller_llcp_cb ; -static hce_apdu_listener_cb g_emul_controller_hce_cb ; +static target_detection_listener_cb g_emul_controller_target_cb ; +static se_transaction_listener_cb g_emul_controller_se_cb ; +static llcp_event_listener_cb g_emul_controller_llcp_cb ; +static hce_apdu_listener_cb g_emul_controller_hce_cb ; /* for emulator management */ pthread_t gEmulThread; /* for stack management */ static net_nfc_target_handle_s * current_working_handle = NULL; -static bool g_stack_init_successful = 0; -static bool g_tag_attached = 0; -static bool g_p2p_attached = 0; -static int current_connection_id = 1; +static bool g_stack_init_successful = 0; +static bool g_tag_attached = 0; +static bool g_p2p_attached = 0; +static int current_connection_id = 1; /* for llcp functionality */ -socket_info_s socket_info_array[LLCP_NB_SOCKET_MAX] = {{0,}}; +socket_info_s socket_info_array[LLCP_NB_SOCKET_MAX] = { {0, } }; -snep_msg_s* Snep_Server_msg; -data_s * llcp_server_data = NULL; +snep_msg_s* Snep_Server_msg; +data_s* llcp_server_data = NULL; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; @@ -234,8 +234,8 @@ pthread_cond_t cond = PTHREAD_COND_INITIALIZER; /*************************** INTERFACE START ***************************************/ -static bool net_nfc_emul_controller_init (net_nfc_error_e* result); -static bool net_nfc_emul_controller_deinit (void); +static bool net_nfc_emul_controller_init(net_nfc_error_e* result); +static bool net_nfc_emul_controller_deinit(void); static bool net_nfc_emul_controller_register_listener( target_detection_listener_cb target_detection_listener, se_transaction_listener_cb se_transaction_listener, @@ -247,7 +247,7 @@ static bool net_nfc_emul_controller_get_firmware_version(data_s **data, net_nfc_ static bool net_nfc_emul_controller_check_firmware_version(net_nfc_error_e* result); static bool net_nfc_emul_controller_update_firmware(net_nfc_error_e* result); static bool net_nfc_emul_controller_get_stack_information(net_nfc_stack_information_s* stack_info, net_nfc_error_e* result); -static bool net_nfc_emul_controller_configure_discovery (net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result); +static bool net_nfc_emul_controller_configure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result); static bool net_nfc_emul_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result); static bool net_nfc_emul_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); static bool net_nfc_emul_controller_connect(net_nfc_target_handle_s* handle, net_nfc_error_e* result); @@ -257,35 +257,35 @@ static bool net_nfc_emul_controller_check_target_presence(net_nfc_target_handle_ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, data_s** data, net_nfc_error_e* result); static bool net_nfc_emul_controller_write_ndef(net_nfc_target_handle_s* handle, data_s* data, net_nfc_error_e* result); static bool net_nfc_emul_controller_make_read_only_ndef(net_nfc_target_handle_s* handle, net_nfc_error_e* result); -static bool net_nfc_emul_controller_transceive (net_nfc_target_handle_s* handle, net_nfc_transceive_info_s* info, data_s** data, net_nfc_error_e* result); +static bool net_nfc_emul_controller_transceive(net_nfc_target_handle_s* handle, net_nfc_transceive_info_s* info, data_s** data, net_nfc_error_e* result); static bool net_nfc_emul_controller_format_ndef(net_nfc_target_handle_s* handle, data_s* secure_key, net_nfc_error_e* result); static bool net_nfc_emul_controller_exception_handler(void); static bool net_nfc_emul_controller_is_ready(net_nfc_error_e* error); -static bool net_nfc_emul_controller_llcp_config (net_nfc_llcp_config_info_s * config, net_nfc_error_e * result); -static bool net_nfc_emul_controller_llcp_check_llcp (net_nfc_target_handle_s * handle, net_nfc_error_e* result); -static bool net_nfc_emul_controller_llcp_activate_llcp (net_nfc_target_handle_s * handle, net_nfc_error_e* result); -static bool net_nfc_emul_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); +static bool net_nfc_emul_controller_llcp_config(net_nfc_llcp_config_info_s * config, net_nfc_error_e * result); +static bool net_nfc_emul_controller_llcp_check_llcp(net_nfc_target_handle_s * handle, net_nfc_error_e* result); +static bool net_nfc_emul_controller_llcp_activate_llcp(net_nfc_target_handle_s * handle, net_nfc_error_e* result); +static bool net_nfc_emul_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); static bool net_nfc_emul_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result); static bool net_nfc_emul_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); -static bool net_nfc_emul_controller_llcp_accept (net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void *user_param); -static bool net_nfc_emul_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); +static bool net_nfc_emul_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void *user_param); +static bool net_nfc_emul_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); static bool net_nfc_emul_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); static bool net_nfc_emul_controller_llcp_reject(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result); -static bool net_nfc_emul_controller_llcp_disconnect (net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param); -static bool net_nfc_emul_controller_llcp_socket_close (net_nfc_llcp_socket_t socket, net_nfc_error_e* result); +static bool net_nfc_emul_controller_llcp_disconnect(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param); +static bool net_nfc_emul_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e* result); static bool net_nfc_emul_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); static bool net_nfc_emul_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); static bool net_nfc_emul_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); static bool net_nfc_emul_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); -static bool net_nfc_emul_controller_llcp_get_remote_config (net_nfc_target_handle_s* handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e* result); -static bool net_nfc_emul_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); +static bool net_nfc_emul_controller_llcp_get_remote_config(net_nfc_target_handle_s* handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e* result); +static bool net_nfc_emul_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); static bool net_nfc_emul_controller_support_nfc(net_nfc_error_e *result); static bool net_nfc_emul_controller_secure_element_open(net_nfc_secure_element_type_e element_type, net_nfc_target_handle_s **handle, net_nfc_error_e *result); static bool net_nfc_emul_controller_secure_element_get_atr(net_nfc_target_handle_s *handle, - data_s **atr, net_nfc_error_e *result); + data_s **atr, net_nfc_error_e *result); static bool net_nfc_emul_controller_secure_element_send_apdu(net_nfc_target_handle_s *handle, data_s *command, data_s **response, net_nfc_error_e *result); static bool net_nfc_emul_controller_secure_element_close(net_nfc_target_handle_s *handle, @@ -303,23 +303,22 @@ static bool net_nfc_emul_controller_secure_element_close(net_nfc_target_handle_s void __nfc_emul_util_free_mem(void** mem, char * filename, unsigned int line); /* allocation memory */ void __nfc_emul_util_alloc_mem(void** mem, int size, char * filename, unsigned int line); -#define _nfc_emul_util_alloc_mem(mem,size) __nfc_emul_util_alloc_mem((void **)&mem,size,__FILE__, __LINE__) -#define _nfc_emul_util_free_mem(mem) __nfc_emul_util_free_mem((void **)&mem,__FILE__, __LINE__) +#define _nfc_emul_util_alloc_mem(mem, size) __nfc_emul_util_alloc_mem((void **)&mem, size, __FILE__, __LINE__) +#define _nfc_emul_util_free_mem(mem) __nfc_emul_util_free_mem((void **)&mem, __FILE__, __LINE__) -static bool __net_nfc_is_valide_target_handle (net_nfc_target_handle_s * handle); -static void __net_nfc_make_valid_target_handle (net_nfc_target_handle_s ** handle); -static void __net_nfc_make_invalid_target_handle (); +static bool __net_nfc_is_valide_target_handle(net_nfc_target_handle_s * handle); +static void __net_nfc_make_valid_target_handle(net_nfc_target_handle_s ** handle); +static void __net_nfc_make_invalid_target_handle(); /*************************** STATIC FUNCTION DECLARE END ***************************************/ -void __nfc_emul_util_free_mem (void** mem, char * filename, unsigned int line) +void __nfc_emul_util_free_mem(void** mem, char * filename, unsigned int line) { - if (mem == NULL || *mem == NULL) - { - LOGE ("FILE: %s, LINE:%d, Invalid parameter in mem free util (pinter is NULL)", filename, line); + if (mem == NULL || *mem == NULL) { + LOGE("FILE: %s, LINE:%d, Invalid parameter in mem free util (pinter is NULL)", filename, line); return; } free(*mem); @@ -328,66 +327,56 @@ void __nfc_emul_util_free_mem (void** mem, char * filename, unsigned int line) void __nfc_emul_util_alloc_mem(void** mem, int size, char * filename, unsigned int line) { - if (mem == NULL || size <= 0) - { - LOGE ("FILE: %s, LINE:%d, Invalid parameter in mem alloc util", filename, line); + if (mem == NULL || size <= 0) { + LOGE("FILE: %s, LINE:%d, Invalid parameter in mem alloc util", filename, line); return; } DEBUG_MSG("size to malloc() = [%d]", size); if (*mem != NULL) - { LOGE("FILE: %s, LINE:%d, WARNING: Pointer is already allocated or it was not initialized with NULL", filename, line); - } - *mem = malloc (size); + *mem = malloc(size); if (*mem != NULL) - { - memset (*mem, 0x0, size); - } + memset(*mem, 0x0, size); else - { LOGE("FILE: %s, LINE:%d, Allocation is failed", filename, line); - } } -static bool __net_nfc_is_valide_target_handle (net_nfc_target_handle_s * handle) +static bool __net_nfc_is_valide_target_handle(net_nfc_target_handle_s * handle) { bool result = (current_working_handle == handle); - if (!result){ - DEBUG_MSG ("[WARNING]: INVALID HANDLE IS DETECTED!"); - } + if (!result) + DEBUG_MSG("[WARNING]: INVALID HANDLE IS DETECTED!"); + return result; } -static void __net_nfc_make_valid_target_handle (net_nfc_target_handle_s ** handle) +static void __net_nfc_make_valid_target_handle(net_nfc_target_handle_s ** handle) { - if (current_working_handle != NULL){ - DEBUG_MSG ("[WARNING]: HANDLE WAS ALLOCATED ALREADY!"); - } - _nfc_emul_util_alloc_mem (*handle, sizeof (net_nfc_target_handle_s)); - if (*handle != NULL) { + if (current_working_handle != NULL) + DEBUG_MSG("[WARNING]: HANDLE WAS ALLOCATED ALREADY!"); + + _nfc_emul_util_alloc_mem(*handle, sizeof(net_nfc_target_handle_s)); + if (*handle != NULL) current_working_handle = *handle; - } } -static void __net_nfc_make_invalid_target_handle () +static void __net_nfc_make_invalid_target_handle() { if (current_working_handle != NULL) { - _nfc_emul_util_free_mem (current_working_handle); + _nfc_emul_util_free_mem(current_working_handle); current_working_handle = NULL; } } -static socket_info_s * _net_nfc_get_available_socket_slot () +static socket_info_s * _net_nfc_get_available_socket_slot() { int idx = 0; - for (; idx < LLCP_NB_SOCKET_MAX; idx++) - { - if (socket_info_array [idx].isValid == false) - { - memset (&(socket_info_array[idx]), 0x00, sizeof (socket_info_s)); - socket_info_array [idx].isValid = true; + for (; idx < LLCP_NB_SOCKET_MAX; idx++) { + if (socket_info_array[idx].isValid == false) { + memset(&(socket_info_array[idx]), 0x00, sizeof(socket_info_s)); + socket_info_array[idx].isValid = true; return &(socket_info_array[idx]); } } @@ -396,31 +385,26 @@ static socket_info_s * _net_nfc_get_available_socket_slot () return NULL; } -static void _net_nfc_remove_socket_slot (net_nfc_llcp_socket_t socket) +static void _net_nfc_remove_socket_slot(net_nfc_llcp_socket_t socket) { int idx = 0; - for (; idx < LLCP_NB_SOCKET_MAX; idx++) - { - if (socket_info_array [idx].isValid == true && - socket_info_array [idx].socket_handle == socket) - { - socket_info_array [idx].isValid = false; - socket_info_array [idx].socket_handle = 0; - socket_info_array [idx].user_context= NULL; + for (; idx < LLCP_NB_SOCKET_MAX; idx++) { + if (socket_info_array[idx].isValid == true && + socket_info_array[idx].socket_handle == socket) { + socket_info_array[idx].isValid = false; + socket_info_array[idx].socket_handle = 0; + socket_info_array[idx].user_context = NULL; } } } -static socket_info_s * _net_nfc_find_server_socket (net_nfc_llcp_socket_t socket) +static socket_info_s * _net_nfc_find_server_socket(net_nfc_llcp_socket_t socket) { int idx = 0; - for (; idx < LLCP_NB_SOCKET_MAX; idx++) - { - if (socket_info_array [idx].socket_handle == socket && socket_info_array [idx].isValid == true) - { + for (; idx < LLCP_NB_SOCKET_MAX; idx++) { + if (socket_info_array[idx].socket_handle == socket && socket_info_array[idx].isValid == true) return &(socket_info_array[idx]); - } } DEBUG_ERR_MSG("_net_nfc_find_server_socket is failed"); @@ -429,7 +413,7 @@ static socket_info_s * _net_nfc_find_server_socket (net_nfc_llcp_socket_t socket ////////////// INTERFACE START ////////// -NET_NFC_EXPORT_API bool onload(net_nfc_oem_interface_s* emul_interfaces) +NET_NFC_EXPORT_API bool onload(net_nfc_oem_interface_s * emul_interfaces) { DEBUG_EMUL_BEGIN(); @@ -499,8 +483,7 @@ static void _net_nfc_initialize_llcp(void) { DEBUG_EMUL_BEGIN(); - if(Snep_Server_msg == NULL) - { + if (Snep_Server_msg == NULL) { Snep_Server_msg = (snep_msg_s *)calloc(1, sizeof(snep_msg_s)); Snep_Server_msg->data = (data_s *)calloc(1, sizeof(data_s)); Snep_Server_msg->data->buffer = (uint8_t *)calloc(1, sizeof(uint8_t) * BUFFER_LENGTH_MAX); @@ -513,13 +496,9 @@ static void _net_nfc_deinitialize_llcp(void) { DEBUG_EMUL_BEGIN(); - if (Snep_Server_msg != NULL) - { - if (Snep_Server_msg->data != NULL) - { - - if (Snep_Server_msg->data->buffer != NULL) - { + if (Snep_Server_msg != NULL) { + if (Snep_Server_msg->data != NULL) { + if (Snep_Server_msg->data->buffer != NULL) { free(Snep_Server_msg->data->buffer); Snep_Server_msg->data->buffer = NULL; } @@ -566,20 +545,18 @@ static bool _net_nfc_is_data_emulMsgData(emul_message_id messageId) bool retval = false; switch (messageId) { - case EMUL_NFC_TAG_DISCOVERED :{ - retval = true; - } + case EMUL_NFC_TAG_DISCOVERED: + retval = true; break; - case EMUL_NFC_P2P_SEND :{ - retval = true; - } + case EMUL_NFC_P2P_SEND: + retval = true; break; - case EMUL_NFC_TAG_DETACHED : - case EMUL_NFC_P2P_DISCOVERED : - case EMUL_NFC_P2P_DETACHED : - default : + case EMUL_NFC_TAG_DETACHED: + case EMUL_NFC_P2P_DISCOVERED: + case EMUL_NFC_P2P_DETACHED: + default: break; } @@ -598,35 +575,34 @@ static net_nfc_record_tnf_e _net_nfc_get_tnf_type(int name_format) net_nfc_record_tnf_e tnf = NET_NFC_RECORD_EMPTY; switch (name_format) { - case EMUL_NDEF_TNF_EMPTY : - tnf = NET_NFC_RECORD_EMPTY; + case EMUL_NDEF_TNF_EMPTY: + tnf = NET_NFC_RECORD_EMPTY; break; - case EMUL_NDEF_TNF_WELL_KNOWN : - tnf = NET_NFC_RECORD_WELL_KNOWN_TYPE; + case EMUL_NDEF_TNF_WELL_KNOWN: + tnf = NET_NFC_RECORD_WELL_KNOWN_TYPE; break; - case EMUL_NDEF_TNF_MIME_MEDIA : - tnf = NET_NFC_RECORD_MIME_TYPE; + case EMUL_NDEF_TNF_MIME_MEDIA: + tnf = NET_NFC_RECORD_MIME_TYPE; break; - case EMUL_NDEF_TNF_ABSOLUTE_URI : - tnf = NET_NFC_RECORD_URI; + case EMUL_NDEF_TNF_ABSOLUTE_URI: + tnf = NET_NFC_RECORD_URI; break; - case EMUL_NDEF_TNF_EXTERNAL : - tnf = NET_NFC_RECORD_EXTERNAL_RTD; + case EMUL_NDEF_TNF_EXTERNAL: + tnf = NET_NFC_RECORD_EXTERNAL_RTD; break; - case EMUL_NDEF_TNF_UNKNOWN : - tnf = NET_NFC_RECORD_UNKNOWN; + case EMUL_NDEF_TNF_UNKNOWN: + tnf = NET_NFC_RECORD_UNKNOWN; break; - default : - tnf = NET_NFC_RECORD_UNKNOWN; - DEBUG_MSG("data is currupted"); + default: + tnf = NET_NFC_RECORD_UNKNOWN; + DEBUG_MSG("data is currupted"); break; - } DEBUG_MSG("tnf [%d]", tnf); @@ -645,10 +621,10 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag int create_record_count = 0; char emulMsg[BUFFER_LENGTH_MAX] = { 0, }; - memcpy(emulMsg, emul_msg->file_data, strlen((char*)emul_msg->file_data)); + memcpy(emulMsg, emul_msg->file_data, sizeof(emulMsg)-1); /* parsing data and create record to record structure */ - for (index = 0; index < record_count ; index ++) { + for (index = 0; index < record_count ; index++) { char *name_format; char *type_name; char *record_id; @@ -659,20 +635,16 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag /* parse string */ if (index == 0) - { name_format = strtok((char *) emulMsg, NET_NFC_EMUL_MSG_RECORD_SEPERATOR); - } else - { name_format = strtok(NULL, NET_NFC_EMUL_MSG_RECORD_SEPERATOR); - } + type_name = strtok(NULL, NET_NFC_EMUL_MSG_RECORD_SEPERATOR); record_id = strtok(NULL, NET_NFC_EMUL_MSG_RECORD_SEPERATOR); if (index == record_count-1) { /* the last payload : we have to read sentence fully */ record_payload = strtok(NULL, "\n"); - } - else { + } else { record_payload = strtok(NULL, NET_NFC_EMUL_MSG_RECORD_SEPERATOR); } @@ -682,7 +654,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag DEBUG_MSG("Data : type_name "); record.typeName.length = strlen(type_name); - _nfc_emul_util_alloc_mem(record.typeName.buffer, record.typeName.length); + _nfc_emul_util_alloc_mem(record.typeName.buffer, record.typeName.length + 1); if (record.typeName.buffer == NULL) { DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); @@ -693,7 +665,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag DEBUG_MSG("Data : record_id "); record.id.length = strlen(record_id); - _nfc_emul_util_alloc_mem(record.id.buffer, record.id.length); + _nfc_emul_util_alloc_mem(record.id.buffer, record.id.length + 1); if (record.id.buffer == NULL) { DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); @@ -704,7 +676,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag DEBUG_MSG("Data : record_payload "); record.payload.length = strlen(record_payload); - _nfc_emul_util_alloc_mem(record.payload.buffer, record.payload.length); + _nfc_emul_util_alloc_mem(record.payload.buffer, record.payload.length + 1); if (record.payload.buffer == NULL) { DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); @@ -726,30 +698,26 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag net_nfc_error_e result = NET_NFC_OK; if (record.tnf == NET_NFC_RECORD_EMPTY) { - if((result = net_nfc_util_create_record(NET_NFC_RECORD_EMPTY, &record.typeName, &record.id, &record.payload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { + if ((result = net_nfc_util_create_record(NET_NFC_RECORD_EMPTY, &record.typeName, &record.id, &record.payload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { DEBUG_MSG("net_nfc_create_record failed[%d]", result); goto ERROR;; } - } - else if (record.tnf == NET_NFC_RECORD_UNKNOWN) { - if((result = net_nfc_util_create_record(NET_NFC_RECORD_UNKNOWN, &record.typeName, &record.id, &record.payload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { + } else if (record.tnf == NET_NFC_RECORD_UNKNOWN) { + if ((result = net_nfc_util_create_record(NET_NFC_RECORD_UNKNOWN, &record.typeName, &record.id, &record.payload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { DEBUG_MSG("net_nfc_create_record failed[%d]", result); goto ERROR;; } - } - else if ((record.tnf == NET_NFC_RECORD_WELL_KNOWN_TYPE)) { + } else if (record.tnf == NET_NFC_RECORD_WELL_KNOWN_TYPE) { if (!strncmp((char *)record.typeName.buffer, "U", 1)) { DEBUG_MSG("URI Type "); data_s payload_data = { NULL, 0 }; - if (record.payload.buffer != NULL ) - { + if (record.payload.buffer != NULL) { payload_data.length = strlen((char *)record_payload) + 1; _nfc_emul_util_alloc_mem(payload_data.buffer, payload_data.length); - if (payload_data.buffer == NULL) - { + if (payload_data.buffer == NULL) { DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); goto ERROR; } @@ -758,28 +726,25 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag memcpy(payload_data.buffer + 1, record.payload.buffer, payload_data.length - 1); } - if (net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &payload_data, (ndef_record_s**) &new_record) != NET_NFC_OK){ + if (net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &payload_data, (ndef_record_s**) &new_record) != NET_NFC_OK) { DEBUG_ERR_MSG("net_nfc_util_create_record is failed"); goto ERROR; } - if (payload_data.buffer != NULL ) + if (payload_data.buffer != NULL) _nfc_emul_util_free_mem(payload_data.buffer); - } - else if (!strncmp((char *)record.typeName.buffer, "T", 1)) { + } else if (!strncmp((char *)record.typeName.buffer, "T", 1)) { DEBUG_MSG("TEXT Type "); data_s payload_data = { NULL, 0 }; int offset = 0; int controll_byte; - if (record.payload.buffer != NULL ) - { + if (record.payload.buffer != NULL) { payload_data.length = strlen((char *)record_payload) + strlen("en-US") + 1; _nfc_emul_util_alloc_mem(payload_data.buffer, payload_data.length); - if (payload_data.buffer == NULL) - { + if (payload_data.buffer == NULL) { DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); goto ERROR; } @@ -793,24 +758,20 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag offset = offset + strlen("en-US"); memcpy(payload_data.buffer + offset, record.payload.buffer, strlen(record_payload)); - } - if (net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &payload_data, (ndef_record_s**) &new_record) != NET_NFC_OK){ + if (net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &payload_data, (ndef_record_s**) &new_record) != NET_NFC_OK) { DEBUG_ERR_MSG("net_nfc_util_create_record is failed"); goto ERROR; } - if (payload_data.buffer != NULL ) + if (payload_data.buffer != NULL) _nfc_emul_util_free_mem(payload_data.buffer); - } - else { + } else { DEBUG_ERR_MSG("NET_NFC_RECORD_WELL_KNOWN_TYPE >> typeName is wrong"); goto ERROR; } - } - else if ((record.tnf == NET_NFC_RECORD_MIME_TYPE)) { - + } else if ((record.tnf == NET_NFC_RECORD_MIME_TYPE)) { FILE *file = NULL; /* open file : size limit? 10k? */ @@ -825,26 +786,23 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag _nfc_emul_util_alloc_mem(file_data, file_len); - if (file_data == NULL) - { + if (file_data == NULL) { DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); fclose(file); goto ERROR; } /* create payload */ - do - { + do { read_count = fread(file_data + read_total, 1, file_len - read_total, file); read_total += read_count; - } - while (read_count != 0 && read_total < file_len); + } while (read_count != 0 && read_total < file_len); fclose(file); DEBUG_MSG("fread(%s) success, size %ld", record.payload.buffer, file_len); - filePayload.length= file_len; + filePayload.length = file_len; _nfc_emul_util_alloc_mem(filePayload.buffer, filePayload.length); if (filePayload.buffer == NULL) { @@ -861,15 +819,13 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag char *file_name = NULL; file_name = strrchr(record_payload, '/'); - if (file_name == NULL) { + if (file_name == NULL) file_name = (char *) record_payload; - } - else { + else file_name++; - } record.id.length = strlen(file_name); - _nfc_emul_util_alloc_mem(record.id.buffer, record.id.length); + _nfc_emul_util_alloc_mem(record.id.buffer, record.id.length + 1); if (record.id.buffer == NULL) { DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); @@ -878,51 +834,47 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag } memcpy(record.id.buffer, file_name, record.id.length); } - } - else { + } else { DEBUG_MSG("file open error"); goto ERROR;; } /* create record */ - if((result = net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &filePayload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { + if ((result = net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &filePayload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { DEBUG_MSG("net_nfc_create_record failed[%d]", result); goto ERROR;; } - } - else { + } else { /* NET_NFC_RECORD_URI or NET_NFC_RECORD_EXTERNAL_RTD */ - if((result = net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &record.payload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { + if ((result = net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &record.payload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { DEBUG_MSG("net_nfc_create_record failed[%d]", result); goto ERROR;; } } /* append record to ndef msg */ - if((result = net_nfc_util_append_record((ndef_message_s*) *ndef_message, (ndef_record_s *) new_record)) != NET_NFC_OK){ + if ((result = net_nfc_util_append_record((ndef_message_s*) *ndef_message, (ndef_record_s *) new_record)) != NET_NFC_OK) { DEBUG_MSG("net_nfc_util_append_record failed[%d]", result); goto ERROR;; } create_record_count++; DEBUG_MSG("Create Record Sucess. Create Record Count[%d]", create_record_count); -ERROR : - /* To Do : memory issue */ -#if 0 +ERROR: + /* free data */ - if (record.typeName.buffer != NULL) { + if (record.typeName.buffer != NULL) _nfc_emul_util_free_mem(record.typeName.buffer); - } - if (record.id.buffer != NULL) { + + if (record.id.buffer != NULL) _nfc_emul_util_free_mem(record.id.buffer); - } - if (record.payload.buffer != NULL) { + + if (record.payload.buffer != NULL) _nfc_emul_util_free_mem(record.payload.buffer); - } - if(filePayload.buffer != NULL) { + + if (filePayload.buffer != NULL) _nfc_emul_util_free_mem(filePayload.buffer); - } -#endif + DEBUG_MSG("Create Record Loop End"); } @@ -951,9 +903,7 @@ static bool _net_nfc_change_file_owner_permission(FILE *file) /* 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) @@ -965,9 +915,7 @@ static bool _net_nfc_change_file_owner_permission(FILE *file) /* 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) @@ -976,12 +924,9 @@ static bool _net_nfc_change_file_owner_permission(FILE *file) getgrnam_r("inhouse", &grp, buffer, buffer_len, &gr_inhouse); _net_nfc_util_free_mem(buffer); - if ((pw_inhouse != NULL) && (gr_inhouse != NULL)) - { + if ((pw_inhouse != NULL) && (gr_inhouse != NULL)) { if (fchown(fileno(file), pw_inhouse->pw_uid, gr_inhouse->gr_gid) < 0) - { DEBUG_MSG("failed to change owner"); - } } return true; @@ -993,9 +938,7 @@ static void _net_nfc_store_ndef_message(data_s *data) FILE *fp = NULL; if (data == NULL) - { return; - } /* create file */ snprintf(file_name, sizeof(file_name), "%s/%s/%s", "/opt/usr/share/nfc-manager-daemon", @@ -1003,20 +946,16 @@ static void _net_nfc_store_ndef_message(data_s *data) unlink(file_name); - if ((fp = fopen(file_name, "w")) != NULL) - { + if ((fp = fopen(file_name, "w")) != NULL) { int length = 0; - if ((length = fwrite(data->buffer, 1, data->length, fp)) > 0) - { + if ((length = fwrite(data->buffer, 1, data->length, fp)) > 0) { DEBUG_MSG("[%d] bytes is written", length); _net_nfc_change_file_owner_permission(fp); fflush(fp); fsync(fileno(fp)); - } - else - { + } else { DEBUG_MSG("write is failed = [%d]", data->length); } @@ -1031,16 +970,13 @@ static net_nfc_error_e _net_nfc_retrieve_ndef_message(data_s *data) net_nfc_error_e result = NET_NFC_OK; if (data == NULL) - { return NET_NFC_NULL_PARAMETER; - } /* retreive file */ snprintf(file_name, sizeof(file_name), "%s/%s/%s", "/opt/usr/share/nfc-manager-daemon", "message", "emul-ndef-message.txt"); - if ((fp = fopen(file_name, "r")) != NULL) - { + if ((fp = fopen(file_name, "r")) != NULL) { long int size = 0; /* rewind to start of file */ @@ -1050,10 +986,8 @@ static net_nfc_error_e _net_nfc_retrieve_ndef_message(data_s *data) DEBUG_MSG("message length = [%ld]", size); - if (size > 0) - { - if (net_nfc_util_init_data(data, size) == true) - { + if (size > 0) { + if (net_nfc_util_init_data(data, size) == true) { int current; size_t offset = 0; @@ -1067,26 +1001,19 @@ static net_nfc_error_e _net_nfc_retrieve_ndef_message(data_s *data) break; } while (offset < data->length); - if (offset == data->length) { + if (offset == data->length) result = NET_NFC_OK; - } else { + else result = NET_NFC_NO_NDEF_MESSAGE; - } - } - else - { + } else { result = NET_NFC_ALLOC_FAIL; } - } - else - { + } else { result = NET_NFC_OPERATION_FAIL; } fclose(fp); - } - else - { + } else { result = NET_NFC_NO_DATA_FOUND; } @@ -1097,9 +1024,8 @@ static bool _net_nfc_create_ndef_from_emulMsg(emulMsg_s *emul_msg) { DEBUG_EMUL_BEGIN(); - if (emul_msg->file_data == NULL) { + if (emul_msg->file_data == NULL) return false; - } int retval = true; net_nfc_error_e result = NET_NFC_OK; @@ -1107,37 +1033,31 @@ static bool _net_nfc_create_ndef_from_emulMsg(emulMsg_s *emul_msg) int record_count = emul_msg->record_count; - if(record_count == 0) { + if (record_count == 0) return false; - } /* create ndef msg */ ndef_message_h ndef_message = NULL; int ndef_length = 0; - if((result = net_nfc_util_create_ndef_message ((ndef_message_s **) &ndef_message)) != NET_NFC_OK) - { + if ((result = net_nfc_util_create_ndef_message((ndef_message_s **) &ndef_message)) != NET_NFC_OK) DEBUG_MSG("failed to create ndef message [%d]", result); - } /* create records and append it to ndef_msg*/ emul_msg->record_count = _net_nfc_create_records_from_emulMsg(emul_msg, (ndef_message_s **) &ndef_message, record_count); /* convert ndef msg to raw data */ - ndef_length = net_nfc_util_get_ndef_message_length ((ndef_message_s *) ndef_message); + ndef_length = net_nfc_util_get_ndef_message_length((ndef_message_s *) ndef_message); - if (!ndef_length){ + if (!ndef_length) DEBUG_MSG("ndef_message size is zero!"); - } rawdata.length = ndef_length; _nfc_emul_util_alloc_mem(rawdata.buffer, ndef_length); - if((result = net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s*)ndef_message, &rawdata)) != NET_NFC_OK) { + if ((result = net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s*)ndef_message, &rawdata)) != NET_NFC_OK) DEBUG_MSG("net_nfc_util_convert_ndef_message_to_rawdata is failed![%d]", result); - } - _net_nfc_store_ndef_message(&rawdata); _nfc_emul_util_free_mem(rawdata.buffer); @@ -1155,14 +1075,13 @@ static bool _net_nfc_create_emulMsg(emulMsg_s **emul_msg, uint8_t * data, long i char *emulMsgData; *emul_msg = (emulMsg_s *)calloc(1, sizeof(emulMsg_s)); - if(*emul_msg == NULL) + if (*emul_msg == NULL) return false; /* emulData => ID : MSG ex) 100:1,1,1,U,samsung,http://www.naver.com */ emulMsgID = strtok((char *)data, NET_NFC_EMUL_MSG_ID_SEPERATOR); - if (emulMsgID != NULL) { + if (emulMsgID != NULL) (*emul_msg)->message_id = (emul_message_id) (atoi(emulMsgID)); - } DEBUG_MSG("emul_msg->message_id >>>>[%d]", (*emul_msg)->message_id); @@ -1172,80 +1091,66 @@ static bool _net_nfc_create_emulMsg(emulMsg_s **emul_msg, uint8_t * data, long i DEBUG_MSG("emulMsgData >>>>[%s]", emulMsgData); switch ((*emul_msg)->message_id) { - case EMUL_NFC_TAG_DISCOVERED : - case EMUL_NFC_P2P_SEND : - { - /* get message : Tag Type, Record Count, Records */ - int target_type = -1; - char file_data[BUFFER_LENGTH_MAX]={ 0, }; - int length =0; - - sscanf(emulMsgData, NET_NFC_EMUL_TAG_DISCOVERED_DATA_FORMAT, &target_type, &((*emul_msg)->record_count), file_data); - - (*emul_msg)->target_type = (emul_target_type) target_type; - - length = strlen(file_data)+1; - _nfc_emul_util_alloc_mem((*emul_msg)->file_data, length); - memcpy((*emul_msg)->file_data, file_data, length); - - DEBUG_ERR_MSG("EMUL MESSAGE DATA START >>>>>>>>>>>>>>>>>>>>>>>>"); - DEBUG_MSG("message_id >>>>[%d]", (*emul_msg)->message_id); - DEBUG_MSG("target_type >>>>[%d]", (*emul_msg)->target_type); - DEBUG_MSG("record_count >>>>[%d]", (*emul_msg)->record_count); - DEBUG_MSG("file_data >>>>[%s]", (char *)(*emul_msg)->file_data); - DEBUG_ERR_MSG("EMUL MESSAGE DATA END >>>>>>>>>>>>>>>>>>>>>>>>"); - - if ( !_net_nfc_create_ndef_from_emulMsg((*emul_msg))) { - DEBUG_ERR_MSG("read ndef_msg is failed >>>"); - } + case EMUL_NFC_TAG_DISCOVERED: + case EMUL_NFC_P2P_SEND: + /* get message : Tag Type, Record Count, Records */ + int target_type = -1; + char file_data[BUFFER_LENGTH_MAX] = {0, }; + int length = 0; - DEBUG_ERR_MSG("_net_nfc_create_ndef_from_emulMsg end"); - } - break; + sscanf(emulMsgData, NET_NFC_EMUL_TAG_DISCOVERED_DATA_FORMAT, &target_type, &((*emul_msg)->record_count), file_data); - default : { - /* exception case */ - DEBUG_ERR_MSG("_net_nfc_set_emulMsg error. Data is currupted"); - return false; - } + (*emul_msg)->target_type = (emul_target_type) target_type; + + length = strlen(file_data)+1; + _nfc_emul_util_alloc_mem((*emul_msg)->file_data, length); + memcpy((*emul_msg)->file_data, file_data, length); + + DEBUG_ERR_MSG("EMUL MESSAGE DATA START >>>>>>>>>>>>>>>>>>>>>>>>"); + DEBUG_MSG("message_id >>>>[%d]", (*emul_msg)->message_id); + DEBUG_MSG("target_type >>>>[%d]", (*emul_msg)->target_type); + DEBUG_MSG("record_count >>>>[%d]", (*emul_msg)->record_count); + DEBUG_MSG("file_data >>>>[%s]", (char *)(*emul_msg)->file_data); + DEBUG_ERR_MSG("EMUL MESSAGE DATA END >>>>>>>>>>>>>>>>>>>>>>>>"); + + if (!_net_nfc_create_ndef_from_emulMsg((*emul_msg))) + DEBUG_ERR_MSG("read ndef_msg is failed >>>"); + + DEBUG_ERR_MSG("_net_nfc_create_ndef_from_emulMsg end"); break; + default: + /* exception case */ + DEBUG_ERR_MSG("_net_nfc_set_emulMsg error. Data is currupted"); + return false; + break; } - } - else { - + } else { switch ((*emul_msg)->message_id) { - case EMUL_NFC_P2P_DISCOVERED :{ - (*emul_msg)->target_type = EMUL_NFC_TARGET; - } + case EMUL_NFC_P2P_DISCOVERED: + (*emul_msg)->target_type = EMUL_NFC_TARGET; break; - case EMUL_NFC_TAG_DETACHED :{ - DEBUG_MSG("TAG DETACHED"); - if(!_net_nfc_emul_get_is_tag_attached()) - { - DEBUG_ERR_MSG("tag is not attached!!"); - return false; - } + case EMUL_NFC_TAG_DETACHED: + DEBUG_MSG("TAG DETACHED"); + if (!_net_nfc_emul_get_is_tag_attached()) { + DEBUG_ERR_MSG("tag is not attached!!"); + return false; } break; - case EMUL_NFC_P2P_DETACHED :{ - DEBUG_MSG("P2P DETACHED"); - if(!_net_nfc_emul_get_is_p2p_attached()) - { - DEBUG_ERR_MSG("tag is not attached!!"); - return false; - } + case EMUL_NFC_P2P_DETACHED: + DEBUG_MSG("P2P DETACHED"); + if (!_net_nfc_emul_get_is_p2p_attached()) { + DEBUG_ERR_MSG("tag is not attached!!"); + return false; } - break; - default : { - /* exception case */ - DEBUG_ERR_MSG("_net_nfc_set_emulMsg error. Data is currupted"); - return false; - } + default: + /* exception case */ + DEBUG_ERR_MSG("_net_nfc_set_emulMsg error. Data is currupted"); + return false; break; } } @@ -1259,9 +1164,8 @@ static void _net_nfc_destroy_emulMsg(emulMsg_s *emul_msg) { DEBUG_EMUL_BEGIN(); - if(emul_msg != NULL) - { - if(emul_msg->file_data != NULL) + if (emul_msg != NULL) { + if (emul_msg->file_data != NULL) free(emul_msg->file_data); free(emul_msg); @@ -1277,32 +1181,31 @@ static int _net_nfc_emul_convert_target_type(emul_target_type targetType) int covert = 0; switch (targetType) { - case EMUL_TAG_TOPAZ_JEWEL : - covert = NET_NFC_JEWEL_PICC; + case EMUL_TAG_TOPAZ_JEWEL: + covert = NET_NFC_JEWEL_PICC; break; - case EMUL_TAG_MIFARE_UL : - covert = NET_NFC_MIFARE_ULTRA_PICC; + case EMUL_TAG_MIFARE_UL: + covert = NET_NFC_MIFARE_ULTRA_PICC; break; - case EMUL_TAG_FELICA : - covert = NET_NFC_FELICA_PICC; + case EMUL_TAG_FELICA: + covert = NET_NFC_FELICA_PICC; break; - case EMUL_TAG_MIFARE_DESFIRE : - covert = NET_NFC_MIFARE_DESFIRE_PICC; + case EMUL_TAG_MIFARE_DESFIRE: + covert = NET_NFC_MIFARE_DESFIRE_PICC; break; - case EMUL_NFC_TARGET : - covert = NET_NFC_NFCIP1_TARGET; + case EMUL_NFC_TARGET: + covert = NET_NFC_NFCIP1_TARGET; break; - case EMUL_TARGET_TYPE_MAX : - default: - /* exception case */ - DEBUG_ERR_MSG("_net_nfc_emul_convert_target_type error. Target type is unknown"); + case EMUL_TARGET_TYPE_MAX: + default: + /* exception case */ + DEBUG_ERR_MSG("_net_nfc_emul_convert_target_type error. Target type is unknown"); break; - } DEBUG_MSG("covert [%d]", covert); @@ -1320,10 +1223,9 @@ static void _net_nfc_target_discovered_cb(emulMsg_s *emul_msg) net_nfc_target_handle_s* handle = NULL; int length = 0; - __net_nfc_make_valid_target_handle (&handle); - if(handle == NULL) { + __net_nfc_make_valid_target_handle(&handle); + if (handle == NULL) return; - } /* make msg */ net_nfc_request_target_detected_t* target_detected = NULL; @@ -1338,9 +1240,7 @@ static void _net_nfc_target_discovered_cb(emulMsg_s *emul_msg) length = sizeof(net_nfc_request_target_detected_t) + sizeof(device_info); _nfc_emul_util_alloc_mem(target_detected, length); if (target_detected == NULL) - { return; - } target_detected->length = length; target_detected->request_type = NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED; @@ -1355,18 +1255,15 @@ static void _net_nfc_target_discovered_cb(emulMsg_s *emul_msg) target_detected->handle->connection_id = current_connection_id++; - if(target_detected->devType == NET_NFC_NFCIP1_TARGET ){ + if (target_detected->devType == NET_NFC_NFCIP1_TARGET) { DEBUG_MSG("set llcp connection type. remote device is target"); handle->connection_type = NET_NFC_P2P_CONNECTION_TARGET; _net_nfc_emul_set_is_p2p_attached(true); - } - else if ( target_detected->devType == NET_NFC_NFCIP1_INITIATOR){ + } else if (target_detected->devType == NET_NFC_NFCIP1_INITIATOR) { DEBUG_MSG("set llcp connection type. remote device is initiator"); handle->connection_type = NET_NFC_P2P_CONNECTION_INITIATOR; _net_nfc_emul_set_is_p2p_attached(true); - } - else - { + } else { DEBUG_MSG("set tag connection"); handle->connection_type = NET_NFC_TAG_CONNECTION; _net_nfc_emul_set_is_tag_attached(true); @@ -1377,7 +1274,7 @@ static void _net_nfc_target_discovered_cb(emulMsg_s *emul_msg) memcpy(&target_detected->target_info_values.buffer, device_info, target_detected->target_info_values.length); /* call target_cb */ - if(g_emul_controller_target_cb != NULL) { + if (g_emul_controller_target_cb != NULL) { DEBUG_MSG("discovered callback is called"); g_emul_controller_target_cb(target_detected, NULL); } @@ -1441,7 +1338,7 @@ static void _net_nfc_llcp_data_receive_from_cb(void* pContext) _nfc_emul_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t)); - if (req_msg != NULL){ + if (req_msg != NULL) { req_msg->length = sizeof(net_nfc_request_llcp_msg_t); req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM; req_msg->result = NET_NFC_OK; @@ -1468,7 +1365,7 @@ static void _net_nfc_llcp_create_snep_server_msg(snep_command_field_e resp_field _net_nfc_retrieve_ndef_message(&rawdata); - /* version response length payload*/ + /* version response length payload*/ Snep_Server_msg->data->length = sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t) + rawdata.length; /* copy version */ @@ -1486,7 +1383,7 @@ static void _net_nfc_llcp_create_snep_server_msg(snep_command_field_e resp_field temp += sizeof(uint32_t); /* copy ndef information to response msg */ - if(rawdata.length > 0) + if (rawdata.length > 0) memcpy(temp, rawdata.buffer, rawdata.length); _nfc_emul_util_free_mem(rawdata.buffer); @@ -1514,8 +1411,7 @@ static bool _net_nfc_make_llcp_data(emulMsg_s *emul_msg) _net_nfc_retrieve_ndef_message(&rawdata); _nfc_emul_util_free_mem(rawdata.buffer); - if (emul_msg->record_count == 0 || rawdata.length == 0) - { + if (emul_msg->record_count == 0 || rawdata.length == 0) { DEBUG_ERR_MSG("data is zero >>>"); return false; } @@ -1532,13 +1428,11 @@ static bool _net_nfc_make_llcp_data(emulMsg_s *emul_msg) llcp_server_data->length = Snep_Server_msg->data->length; memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer, Snep_Server_msg->data->length); - } - else { + } else { DEBUG_MSG("send first segment >>>"); - if (llcp_server_data == NULL) { + if (llcp_server_data == NULL) return false; - } llcp_server_data->length = SNEP_MAX_BUFFER; memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer, SNEP_MAX_BUFFER); @@ -1557,61 +1451,52 @@ static void _net_nfc_send_emulMsg_to_nfc_manager(emulMsg_s *emul_msg) DEBUG_EMUL_BEGIN(); switch (emul_msg->message_id) { - case EMUL_NFC_TAG_DISCOVERED :{ - _net_nfc_target_discovered_cb(emul_msg); - } + case EMUL_NFC_TAG_DISCOVERED: + _net_nfc_target_discovered_cb(emul_msg); break; - case EMUL_NFC_TAG_DETACHED :{ - _net_nfc_tag_detached_cb(); - } + case EMUL_NFC_TAG_DETACHED: + _net_nfc_tag_detached_cb(); break; - case EMUL_NFC_P2P_DISCOVERED : { - _net_nfc_initialize_llcp(); - _net_nfc_target_discovered_cb(emul_msg); - } + case EMUL_NFC_P2P_DISCOVERED: + _net_nfc_initialize_llcp(); + _net_nfc_target_discovered_cb(emul_msg); break; - case EMUL_NFC_P2P_SEND : { - if(!_net_nfc_emul_get_is_p2p_attached()) - { - DEBUG_ERR_MSG("target is not attached!!"); - return; - } - - if(_net_nfc_make_llcp_data(emul_msg)) { - - /* find snep server*/ - socket_info_s *socket_info = _net_nfc_find_server_socket(NET_NFC_EMUL_SNEP_SERVER_SOCKET_NUMBER); - if (socket_info == NULL) { - DEBUG_ERR_MSG ("socket_info is NULL"); - return; - } + case EMUL_NFC_P2P_SEND: + if (!_net_nfc_emul_get_is_p2p_attached()) { + DEBUG_ERR_MSG("target is not attached!!"); + return; + } - _net_nfc_llcp_data_receive_cb(socket_info->user_context); /* call callback */ - } - else { - DEBUG_ERR_MSG("make_p2p_data is fail!!"); + if (_net_nfc_make_llcp_data(emul_msg)) { + /* find snep server*/ + socket_info_s *socket_info = _net_nfc_find_server_socket(NET_NFC_EMUL_SNEP_SERVER_SOCKET_NUMBER); + if (socket_info == NULL) { + DEBUG_ERR_MSG("socket_info is NULL"); return; } + + _net_nfc_llcp_data_receive_cb(socket_info->user_context); /* call callback */ + } else { + DEBUG_ERR_MSG("make_p2p_data is fail!!"); + return; } break; - case EMUL_NFC_P2P_DETACHED : { - if(!_net_nfc_emul_get_is_p2p_attached()) - { - DEBUG_ERR_MSG("target is not attached!!"); - return; - } - - _net_nfc_target_detached_cb(); - _net_nfc_deinitialize_llcp(); + case EMUL_NFC_P2P_DETACHED: + if (!_net_nfc_emul_get_is_p2p_attached()) { + DEBUG_ERR_MSG("target is not attached!!"); + return; } + + _net_nfc_target_detached_cb(); + _net_nfc_deinitialize_llcp(); break; - default : - DEBUG_ERR_MSG("message_id is wrong!!"); + default: + DEBUG_ERR_MSG("message_id is wrong!!"); break; } @@ -1651,7 +1536,7 @@ static void emul_ReaderThread(void * pArg) struct epoll_event *emulMsg_poll_events = NULL; /* make file name */ - snprintf(file_name, sizeof(file_name), "%s/%s", NET_NFC_EMUL_DATA_PATH, NET_NFC_EMUL_MESSAGE_FILE_NAME ); + snprintf(file_name, sizeof(file_name), "%s/%s", NET_NFC_EMUL_DATA_PATH, NET_NFC_EMUL_MESSAGE_FILE_NAME); LOGE("file path : %s", file_name); /* open file for poll */ @@ -1662,15 +1547,13 @@ static void emul_ReaderThread(void * pArg) } /* create epoll */ - if((emulMsg_poll_fd = epoll_create1(EPOLL_CLOEXEC)) == -1) - { + if ((emulMsg_poll_fd = epoll_create1(EPOLL_CLOEXEC)) == -1) { DEBUG_MSG("epoll_create1 is occured"); close(emulMsg_file_fd); return; } - if((emulMsg_poll_events = (struct epoll_event *)calloc(1, sizeof(struct epoll_event) * EPOLL_SIZE)) == NULL) - { + if ((emulMsg_poll_events = (struct epoll_event *)calloc(1, sizeof(struct epoll_event) * EPOLL_SIZE)) == NULL) { DEBUG_MSG("calloc is occured"); close(emulMsg_file_fd); return; @@ -1688,29 +1571,23 @@ static void emul_ReaderThread(void * pArg) while (condition == true) { int num_of_files = 0; - int index =0 ; + int index = 0; /* to do : I will add mutex in the future */ /* lock mutex */ DEBUG_MSG("epoll wait >>>>"); - while((num_of_files = epoll_wait(emulMsg_poll_fd, emulMsg_poll_events, EPOLL_SIZE, -1)) == 0) { + while ((num_of_files = epoll_wait(emulMsg_poll_fd, emulMsg_poll_events, EPOLL_SIZE, -1)) == 0) DEBUG_MSG("no data is changed "); - } - for(index = 0; index < num_of_files; index++) - { - if( (emulMsg_poll_events[index].events & (EPOLLHUP)) || (emulMsg_poll_events[index].events & (EPOLLERR))) - { + for (index = 0; index < num_of_files; index++) { + if ((emulMsg_poll_events[index].events & (EPOLLHUP)) || (emulMsg_poll_events[index].events & (EPOLLERR))) { DEBUG_MSG("connection is closed"); condition = 0; - } - else if(emulMsg_poll_events[index].events & EPOLLIN) - { - if(emulMsg_poll_events[index].data.fd == emulMsg_file_fd) - { + } else if (emulMsg_poll_events[index].events & EPOLLIN) { + if (emulMsg_poll_events[index].data.fd == emulMsg_file_fd) { char readbuffer[READ_BUFFER_LENGTH_MAX]; int readcnt = 0; @@ -1723,19 +1600,14 @@ static void emul_ReaderThread(void * pArg) DEBUG_MSG("message readcnt= [%d] ", readcnt); DEBUG_MSG("message = [%s] ", readbuffer); - /* remove header */ + /* remove header */ _net_nfc_process_emulMsg((uint8_t *)readbuffer + NET_NFC_EMUL_HEADER_LENGTH, (long int)readcnt - NET_NFC_EMUL_HEADER_LENGTH); - } - else - { + } else { DEBUG_MSG("not expected socket connection"); condition = 0; } - } - else - { - if(num_of_files == index) - { + } else { + if (num_of_files == index) { DEBUG_MSG("unknown event"); condition = 0; } @@ -1750,6 +1622,9 @@ static void emul_ReaderThread(void * pArg) close(emulMsg_file_fd); + if (emulMsg_poll_events != NULL) + free(emulMsg_poll_events); + DEBUG_MSG("emul_ReaderThread END >>>>"); } @@ -1771,7 +1646,7 @@ static void emul_ReaderThread(void * pArg) bool condition = true; /* make file name */ - snprintf(file_name, sizeof(file_name), "%s/%s", NET_NFC_EMUL_DATA_PATH, NET_NFC_EMUL_MESSAGE_FILE_NAME ); + snprintf(file_name, sizeof(file_name), "%s/%s", NET_NFC_EMUL_DATA_PATH, NET_NFC_EMUL_MESSAGE_FILE_NAME); LOGE("file path : %s", file_name); time(&curTime); @@ -1780,30 +1655,26 @@ static void emul_ReaderThread(void * pArg) /* polling 500 ms */ while (condition != 0) { - usleep(500 * 1000); /* open file */ if ((fp = fopen(file_name, "r")) == NULL) { DEBUG_MSG("file open error"); condition = false; - } - else { + } else { /* get the modified time of the file */ - if (stat(file_name, &st) ==0) { + if (stat(file_name, &st) == 0) { if ((unsigned long) st.st_mtime <= (unsigned long) curTime) { fclose(fp); continue; - } - else { + } else { DEBUG_MSG("FILE Modified Time [%ld]", (unsigned long) st.st_mtime); /* update current time */ time(&curTime); DEBUG_MSG("Get New Current Time [%ld]", (unsigned long) curTime); } - } - else { + } else { DEBUG_MSG("stat error"); fclose(fp); continue; @@ -1812,9 +1683,8 @@ static void emul_ReaderThread(void * pArg) /* read data */ memset(readBuffer, 0x00, READ_BUFFER_LENGTH_MAX); - if (fscanf(fp, "%[^\n]", readBuffer)) { + if (fscanf(fp, "%[^\n]", readBuffer)) DEBUG_MSG("get DATA >>>> readBuffer [%s]", readBuffer); - } /* process message */ _net_nfc_process_emulMsg((uint8_t *) readBuffer, (long int) strlen(readBuffer)); @@ -1830,7 +1700,7 @@ static void emul_ReaderThread(void * pArg) } #endif -static bool _net_nfc_emul_controller_start_thread (void) +static bool _net_nfc_emul_controller_start_thread(void) { bool ret = true; @@ -1838,7 +1708,7 @@ static bool _net_nfc_emul_controller_start_thread (void) ret = pthread_create(&gEmulThread, NULL, (emul_Nfc_thread_handler_t)emul_ReaderThread, (void*) "emul_read_thread"); - if(ret != 0) + if (ret != 0) return false; DEBUG_EMUL_END(); @@ -1846,7 +1716,7 @@ static bool _net_nfc_emul_controller_start_thread (void) return true; } -static void _net_nfc_emul_controller_stop_thread (void) +static void _net_nfc_emul_controller_stop_thread(void) { DEBUG_EMUL_BEGIN(); @@ -1861,20 +1731,18 @@ static void _net_nfc_emul_controller_stop_thread (void) DEBUG_EMUL_END(); } -static bool net_nfc_emul_controller_init (net_nfc_error_e* result) +static bool net_nfc_emul_controller_init(net_nfc_error_e* result) { bool ret = true; - if (result == NULL) { + if (result == NULL) return false; - } DEBUG_EMUL_BEGIN(); DEBUG_MSG("start stack init "); - if (g_stack_init_successful == true) - { + if (g_stack_init_successful == true) { DEBUG_MSG("Already statck is initialized"); return true; } @@ -1896,13 +1764,12 @@ static bool net_nfc_emul_controller_init (net_nfc_error_e* result) return ret; } -static bool net_nfc_emul_controller_deinit (void) +static bool net_nfc_emul_controller_deinit(void) { DEBUG_EMUL_BEGIN(); /* End thread */ - if (g_stack_init_successful == false) - { + if (g_stack_init_successful == false) { DEBUG_MSG("Already statck is deinitialized"); return true; } @@ -1922,9 +1789,8 @@ static bool net_nfc_emul_controller_register_listener( hce_apdu_listener_cb hce_apdu_listener, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -1956,9 +1822,7 @@ static bool net_nfc_emul_controller_unregister_listener() static bool net_nfc_emul_controller_get_firmware_version(data_s **data, net_nfc_error_e *result) { if (data == NULL || result == NULL) - { return false; - } *result = NET_NFC_OK; @@ -1966,7 +1830,7 @@ static bool net_nfc_emul_controller_get_firmware_version(data_s **data, net_nfc_ *data = (data_s *)calloc(1, sizeof(data_s)); - if(*data == NULL) + if (*data == NULL) return false; (*data)->length = 10; @@ -1981,9 +1845,8 @@ static bool net_nfc_emul_controller_get_firmware_version(data_s **data, net_nfc_ static bool net_nfc_emul_controller_check_firmware_version(net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -1996,9 +1859,8 @@ static bool net_nfc_emul_controller_check_firmware_version(net_nfc_error_e* resu static bool net_nfc_emul_controller_update_firmware(net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2011,9 +1873,8 @@ static bool net_nfc_emul_controller_update_firmware(net_nfc_error_e* result) static bool net_nfc_emul_controller_get_stack_information(net_nfc_stack_information_s* stack_info, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2024,49 +1885,38 @@ static bool net_nfc_emul_controller_get_stack_information(net_nfc_stack_informat return true; } -static bool net_nfc_emul_controller_configure_discovery (net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result) +static bool net_nfc_emul_controller_configure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result) { int idx; bool ret = true; if (result == NULL) - { return false; - } *result = NET_NFC_OK; - if (mode == NET_NFC_DISCOVERY_MODE_START) - { + if (mode == NET_NFC_DISCOVERY_MODE_START) { mode = NET_NFC_DISCOVERY_MODE_CONFIG; - } - else if (mode == NET_NFC_DISCOVERY_MODE_STOP) - { + } else if (mode == NET_NFC_DISCOVERY_MODE_STOP) { mode = NET_NFC_DISCOVERY_MODE_CONFIG; config = NET_NFC_ALL_DISABLE; } DEBUG_EMUL_BEGIN(); - if ((mode == NET_NFC_DISCOVERY_MODE_CONFIG)) - { - if (config == NET_NFC_ALL_DISABLE) - { + if ((mode == NET_NFC_DISCOVERY_MODE_CONFIG)) { + if (config == NET_NFC_ALL_DISABLE) { /* This handle is not useful anymore */ - __net_nfc_make_invalid_target_handle (); + __net_nfc_make_invalid_target_handle(); /* reset socket_info */ for (idx = 0; idx < LLCP_NB_SOCKET_MAX; idx++) - { _net_nfc_remove_socket_slot((net_nfc_llcp_socket_t) idx); - } DEBUG_MSG("Kill Thread"); ret = net_nfc_emul_controller_deinit(); - } - else if(config == NET_NFC_ALL_ENABLE) - { + } else if (config == NET_NFC_ALL_ENABLE) { net_nfc_error_e err; DEBUG_MSG("Create Thread"); @@ -2081,9 +1931,8 @@ static bool net_nfc_emul_controller_configure_discovery (net_nfc_discovery_mode_ static bool net_nfc_emul_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2096,9 +1945,8 @@ static bool net_nfc_emul_controller_get_secure_element_list(net_nfc_secure_eleme static bool net_nfc_emul_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 (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2111,9 +1959,8 @@ static bool net_nfc_emul_controller_set_secure_element_mode(net_nfc_secure_eleme static bool net_nfc_emul_controller_check_target_presence(net_nfc_target_handle_s* handle, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2121,8 +1968,7 @@ static bool net_nfc_emul_controller_check_target_presence(net_nfc_target_handle_ if (_net_nfc_emul_get_is_tag_attached()) { return true; - } - else { + } else { DEBUG_MSG("TAG Detached"); return false; } @@ -2130,9 +1976,8 @@ static bool net_nfc_emul_controller_check_target_presence(net_nfc_target_handle_ static bool net_nfc_emul_controller_connect(net_nfc_target_handle_s* handle, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2150,9 +1995,8 @@ static bool net_nfc_emul_controller_connect(net_nfc_target_handle_s* handle, net static bool net_nfc_emul_controller_disconnect(net_nfc_target_handle_s* handle, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2164,14 +2008,12 @@ static bool net_nfc_emul_controller_disconnect(net_nfc_target_handle_s* handle, } // This handle is not useful anymore - __net_nfc_make_invalid_target_handle (); + __net_nfc_make_invalid_target_handle(); /* reset socket_info */ int idx = 0; for (; idx < LLCP_NB_SOCKET_MAX; idx++) - { _net_nfc_remove_socket_slot((net_nfc_llcp_socket_t) idx); - } DEBUG_EMUL_END(); @@ -2182,14 +2024,12 @@ static bool net_nfc_emul_controller_check_ndef(net_nfc_target_handle_s* handle, { data_s rawdata = { NULL, 0 }; - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; - if (handle == NULL || ndef_card_state == NULL || max_data_size == NULL || real_data_size == NULL || result == NULL) - { + if (handle == NULL || ndef_card_state == NULL || max_data_size == NULL || real_data_size == NULL || result == NULL) { *result = NET_NFC_NULL_PARAMETER; return false; } @@ -2204,15 +2044,12 @@ static bool net_nfc_emul_controller_check_ndef(net_nfc_target_handle_s* handle, _net_nfc_retrieve_ndef_message(&rawdata); _nfc_emul_util_free_mem(rawdata.buffer); - if (_net_nfc_emul_get_is_tag_attached()) - { + if (_net_nfc_emul_get_is_tag_attached()) { *ndef_card_state = NET_NFC_NDEF_CARD_READ_WRITE; *max_data_size = BUFFER_LENGTH_MAX; *real_data_size = rawdata.length; DEBUG_MSG("Card State : [%d] MAX data size :[%d] actual data size = [%d]", *ndef_card_state, *max_data_size, *real_data_size); - } - else - { + } else { DEBUG_MSG("target detached"); } @@ -2223,9 +2060,8 @@ static bool net_nfc_emul_controller_check_ndef(net_nfc_target_handle_s* handle, static bool net_nfc_emul_controller_make_read_only_ndef(net_nfc_target_handle_s* handle, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2248,14 +2084,12 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d DEBUG_EMUL_BEGIN(); - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; - if(handle == NULL || data == NULL || result == NULL) - { + if (handle == NULL || data == NULL || result == NULL) { DEBUG_ERR_MSG("NET_NFC_NULL_PARAMETER >>>"); *result = NET_NFC_NULL_PARAMETER; return false; @@ -2267,23 +2101,21 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d return false; } - if(!_net_nfc_emul_get_is_tag_attached()) { + if (!_net_nfc_emul_get_is_tag_attached()) { DEBUG_ERR_MSG("NET_NFC_NOT_ALLOWED_OPERATION >>>"); *result = NET_NFC_NOT_ALLOWED_OPERATION; return false; } *result = _net_nfc_retrieve_ndef_message(&rawdata); - if(*result != NET_NFC_OK) - { + if (*result != NET_NFC_OK) { _nfc_emul_util_free_mem(rawdata.buffer); return false; } real_data_size = rawdata.length; - if(real_data_size == 0) - { + if (real_data_size == 0) { DEBUG_ERR_MSG("read ndef_msg is failed >>> real_data_size is zero"); *result = NET_NFC_NO_NDEF_MESSAGE; _nfc_emul_util_free_mem(rawdata.buffer); @@ -2292,8 +2124,7 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d *data = (data_s*) calloc(1, sizeof(data_s)); - if(*data == NULL) - { + if (*data == NULL) { *result = NET_NFC_ALLOC_FAIL; _nfc_emul_util_free_mem(rawdata.buffer); return false; @@ -2302,8 +2133,7 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d (*data)->length = real_data_size; (*data)->buffer = (uint8_t *)calloc(1, real_data_size); - if((*data)->buffer == NULL) - { + if ((*data)->buffer == NULL) { free(*data); *result = NET_NFC_ALLOC_FAIL; _nfc_emul_util_free_mem(rawdata.buffer); @@ -2321,9 +2151,8 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d static bool net_nfc_emul_controller_write_ndef(net_nfc_target_handle_s* handle, data_s* data, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2349,9 +2178,8 @@ static bool net_nfc_emul_controller_transceive(net_nfc_target_handle_s *handle, { bool ret = false; - if (result == NULL) { + if (result == NULL) return ret; - } if (info == NULL || info->trans_data.buffer == NULL || info->trans_data.length == 0) { @@ -2378,9 +2206,8 @@ static bool net_nfc_emul_controller_transceive(net_nfc_target_handle_s *handle, static bool net_nfc_emul_controller_format_ndef(net_nfc_target_handle_s* handle, data_s* secure_key, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2402,8 +2229,7 @@ static bool net_nfc_emul_controller_exception_handler(void) net_nfc_error_e error; - if(net_nfc_emul_controller_init(&error) == false) - { + if (net_nfc_emul_controller_init(&error) == false) { DEBUG_ERR_MSG("exception handler is failed!!"); exit(0xff); } @@ -2415,9 +2241,8 @@ static bool net_nfc_emul_controller_exception_handler(void) static bool net_nfc_emul_controller_is_ready(net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2433,11 +2258,10 @@ static bool net_nfc_emul_controller_is_ready(net_nfc_error_e* result) * LLCP definition * ********************/ -static bool net_nfc_emul_controller_llcp_config (net_nfc_llcp_config_info_s * config, net_nfc_error_e * result) +static bool net_nfc_emul_controller_llcp_config(net_nfc_llcp_config_info_s * config, net_nfc_error_e * result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2450,9 +2274,8 @@ static bool net_nfc_emul_controller_llcp_config (net_nfc_llcp_config_info_s * co static bool net_nfc_emul_controller_llcp_check_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2470,9 +2293,8 @@ static bool net_nfc_emul_controller_llcp_check_llcp(net_nfc_target_handle_s* han static bool net_nfc_emul_controller_llcp_activate_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2490,9 +2312,8 @@ static bool net_nfc_emul_controller_llcp_activate_llcp(net_nfc_target_handle_s* static bool net_nfc_emul_controller_llcp_create_socket(net_nfc_llcp_socket_t* socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e* result, void * user_param) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2500,7 +2321,7 @@ static bool net_nfc_emul_controller_llcp_create_socket(net_nfc_llcp_socket_t* so /* get available socket */ socket_info_s* socket_info = _net_nfc_get_available_socket_slot(); - if(socket_info == NULL) { + if (socket_info == NULL) { DEBUG_ERR_MSG("The available socket is nothing!!"); return false; } @@ -2517,28 +2338,23 @@ static bool net_nfc_emul_controller_llcp_create_socket(net_nfc_llcp_socket_t* so DEBUG_MSG("NET_NFC_STATE_EXCHANGER_SERVER"); *socket = NET_NFC_EMUL_SNEP_SERVER_SOCKET_NUMBER; - } - else if (llcp_state == NET_NFC_STATE_EXCHANGER_SERVER_NPP) { + } else if (llcp_state == NET_NFC_STATE_EXCHANGER_SERVER_NPP) { DEBUG_MSG("NET_NFC_STATE_EXCHANGER_SERVER_NPP"); *socket = NET_NFC_EMUL_NPP_SERVER_SOCKET_NUMBER; - } - else if (llcp_state == NET_NFC_STATE_EXCHANGER_CLIENT) { + } else if (llcp_state == NET_NFC_STATE_EXCHANGER_CLIENT) { DEBUG_MSG("NET_NFC_STATE_EXCHANGER_CLIENT"); *socket = NET_NFC_EMUL_CLIENT_SOCKET_NUMBER; - } - else if (llcp_state == NET_NFC_STATE_CONN_HANDOVER_REQUEST) { + } else if (llcp_state == NET_NFC_STATE_CONN_HANDOVER_REQUEST) { DEBUG_MSG("NET_NFC_STATE_CONN_HANDOVER_REQUEST"); *socket = NET_NFC_EMUL_HANDOVER_REQUEST_SOCKET_NUMBER; - } - else if (llcp_state == NET_NFC_STATE_CONN_HANDOVER_SELECT) { + } else if (llcp_state == NET_NFC_STATE_CONN_HANDOVER_SELECT) { DEBUG_MSG("NET_NFC_STATE_CONN_HANDOVER_SELECT"); *socket = NET_NFC_EMUL_HANDOVER_SELECT_SOCKET_NUMBER; - } - else { + } else { DEBUG_MSG("we doesn't support.."); return false; @@ -2556,9 +2372,8 @@ static bool net_nfc_emul_controller_llcp_create_socket(net_nfc_llcp_socket_t* so static bool net_nfc_emul_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2571,9 +2386,8 @@ static bool net_nfc_emul_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint static bool net_nfc_emul_controller_llcp_listen(net_nfc_target_handle_s* handle, uint8_t* service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2590,22 +2404,21 @@ static bool net_nfc_emul_controller_llcp_listen(net_nfc_target_handle_s* handle, socket_info_s *socket_info = _net_nfc_find_server_socket(socket); if (socket_info == NULL) { - DEBUG_ERR_MSG ("socket_info is NULL"); + DEBUG_ERR_MSG("socket_info is NULL"); return false; } llcp_state_e llcp_state = NET_NFC_STATE_UNKNOWN; llcp_state = _net_nfc_get_llcp_state(socket_info->user_context); if (llcp_state == NET_NFC_STATE_UNKNOWN) { - DEBUG_ERR_MSG ("llcp_state is NET_NFC_STATE_UNKNOWN"); + DEBUG_ERR_MSG("llcp_state is NET_NFC_STATE_UNKNOWN"); return false; } if (llcp_state == NET_NFC_STATE_EXCHANGER_SERVER) { _nfc_emul_util_alloc_mem(detail, sizeof(*detail)); - if(detail != NULL) - { + if (detail != NULL) { detail->length = sizeof(*detail); detail->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_LISTEN; @@ -2619,8 +2432,7 @@ static bool net_nfc_emul_controller_llcp_listen(net_nfc_target_handle_s* handle, DEBUG_MSG("accept callback is called"); g_emul_controller_llcp_cb(detail, socket_info->user_context); } - } - else { + } else { DEBUG_MSG("llcp_state is [%d]", llcp_state); } @@ -2632,9 +2444,8 @@ static bool net_nfc_emul_controller_llcp_listen(net_nfc_target_handle_s* handle, /* below accept function does not used. */ static bool net_nfc_emul_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void *user_param) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2647,9 +2458,8 @@ static bool net_nfc_emul_controller_llcp_accept(net_nfc_llcp_socket_t socket, ne static bool net_nfc_emul_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) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2662,14 +2472,14 @@ static bool net_nfc_emul_controller_llcp_connect(net_nfc_target_handle_s* handle socket_info_s *socket_info = _net_nfc_find_server_socket(socket); if (socket_info == NULL) { - DEBUG_ERR_MSG ("socket_info is NULL"); + DEBUG_ERR_MSG("socket_info is NULL"); return false; } llcp_state_e llcp_state = NET_NFC_STATE_UNKNOWN; llcp_state = _net_nfc_get_llcp_state(socket_info->user_context); if (llcp_state == NET_NFC_STATE_UNKNOWN) { - DEBUG_ERR_MSG ("llcp_state is NET_NFC_STATE_UNKNOWN"); + DEBUG_ERR_MSG("llcp_state is NET_NFC_STATE_UNKNOWN"); return false; } @@ -2678,11 +2488,10 @@ static bool net_nfc_emul_controller_llcp_connect(net_nfc_target_handle_s* handle return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_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) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2695,14 +2504,14 @@ static bool net_nfc_emul_controller_llcp_connect_by_url( net_nfc_target_handle_s socket_info_s *socket_info = _net_nfc_find_server_socket(socket); if (socket_info == NULL) { - DEBUG_ERR_MSG ("socket_info is NULL"); + DEBUG_ERR_MSG("socket_info is NULL"); return false; } llcp_state_e llcp_state = NET_NFC_STATE_UNKNOWN; llcp_state = _net_nfc_get_llcp_state(socket_info->user_context); if (llcp_state == NET_NFC_STATE_UNKNOWN) { - DEBUG_ERR_MSG ("llcp_state is NET_NFC_STATE_UNKNOWN"); + DEBUG_ERR_MSG("llcp_state is NET_NFC_STATE_UNKNOWN"); return false; } @@ -2713,9 +2522,8 @@ static bool net_nfc_emul_controller_llcp_connect_by_url( net_nfc_target_handle_s static bool net_nfc_emul_controller_llcp_send(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2728,25 +2536,25 @@ static bool net_nfc_emul_controller_llcp_send(net_nfc_target_handle_s* handle, n socket_info_s *socket_info = _net_nfc_find_server_socket(socket); if (socket_info == NULL) { - DEBUG_ERR_MSG ("socket_info is NULL"); + DEBUG_ERR_MSG("socket_info is NULL"); return false; } llcp_state_e llcp_state = NET_NFC_STATE_UNKNOWN; llcp_state = _net_nfc_get_llcp_state(socket_info->user_context); if (llcp_state == NET_NFC_STATE_UNKNOWN) { - DEBUG_ERR_MSG ("llcp_state is NET_NFC_STATE_UNKNOWN"); + DEBUG_ERR_MSG("llcp_state is NET_NFC_STATE_UNKNOWN"); return false; } - if(llcp_state == NET_NFC_STATE_EXCHANGER_SERVER) { + if (llcp_state == NET_NFC_STATE_EXCHANGER_SERVER) { net_nfc_request_llcp_msg_t *req_msg = NULL; _nfc_emul_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t)); socket_info->user_context = user_param; - if (req_msg != NULL){ + if (req_msg != NULL) { req_msg->length = sizeof(net_nfc_request_llcp_msg_t); req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_SEND; req_msg->result = NET_NFC_OK; @@ -2763,9 +2571,8 @@ static bool net_nfc_emul_controller_llcp_send(net_nfc_target_handle_s* handle, n static bool net_nfc_emul_controller_llcp_send_to(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, uint8_t service_access_point, net_nfc_error_e* result, void * user_param) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2778,25 +2585,25 @@ static bool net_nfc_emul_controller_llcp_send_to(net_nfc_target_handle_s* handle socket_info_s *socket_info = _net_nfc_find_server_socket(socket); if (socket_info == NULL) { - DEBUG_ERR_MSG ("socket_info is NULL"); + DEBUG_ERR_MSG("socket_info is NULL"); return false; } llcp_state_e llcp_state = NET_NFC_STATE_UNKNOWN; llcp_state = _net_nfc_get_llcp_state(socket_info->user_context); if (llcp_state == NET_NFC_STATE_UNKNOWN) { - DEBUG_ERR_MSG ("llcp_state is NET_NFC_STATE_UNKNOWN"); + DEBUG_ERR_MSG("llcp_state is NET_NFC_STATE_UNKNOWN"); return false; } - if(llcp_state == NET_NFC_STATE_EXCHANGER_SERVER) { + if (llcp_state == NET_NFC_STATE_EXCHANGER_SERVER) { net_nfc_request_llcp_msg_t *req_msg = NULL; _nfc_emul_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t)); socket_info->user_context = user_param; - if (req_msg != NULL){ + if (req_msg != NULL) { req_msg->length = sizeof(net_nfc_request_llcp_msg_t); req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO; req_msg->result = NET_NFC_OK; @@ -2814,9 +2621,8 @@ static bool net_nfc_emul_controller_llcp_send_to(net_nfc_target_handle_s* handle static bool net_nfc_emul_controller_llcp_recv(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s * data, net_nfc_error_e* result, void * user_param) { - if (result == NULL || data == NULL) { + if (result == NULL || data == NULL) return false; - } *result = NET_NFC_OK; @@ -2829,14 +2635,14 @@ static bool net_nfc_emul_controller_llcp_recv(net_nfc_target_handle_s* handle, n socket_info_s *socket_info = _net_nfc_find_server_socket(socket); if (socket_info == NULL) { - DEBUG_ERR_MSG ("socket_info is NULL"); + DEBUG_ERR_MSG("socket_info is NULL"); return false; } llcp_state_e llcp_state = NET_NFC_STATE_UNKNOWN; llcp_state = _net_nfc_get_llcp_state(socket_info->user_context); if (llcp_state == NET_NFC_STATE_UNKNOWN) { - DEBUG_ERR_MSG ("llcp_state is NET_NFC_STATE_UNKNOWN"); + DEBUG_ERR_MSG("llcp_state is NET_NFC_STATE_UNKNOWN"); return false; } @@ -2845,7 +2651,7 @@ static bool net_nfc_emul_controller_llcp_recv(net_nfc_target_handle_s* handle, n DEBUG_MSG("NET_NFC_STATE_EXCHANGER_SERVER"); socket_info->user_context = user_param; - if(Snep_Server_msg->isSegment) { + if (Snep_Server_msg->isSegment) { /* send snep msg continueosly ..*/ DEBUG_MSG("send segments for snep msg"); @@ -2862,8 +2668,7 @@ static bool net_nfc_emul_controller_llcp_recv(net_nfc_target_handle_s* handle, n memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer+Snep_Server_msg->offset , remained_size); Snep_Server_msg->isSegment = false; - } - else { + } else { DEBUG_MSG("send continue segment >>>"); llcp_server_data->length = SNEP_MAX_BUFFER; @@ -2873,15 +2678,13 @@ static bool net_nfc_emul_controller_llcp_recv(net_nfc_target_handle_s* handle, n } _net_nfc_llcp_data_receive_cb(socket_info->user_context); /* call callback */ - } - else { + } else { /* In here, we dosen't call _net_nfc_llcp_data_receive_cb. just wait event from emulator */ /*After copying data address, we will return it, immediately */ DEBUG_MSG("data address is set"); llcp_server_data = data; } - } - else { + } else { DEBUG_MSG("we don't support.."); } @@ -2892,9 +2695,8 @@ static bool net_nfc_emul_controller_llcp_recv(net_nfc_target_handle_s* handle, n static bool net_nfc_emul_controller_llcp_recv_from(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s * data, net_nfc_error_e* result, void * user_param) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2907,14 +2709,14 @@ static bool net_nfc_emul_controller_llcp_recv_from(net_nfc_target_handle_s* hand socket_info_s *socket_info = _net_nfc_find_server_socket(socket); if (socket_info == NULL) { - DEBUG_ERR_MSG ("socket_info is NULL"); + DEBUG_ERR_MSG("socket_info is NULL"); return false; } llcp_state_e llcp_state = NET_NFC_STATE_UNKNOWN; llcp_state = _net_nfc_get_llcp_state(socket_info->user_context); if (llcp_state == NET_NFC_STATE_UNKNOWN) { - DEBUG_ERR_MSG ("llcp_state is NET_NFC_STATE_UNKNOWN"); + DEBUG_ERR_MSG("llcp_state is NET_NFC_STATE_UNKNOWN"); return false; } @@ -2923,7 +2725,7 @@ static bool net_nfc_emul_controller_llcp_recv_from(net_nfc_target_handle_s* hand DEBUG_MSG("NET_NFC_STATE_EXCHANGER_SERVER"); socket_info->user_context = user_param; - if(Snep_Server_msg->isSegment) { + if (Snep_Server_msg->isSegment) { /* send snep msg continueosly ..*/ DEBUG_MSG("send segments for snep msg"); @@ -2940,8 +2742,7 @@ static bool net_nfc_emul_controller_llcp_recv_from(net_nfc_target_handle_s* hand memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer+Snep_Server_msg->offset , remained_size); Snep_Server_msg->isSegment = false; - } - else { + } else { DEBUG_MSG("send continue segment >>>"); llcp_server_data->length = SNEP_MAX_BUFFER; @@ -2951,21 +2752,18 @@ static bool net_nfc_emul_controller_llcp_recv_from(net_nfc_target_handle_s* hand } _net_nfc_llcp_data_receive_from_cb(socket_info->user_context); /* call callback */ - } - else { + } else { /* In here, we dosen't call _net_nfc_llcp_data_receive_cb. just wait event from emulator */ /*After copying data address, we will return it, immediately */ - if(data != NULL) { + if (data != NULL) { DEBUG_MSG("data address is set"); llcp_server_data = data; - } - else { + } else { DEBUG_ERR_MSG("data address is NULL"); return false; } } - } - else { + } else { DEBUG_MSG("we donen't support.."); } @@ -2976,9 +2774,8 @@ static bool net_nfc_emul_controller_llcp_recv_from(net_nfc_target_handle_s* hand static bool net_nfc_emul_controller_llcp_disconnect(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -2991,14 +2788,14 @@ static bool net_nfc_emul_controller_llcp_disconnect(net_nfc_target_handle_s* han socket_info_s *socket_info = _net_nfc_find_server_socket(socket); if (socket_info == NULL) { - DEBUG_ERR_MSG ("socket_info is NULL"); + DEBUG_ERR_MSG("socket_info is NULL"); return false; } llcp_state_e llcp_state = NET_NFC_STATE_UNKNOWN; llcp_state = _net_nfc_get_llcp_state(socket_info->user_context); if (llcp_state == NET_NFC_STATE_UNKNOWN) { - DEBUG_ERR_MSG ("llcp_state is NET_NFC_STATE_UNKNOWN"); + DEBUG_ERR_MSG("llcp_state is NET_NFC_STATE_UNKNOWN"); return false; } @@ -3009,7 +2806,7 @@ static bool net_nfc_emul_controller_llcp_disconnect(net_nfc_target_handle_s* han socket_info->user_context = user_param; - if (req_msg != NULL){ + if (req_msg != NULL) { req_msg->length = sizeof(net_nfc_request_llcp_msg_t); req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT; req_msg->result = NET_NFC_OK; @@ -3028,9 +2825,8 @@ static bool net_nfc_emul_controller_llcp_disconnect(net_nfc_target_handle_s* han static bool net_nfc_emul_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -3043,9 +2839,8 @@ static bool net_nfc_emul_controller_llcp_socket_close(net_nfc_llcp_socket_t sock static bool net_nfc_emul_controller_llcp_reject(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -3061,11 +2856,10 @@ static bool net_nfc_emul_controller_llcp_reject(net_nfc_target_handle_s* handle, return true; } -static bool net_nfc_emul_controller_llcp_get_remote_config (net_nfc_target_handle_s* handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e* result) +static bool net_nfc_emul_controller_llcp_get_remote_config(net_nfc_target_handle_s* handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e* result) { - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -3081,14 +2875,13 @@ static bool net_nfc_emul_controller_llcp_get_remote_config (net_nfc_target_handl return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_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) { /* In llcp specification ver 1.1, default miu size is 128 */ const uint16_t default_miu = 128; - if (result == NULL) { + if (result == NULL) return false; - } *result = NET_NFC_OK; @@ -3112,8 +2905,7 @@ static bool net_nfc_emul_controller_support_nfc(net_nfc_error_e *result) bool ret = false; struct stat st = { 0, }; - if (stat("/dev/nfc0", &st) == -1) - { + if (stat("/dev/nfc0", &st) == -1) { if (result) *result = NET_NFC_NOT_SUPPORTED; return ret; @@ -3149,14 +2941,14 @@ static bool net_nfc_emul_controller_secure_element_get_atr(net_nfc_target_handle strncpy(buffer, "getatr", sizeof(buffer)); - temp = (data_s *)calloc(1, sizeof(*temp)); - if (temp != NULL) { - temp->buffer = (uint8_t *)calloc(1, length); - if (temp->buffer != NULL) { - memcpy(temp->buffer, buffer, length); - temp->length = length; - *atr = temp; - *result = NET_NFC_OK; + temp = (data_s *)calloc(1, sizeof(*temp)); + if (temp != NULL) { + temp->buffer = (uint8_t *)calloc(1, length); + if (temp->buffer != NULL) { + memcpy(temp->buffer, buffer, length); + temp->length = length; + *atr = temp; + *result = NET_NFC_OK; } else { free(temp); *result = NET_NFC_ALLOC_FAIL; @@ -3187,9 +2979,9 @@ static bool net_nfc_emul_controller_secure_element_send_apdu(net_nfc_target_hand length = strlen(buffer); - temp = (data_s *)calloc(1, sizeof(*temp)); + temp = (data_s *)calloc(1, sizeof(*temp)); if (temp != NULL) { - temp->buffer = (uint8_t *)calloc(1, length); + temp->buffer = (uint8_t *)calloc(1, length + 1); if (temp->buffer != NULL) { memcpy(temp->buffer, buffer, length); temp->length = length; @@ -3210,7 +3002,7 @@ static bool net_nfc_emul_controller_secure_element_send_apdu(net_nfc_target_hand return ret; } static bool net_nfc_emul_controller_secure_element_close(net_nfc_target_handle_s *handle, - net_nfc_error_e *result) + net_nfc_error_e *result) { DEBUG_ERR_MSG("se close start"); *result = NET_NFC_OK; -- 2.7.4 From dd80e72f0edd4933b60f852dac98a4d6e834571d Mon Sep 17 00:00:00 2001 From: Hyihong Chae Date: Thu, 27 Apr 2017 14:54:08 +0900 Subject: [PATCH 07/16] fix build error Change-Id: I297c075f745de33db92a0b84112b8d16ffbe4993 Signed-off-by: HyiHong Chae --- src/oem/oem_emul.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/oem/oem_emul.c b/src/oem/oem_emul.c index 1b7e8cd..9c7e7cb 100755 --- a/src/oem/oem_emul.c +++ b/src/oem/oem_emul.c @@ -1093,6 +1093,7 @@ static bool _net_nfc_create_emulMsg(emulMsg_s **emul_msg, uint8_t * data, long i switch ((*emul_msg)->message_id) { case EMUL_NFC_TAG_DISCOVERED: case EMUL_NFC_P2P_SEND: + { /* get message : Tag Type, Record Count, Records */ int target_type = -1; char file_data[BUFFER_LENGTH_MAX] = {0, }; @@ -1118,6 +1119,7 @@ static bool _net_nfc_create_emulMsg(emulMsg_s **emul_msg, uint8_t * data, long i DEBUG_ERR_MSG("_net_nfc_create_ndef_from_emulMsg end"); break; + } default: /* exception case */ -- 2.7.4 From 8437d512d9d8b5f290fcca951d3beb40e87cc812 Mon Sep 17 00:00:00 2001 From: "jh8801.jung" Date: Thu, 22 Jun 2017 14:38:46 +0900 Subject: [PATCH 08/16] Change for C sharp TC fail Signed-off-by: jh8801.jung Change-Id: I74cde2becefabb22c381a9f3e9504b0cbb74a2f0 --- packaging/nfc-plugin-emul.spec | 2 +- src/oem/oem_emul.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packaging/nfc-plugin-emul.spec b/packaging/nfc-plugin-emul.spec index 65fb8f4..8b9b6e2 100644 --- a/packaging/nfc-plugin-emul.spec +++ b/packaging/nfc-plugin-emul.spec @@ -1,6 +1,6 @@ Name: nfc-plugin-emul Summary: NFC emul plugin -Version: 0.0.24 +Version: 0.0.25 Release: 0 Group: TO_BE/FILLED_IN License: Apache-2.0 diff --git a/src/oem/oem_emul.c b/src/oem/oem_emul.c index 9c7e7cb..8ca646c 100755 --- a/src/oem/oem_emul.c +++ b/src/oem/oem_emul.c @@ -860,6 +860,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag create_record_count++; DEBUG_MSG("Create Record Sucess. Create Record Count[%d]", create_record_count); + continue; ERROR: /* free data */ @@ -876,7 +877,7 @@ ERROR: _nfc_emul_util_free_mem(filePayload.buffer); DEBUG_MSG("Create Record Loop End"); - + break; } DEBUG_EMUL_END(); @@ -2860,6 +2861,9 @@ static bool net_nfc_emul_controller_llcp_reject(net_nfc_target_handle_s* handle, static bool net_nfc_emul_controller_llcp_get_remote_config(net_nfc_target_handle_s* handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e* result) { + /* In llcp specification ver 1.1, default miu size is 128 */ + const uint16_t default_miu = 128; + if (result == NULL) return false; @@ -2872,6 +2876,8 @@ static bool net_nfc_emul_controller_llcp_get_remote_config(net_nfc_target_handle DEBUG_EMUL_BEGIN(); + config->miu = default_miu; + DEBUG_EMUL_END(); return true; -- 2.7.4 From b9897579372d3a4bec5db097cf27e45bdb78b888 Mon Sep 17 00:00:00 2001 From: "jh8801.jung" Date: Thu, 21 Sep 2017 13:15:47 +0900 Subject: [PATCH 09/16] Fix Svace issues Signed-off-by: jh8801.jung Change-Id: I278d2883215b46b1990aa29eeab092464140f43a --- packaging/nfc-plugin-emul.spec | 2 +- src/oem/oem_emul.c | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packaging/nfc-plugin-emul.spec b/packaging/nfc-plugin-emul.spec index 8b9b6e2..b11917a 100644 --- a/packaging/nfc-plugin-emul.spec +++ b/packaging/nfc-plugin-emul.spec @@ -1,6 +1,6 @@ Name: nfc-plugin-emul Summary: NFC emul plugin -Version: 0.0.25 +Version: 0.0.26 Release: 0 Group: TO_BE/FILLED_IN License: Apache-2.0 diff --git a/src/oem/oem_emul.c b/src/oem/oem_emul.c index 8ca646c..c6c915c 100755 --- a/src/oem/oem_emul.c +++ b/src/oem/oem_emul.c @@ -485,7 +485,13 @@ static void _net_nfc_initialize_llcp(void) if (Snep_Server_msg == NULL) { Snep_Server_msg = (snep_msg_s *)calloc(1, sizeof(snep_msg_s)); + if (Snep_Server_msg == NULL) + return; + Snep_Server_msg->data = (data_s *)calloc(1, sizeof(data_s)); + if (Snep_Server_msg->data == NULL) + return; + Snep_Server_msg->data->buffer = (uint8_t *)calloc(1, sizeof(uint8_t) * BUFFER_LENGTH_MAX); } @@ -660,7 +666,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); goto ERROR; } - memcpy(record.typeName.buffer, type_name, record.typeName.length); + memcpy(record.typeName.buffer, type_name, sizeof(record.typeName.buffer) - 1); DEBUG_MSG("Data : record_id "); @@ -671,7 +677,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); goto ERROR; } - memcpy(record.id.buffer, record_id, record.id.length); + memcpy(record.id.buffer, record_id, sizeof(record.id.buffer) - 1); DEBUG_MSG("Data : record_payload "); @@ -682,7 +688,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); goto ERROR; } - memcpy(record.payload.buffer, record_payload, record.payload.length); + memcpy(record.payload.buffer, record_payload, sizeof(record.payload.buffer) - 1); #ifndef __EMUL_DEBUG__ DEBUG_ERR_MSG("RECORD DATA START >>>>>>>>>>>>>>>>>>>>>>>>"); @@ -832,7 +838,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag _nfc_emul_util_free_mem(filePayload.buffer); goto ERROR; } - memcpy(record.id.buffer, file_name, record.id.length); + memcpy(record.id.buffer, file_name, sizeof(record.id.buffer) - 1); } } else { DEBUG_MSG("file open error"); @@ -898,7 +904,7 @@ static bool _net_nfc_change_file_owner_permission(FILE *file) return false; /* change permission */ - fchmod(fileno(file), 0777); + fchmod(fileno(file), 0644); /* change owner */ /* get passwd id */ @@ -1062,6 +1068,7 @@ static bool _net_nfc_create_ndef_from_emulMsg(emulMsg_s *emul_msg) _net_nfc_store_ndef_message(&rawdata); _nfc_emul_util_free_mem(rawdata.buffer); + net_nfc_util_free_ndef_message(ndef_message); DEBUG_EMUL_END(); @@ -1839,6 +1846,9 @@ static bool net_nfc_emul_controller_get_firmware_version(data_s **data, net_nfc_ (*data)->length = 10; (*data)->buffer = (uint8_t *)calloc(1, (*data)->length); + if ((*data)->buffer == NULL) + return false; + snprintf((char *)(*data)->buffer, (*data)->length, "%d.%d", 1, 0); DEBUG_EMUL_END(); @@ -2991,7 +3001,7 @@ static bool net_nfc_emul_controller_secure_element_send_apdu(net_nfc_target_hand if (temp != NULL) { temp->buffer = (uint8_t *)calloc(1, length + 1); if (temp->buffer != NULL) { - memcpy(temp->buffer, buffer, length); + memcpy(temp->buffer, buffer, sizeof(temp->buffer) - 1); temp->length = length; *response = temp; -- 2.7.4 From 2700f17f21218efa77b6a582f3de798be2ea1fbb Mon Sep 17 00:00:00 2001 From: "jh8801.jung" Date: Fri, 13 Oct 2017 14:33:22 +0900 Subject: [PATCH 10/16] Fix coverity issue Signed-off-by: jh8801.jung Change-Id: Ie739ad173723484877cc8164902d14fd85345416 --- src/oem/oem_emul.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/oem/oem_emul.c b/src/oem/oem_emul.c index c6c915c..3b8a125 100755 --- a/src/oem/oem_emul.c +++ b/src/oem/oem_emul.c @@ -637,7 +637,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag char *record_payload; emulMsg_data_s record = { 0, }; - data_s filePayload; + data_s filePayload = { NULL, 0 }; /* parse string */ if (index == 0) @@ -1598,12 +1598,12 @@ static void emul_ReaderThread(void * pArg) condition = 0; } else if (emulMsg_poll_events[index].events & EPOLLIN) { if (emulMsg_poll_events[index].data.fd == emulMsg_file_fd) { - char readbuffer[READ_BUFFER_LENGTH_MAX]; + char readbuffer[READ_BUFFER_LENGTH_MAX + 1]; int readcnt = 0; DEBUG_MSG("precess POLLIN "); - memset(readbuffer, 0x00, sizeof(READ_BUFFER_LENGTH_MAX)); + memset(readbuffer, 0x00, sizeof(READ_BUFFER_LENGTH_MAX) + 1); readcnt = read(emulMsg_file_fd, readbuffer, READ_BUFFER_LENGTH_MAX); -- 2.7.4 From 3341186b239788a3632265e245a017305dea63de Mon Sep 17 00:00:00 2001 From: Youngjae Shin Date: Fri, 14 Aug 2020 15:22:38 +0900 Subject: [PATCH 11/16] [cleanup]revise file location and mode Change-Id: Ib755c0088c0df04892156effb0a10f099902611e --- 98-nfc-plugin-emul.rules | 0 AUTHORS | 7 ------- CMakeLists.txt | 2 +- LICENSE.Apache-2.0 => LICENSE.APLv2 | 3 --- NOTICE | 2 +- packaging/nfc-plugin-emul.spec | 2 +- src/nfc_debug_private.h | 0 src/{oem => }/oem_emul.c | 1 - 8 files changed, 3 insertions(+), 14 deletions(-) mode change 100755 => 100644 98-nfc-plugin-emul.rules delete mode 100644 AUTHORS mode change 100755 => 100644 CMakeLists.txt rename LICENSE.Apache-2.0 => LICENSE.APLv2 (99%) mode change 100755 => 100644 src/nfc_debug_private.h rename src/{oem => }/oem_emul.c (99%) mode change 100755 => 100644 diff --git a/98-nfc-plugin-emul.rules b/98-nfc-plugin-emul.rules old mode 100755 new mode 100644 diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index 22aae9a..0000000 --- a/AUTHORS +++ /dev/null @@ -1,7 +0,0 @@ -Lee Sangsoo -Junyong Sim -Wonkyu Kwon -Sungjae Lim -Sechang Sohn -Jinmin Chung -Jaekyun Lee diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 index a83b598..cdc76d2 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ MESSAGE("build nfc-plugin-emul") include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/oem SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) IF("${CMAKE_BUILD_TYPE}" STREQUAL "") SET(CMAKE_BUILD_TYPE "Release") diff --git a/LICENSE.Apache-2.0 b/LICENSE.APLv2 similarity index 99% rename from LICENSE.Apache-2.0 rename to LICENSE.APLv2 index 2e43946..181359e 100644 --- a/LICENSE.Apache-2.0 +++ b/LICENSE.APLv2 @@ -201,6 +201,3 @@ Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - - - diff --git a/NOTICE b/NOTICE index 0e0f016..7a9049f 100644 --- a/NOTICE +++ b/NOTICE @@ -1,3 +1,3 @@ Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. Except as noted, this software is licensed under Apache License, Version 2. -Please, see the LICENSE.APLv2 file for Apache License terms and conditions. +Please, see the LICENSE.APLv2 file for Apache license, version 2 terms and conditions. diff --git a/packaging/nfc-plugin-emul.spec b/packaging/nfc-plugin-emul.spec index b11917a..049f8e5 100644 --- a/packaging/nfc-plugin-emul.spec +++ b/packaging/nfc-plugin-emul.spec @@ -40,7 +40,7 @@ cp 98-nfc-plugin-emul.rules %{buildroot}/usr/lib/udev/rules.d/98-nfc-plugin-emul %post -p /sbin/ldconfig %files -%license LICENSE.Apache-2.0 +%license LICENSE.APLv2 %defattr(-,root,root,-) /usr/lib/nfc/libnfc-plugin.so /usr/lib/udev/rules.d/98-nfc-plugin-emul.rules diff --git a/src/nfc_debug_private.h b/src/nfc_debug_private.h old mode 100755 new mode 100644 diff --git a/src/oem/oem_emul.c b/src/oem_emul.c old mode 100755 new mode 100644 similarity index 99% rename from src/oem/oem_emul.c rename to src/oem_emul.c index 3b8a125..95e0dba --- a/src/oem/oem_emul.c +++ b/src/oem_emul.c @@ -3029,4 +3029,3 @@ static bool net_nfc_emul_controller_secure_element_close(net_nfc_target_handle_s } ////////////// INTERFACE END ////////// - -- 2.7.4 From 25340e7e9873e78cc28753926514de58766a6b09 Mon Sep 17 00:00:00 2001 From: Youngjae Shin Date: Fri, 14 Aug 2020 15:27:09 +0900 Subject: [PATCH 12/16] [cleanup]revise build scripts and packaging Change-Id: I23b506d271387cd4d16cd960d5f28393eeb5d642 --- CMakeLists.txt | 40 ++++++++------------------------- packaging/nfc-plugin-emul.manifest | 5 +++++ packaging/nfc-plugin-emul.spec | 46 +++++++++++++------------------------- 3 files changed, 30 insertions(+), 61 deletions(-) create mode 100644 packaging/nfc-plugin-emul.manifest diff --git a/CMakeLists.txt b/CMakeLists.txt index cdc76d2..7388580 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,40 +1,18 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(nfc-plugin C) -MESSAGE("build nfc-plugin-emul") - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) - -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) - -IF("${CMAKE_BUILD_TYPE}" STREQUAL "") - SET(CMAKE_BUILD_TYPE "Release") -ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") -MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") - INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0 gobject-2.0 dlog nfc-common-lib vconf) - -FOREACH(flag ${pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -# this for NFC flag +SET(EXTRA_FLAGS "-Wall -Werror -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS}") -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fno-strict-aliasing -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -Wl,-zdefs -fvisibility=hidden") -SET(ARM_CFLAGS "${ARM_CFLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic") - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration -Wl,--unresolved-symbols=ignore-in-shared-libs") - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") -SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -#SET(CMAKE_C_FLAGS_RELEASE "-O2") - -ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +pkg_check_modules(pkgs REQUIRED dlog nfc-common-lib vconf) +INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS}) +LINK_DIRECTORIES(${pkgs_LIBRARY_DIRS}) +FILE(GLOB SRCS src/*.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) - -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} pthread "-ldl") - +TARGET_COMPILE_OPTIONS(${PROJECT_NAME} PUBLIC ${pkgs_CFLAGS_OTHER}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LIBRARIES} pthread) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib/nfc) +INSTALL(FILES 98-${PROJECT_NAME}-emul.rules DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/udev/rules.d/) diff --git a/packaging/nfc-plugin-emul.manifest b/packaging/nfc-plugin-emul.manifest new file mode 100644 index 0000000..a76fdba --- /dev/null +++ b/packaging/nfc-plugin-emul.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/nfc-plugin-emul.spec b/packaging/nfc-plugin-emul.spec index 049f8e5..2424e16 100644 --- a/packaging/nfc-plugin-emul.spec +++ b/packaging/nfc-plugin-emul.spec @@ -1,46 +1,32 @@ -Name: nfc-plugin-emul -Summary: NFC emul plugin -Version: 0.0.26 -Release: 0 -Group: TO_BE/FILLED_IN -License: Apache-2.0 -Source0: %{name}-%{version}.tar.gz -BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(gobject-2.0) -BuildRequires: pkgconfig(vconf) +Name: nfc-plugin-emul +Summary: NFC emul plugin +Version: 0.0.26 +Release: 0 +Group: Network & Connectivity/NFC +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz +Source1001: %{name}.manifest +BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(nfc-common-lib) -BuildRequires: cmake -BuildRequires: gettext-tools +BuildRequires: pkgconfig(vconf) %description NFC Plugin Emul %prep %setup -q - +cp %{SOURCE1001} ./%{name}.manifest %build -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ -%ifarch aarch64 x86_64 - -DTIZEN_ARCH_64=1 \ -%endif - -make %{?jobs:-j%jobs} +%cmake . -DCMAKE_VERBOSE_MAKEFILE=OFF +make %{?_smp_mflags} %install -rm -rf %{buildroot} %make_install -mkdir -p %{buildroot}/usr/lib/udev/rules.d -cp 98-nfc-plugin-emul.rules %{buildroot}/usr/lib/udev/rules.d/98-nfc-plugin-emul.rules - -%postun -p /sbin/ldconfig - -%post -p /sbin/ldconfig - %files -%license LICENSE.APLv2 -%defattr(-,root,root,-) +%manifest %{name}.manifest /usr/lib/nfc/libnfc-plugin.so -/usr/lib/udev/rules.d/98-nfc-plugin-emul.rules +%{_prefix}/lib/udev/rules.d/98-%{name}.rules +%license LICENSE.APLv2 -- 2.7.4 From 47e22def0258cc5add351779e8d6754341ee9275 Mon Sep 17 00:00:00 2001 From: Youngjae Shin Date: Fri, 14 Aug 2020 15:40:01 +0900 Subject: [PATCH 13/16] code cleanup Change-Id: Ia7edf621efc0d5384b087c421799bf4505860aa3 --- src/oem_emul.c | 544 +++++++++++++++++++++++---------------------------------- 1 file changed, 218 insertions(+), 326 deletions(-) diff --git a/src/oem_emul.c b/src/oem_emul.c index 95e0dba..b5acb0a 100644 --- a/src/oem_emul.c +++ b/src/oem_emul.c @@ -13,42 +13,25 @@ * 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 +#include +#include +#include #include - -#ifdef USE_GLIB_MAIN_LOOP -#include -#endif +#include #include -#include "net_nfc_typedef.h" +#include +#include +#include +#include #include "nfc_debug_private.h" -#include "net_nfc_util_internal.h" -#include "net_nfc_util_ndef_message.h" -#include "net_nfc_util_ndef_record.h" - -#include - -/*************************** STRUCTURE DEFINE START ***************************************/ - -#ifndef NET_NFC_EXPORT_API -#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) -#endif typedef enum { EMUL_NFC_TAG_DISCOVERED = 100, @@ -105,7 +88,7 @@ typedef enum { typedef struct _socket_info_s { net_nfc_llcp_socket_t socket_handle; bool isValid; - void* user_context; + void *user_context; } socket_info_s; typedef struct _net_nfc_oem_llcp_state_t { @@ -115,14 +98,14 @@ typedef struct _net_nfc_oem_llcp_state_t { llcp_state_e state; net_nfc_llcp_socket_t socket; uint16_t max_capability; - net_nfc_target_handle_s * handle; + net_nfc_target_handle_s *handle; net_nfc_error_e prev_result; net_nfc_llcp_socket_t incomming_socket; ndef_message_s *requester; ndef_message_s *selector; bool low_power; - void * user_data; - void * payload; + void *user_data; + void *payload; llcp_app_protocol_e type_app_protocol; net_nfc_conn_handover_carrier_type_e type; @@ -152,18 +135,13 @@ typedef struct _emulMsg_s { emul_message_id message_id; emul_target_type target_type; int record_count; - uint8_t* file_data; + uint8_t *file_data; } emulMsg_s; -typedef void * (*emul_Nfc_thread_handler_t) (void * pParam); - -/*************************** STRUCTURE DEFINE START ***************************************/ +typedef void* (*emul_Nfc_thread_handler_t)(void *pParam); #define __USE_EPOLL_FOR_FILE__ 1 - -/****************************** DEFINE START *******************************************/ - /* for emulator management */ #define NET_NFC_EMUL_DATA_PATH "/dev" #define NET_NFC_EMUL_MESSAGE_FILE_NAME "nfc0" @@ -196,23 +174,17 @@ typedef void * (*emul_Nfc_thread_handler_t) (void * pParam); #define WRITE_BUFFER_LENGTH_MAX BUFFER_LENGTH_MAX #define NET_NFC_MAX_LLCP_SOCKET_BUFFER BUFFER_LENGTH_MAX -/****************************** DEFINE END *******************************************/ - - - -/****************************** VARIABLE START *******************************************/ - /* listener callback */ -static target_detection_listener_cb g_emul_controller_target_cb ; -static se_transaction_listener_cb g_emul_controller_se_cb ; -static llcp_event_listener_cb g_emul_controller_llcp_cb ; -static hce_apdu_listener_cb g_emul_controller_hce_cb ; +static target_detection_listener_cb g_emul_controller_target_cb; +static se_transaction_listener_cb g_emul_controller_se_cb; +static llcp_event_listener_cb g_emul_controller_llcp_cb; +static hce_apdu_listener_cb g_emul_controller_hce_cb; /* for emulator management */ -pthread_t gEmulThread; +pthread_t gEmulThread; /* for stack management */ -static net_nfc_target_handle_s * current_working_handle = NULL; +static net_nfc_target_handle_s *current_working_handle = NULL; static bool g_stack_init_successful = 0; static bool g_tag_attached = 0; static bool g_p2p_attached = 0; @@ -221,101 +193,22 @@ static int current_connection_id = 1; socket_info_s socket_info_array[LLCP_NB_SOCKET_MAX] = { {0, } }; -snep_msg_s* Snep_Server_msg; -data_s* llcp_server_data = NULL; +snep_msg_s *Snep_Server_msg; +data_s *llcp_server_data = NULL; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -/****************************** VARIABLE END *******************************************/ - - - -/*************************** STATIC FUNCTION DECLARE START ***************************************/ - -/*************************** INTERFACE START ***************************************/ - -static bool net_nfc_emul_controller_init(net_nfc_error_e* result); -static bool net_nfc_emul_controller_deinit(void); -static bool net_nfc_emul_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); -static bool net_nfc_emul_controller_unregister_listener(); -static bool net_nfc_emul_controller_get_firmware_version(data_s **data, net_nfc_error_e *result); -static bool net_nfc_emul_controller_check_firmware_version(net_nfc_error_e* result); -static bool net_nfc_emul_controller_update_firmware(net_nfc_error_e* result); -static bool net_nfc_emul_controller_get_stack_information(net_nfc_stack_information_s* stack_info, net_nfc_error_e* result); -static bool net_nfc_emul_controller_configure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result); -static bool net_nfc_emul_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result); -static bool net_nfc_emul_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); -static bool net_nfc_emul_controller_connect(net_nfc_target_handle_s* handle, net_nfc_error_e* result); -static bool net_nfc_emul_controller_disconnect(net_nfc_target_handle_s* handle, net_nfc_error_e* result); -static bool net_nfc_emul_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); -static bool net_nfc_emul_controller_check_target_presence(net_nfc_target_handle_s* handle, net_nfc_error_e* result); -static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, data_s** data, net_nfc_error_e* result); -static bool net_nfc_emul_controller_write_ndef(net_nfc_target_handle_s* handle, data_s* data, net_nfc_error_e* result); -static bool net_nfc_emul_controller_make_read_only_ndef(net_nfc_target_handle_s* handle, net_nfc_error_e* result); -static bool net_nfc_emul_controller_transceive(net_nfc_target_handle_s* handle, net_nfc_transceive_info_s* info, data_s** data, net_nfc_error_e* result); -static bool net_nfc_emul_controller_format_ndef(net_nfc_target_handle_s* handle, data_s* secure_key, net_nfc_error_e* result); -static bool net_nfc_emul_controller_exception_handler(void); -static bool net_nfc_emul_controller_is_ready(net_nfc_error_e* error); - -static bool net_nfc_emul_controller_llcp_config(net_nfc_llcp_config_info_s * config, net_nfc_error_e * result); -static bool net_nfc_emul_controller_llcp_check_llcp(net_nfc_target_handle_s * handle, net_nfc_error_e* result); -static bool net_nfc_emul_controller_llcp_activate_llcp(net_nfc_target_handle_s * handle, net_nfc_error_e* result); -static bool net_nfc_emul_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); -static bool net_nfc_emul_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result); -static bool net_nfc_emul_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); -static bool net_nfc_emul_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void *user_param); -static bool net_nfc_emul_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); -static bool net_nfc_emul_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); -static bool net_nfc_emul_controller_llcp_reject(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result); -static bool net_nfc_emul_controller_llcp_disconnect(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param); -static bool net_nfc_emul_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e* result); -static bool net_nfc_emul_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); -static bool net_nfc_emul_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); -static bool net_nfc_emul_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); -static bool net_nfc_emul_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); -static bool net_nfc_emul_controller_llcp_get_remote_config(net_nfc_target_handle_s* handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e* result); -static bool net_nfc_emul_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); - -static bool net_nfc_emul_controller_support_nfc(net_nfc_error_e *result); -static bool net_nfc_emul_controller_secure_element_open(net_nfc_secure_element_type_e element_type, - net_nfc_target_handle_s **handle, net_nfc_error_e *result); -static bool net_nfc_emul_controller_secure_element_get_atr(net_nfc_target_handle_s *handle, - data_s **atr, net_nfc_error_e *result); -static bool net_nfc_emul_controller_secure_element_send_apdu(net_nfc_target_handle_s *handle, - data_s *command, data_s **response, net_nfc_error_e *result); -static bool net_nfc_emul_controller_secure_element_close(net_nfc_target_handle_s *handle, - net_nfc_error_e *result); - - -/*************************** INTERFACE END ***************************************/ - - - -/*************************** ETC Function ***************************************/ /* Memory utils */ /* free memory, after free given memory it set NULL. Before proceed free, this function also check NULL */ -void __nfc_emul_util_free_mem(void** mem, char * filename, unsigned int line); +static void __nfc_emul_util_free_mem(void **mem, char *filename, unsigned int line); /* allocation memory */ -void __nfc_emul_util_alloc_mem(void** mem, int size, char * filename, unsigned int line); -#define _nfc_emul_util_alloc_mem(mem, size) __nfc_emul_util_alloc_mem((void **)&mem, size, __FILE__, __LINE__) -#define _nfc_emul_util_free_mem(mem) __nfc_emul_util_free_mem((void **)&mem, __FILE__, __LINE__) - +static void __nfc_emul_util_alloc_mem(void **mem, int size, char *filename, unsigned int line); +#define _nfc_emul_util_alloc_mem(mem, size) __nfc_emul_util_alloc_mem((void**)&mem, size, __FILE__, __LINE__) +#define _nfc_emul_util_free_mem(mem) __nfc_emul_util_free_mem((void**)&mem, __FILE__, __LINE__) -static bool __net_nfc_is_valide_target_handle(net_nfc_target_handle_s * handle); -static void __net_nfc_make_valid_target_handle(net_nfc_target_handle_s ** handle); -static void __net_nfc_make_invalid_target_handle(); -/*************************** STATIC FUNCTION DECLARE END ***************************************/ - - - -void __nfc_emul_util_free_mem(void** mem, char * filename, unsigned int line) +static void __nfc_emul_util_free_mem(void **mem, char *filename, unsigned int line) { if (mem == NULL || *mem == NULL) { LOGE("FILE: %s, LINE:%d, Invalid parameter in mem free util (pinter is NULL)", filename, line); @@ -325,7 +218,7 @@ void __nfc_emul_util_free_mem(void** mem, char * filename, unsigned int line) *mem = NULL; } -void __nfc_emul_util_alloc_mem(void** mem, int size, char * filename, unsigned int line) +static void __nfc_emul_util_alloc_mem(void **mem, int size, char *filename, unsigned int line) { if (mem == NULL || size <= 0) { LOGE("FILE: %s, LINE:%d, Invalid parameter in mem alloc util", filename, line); @@ -345,7 +238,7 @@ void __nfc_emul_util_alloc_mem(void** mem, int size, char * filename, unsigned i LOGE("FILE: %s, LINE:%d, Allocation is failed", filename, line); } -static bool __net_nfc_is_valide_target_handle(net_nfc_target_handle_s * handle) +static bool __net_nfc_is_valide_target_handle(net_nfc_target_handle_s *handle) { bool result = (current_working_handle == handle); if (!result) @@ -353,7 +246,8 @@ static bool __net_nfc_is_valide_target_handle(net_nfc_target_handle_s * handle) return result; } -static void __net_nfc_make_valid_target_handle(net_nfc_target_handle_s ** handle) + +static void __net_nfc_make_valid_target_handle(net_nfc_target_handle_s **handle) { if (current_working_handle != NULL) DEBUG_MSG("[WARNING]: HANDLE WAS ALLOCATED ALREADY!"); @@ -362,6 +256,7 @@ static void __net_nfc_make_valid_target_handle(net_nfc_target_handle_s ** handle if (*handle != NULL) current_working_handle = *handle; } + static void __net_nfc_make_invalid_target_handle() { if (current_working_handle != NULL) { @@ -370,7 +265,7 @@ static void __net_nfc_make_invalid_target_handle() } } -static socket_info_s * _net_nfc_get_available_socket_slot() +static socket_info_s* _net_nfc_get_available_socket_slot() { int idx = 0; for (; idx < LLCP_NB_SOCKET_MAX; idx++) { @@ -399,7 +294,7 @@ static void _net_nfc_remove_socket_slot(net_nfc_llcp_socket_t socket) } } -static socket_info_s * _net_nfc_find_server_socket(net_nfc_llcp_socket_t socket) +static socket_info_s* _net_nfc_find_server_socket(net_nfc_llcp_socket_t socket) { int idx = 0; for (; idx < LLCP_NB_SOCKET_MAX; idx++) { @@ -411,88 +306,20 @@ static socket_info_s * _net_nfc_find_server_socket(net_nfc_llcp_socket_t socket) return NULL; } -////////////// INTERFACE START ////////// - -NET_NFC_EXPORT_API bool onload(net_nfc_oem_interface_s * emul_interfaces) -{ - DEBUG_EMUL_BEGIN(); - - emul_interfaces->init = net_nfc_emul_controller_init; - emul_interfaces->deinit = net_nfc_emul_controller_deinit; - emul_interfaces->register_listener = net_nfc_emul_controller_register_listener; - emul_interfaces->unregister_listener = net_nfc_emul_controller_unregister_listener; - emul_interfaces->get_firmware_version = net_nfc_emul_controller_get_firmware_version; - emul_interfaces->check_firmware_version = net_nfc_emul_controller_check_firmware_version; - emul_interfaces->update_firmeware = net_nfc_emul_controller_update_firmware; - emul_interfaces->get_stack_information = net_nfc_emul_controller_get_stack_information; - emul_interfaces->configure_discovery = net_nfc_emul_controller_configure_discovery; - emul_interfaces->get_secure_element_list = net_nfc_emul_controller_get_secure_element_list; - emul_interfaces->set_secure_element_mode = net_nfc_emul_controller_set_secure_element_mode; - emul_interfaces->connect = net_nfc_emul_controller_connect; - emul_interfaces->disconnect = net_nfc_emul_controller_disconnect; - emul_interfaces->check_ndef = net_nfc_emul_controller_check_ndef; - emul_interfaces->check_presence = net_nfc_emul_controller_check_target_presence; - emul_interfaces->read_ndef = net_nfc_emul_controller_read_ndef; - emul_interfaces->write_ndef = net_nfc_emul_controller_write_ndef; - emul_interfaces->make_read_only_ndef = net_nfc_emul_controller_make_read_only_ndef; - emul_interfaces->transceive = net_nfc_emul_controller_transceive; - emul_interfaces->format_ndef = net_nfc_emul_controller_format_ndef; - emul_interfaces->exception_handler = net_nfc_emul_controller_exception_handler; - emul_interfaces->is_ready = net_nfc_emul_controller_is_ready; - - emul_interfaces->config_llcp = net_nfc_emul_controller_llcp_config; - emul_interfaces->check_llcp_status = net_nfc_emul_controller_llcp_check_llcp; - emul_interfaces->activate_llcp = net_nfc_emul_controller_llcp_activate_llcp; - emul_interfaces->create_llcp_socket = net_nfc_emul_controller_llcp_create_socket; - emul_interfaces->bind_llcp_socket = net_nfc_emul_controller_llcp_bind; - emul_interfaces->listen_llcp_socket = net_nfc_emul_controller_llcp_listen; - emul_interfaces->accept_llcp_socket = net_nfc_emul_controller_llcp_accept; - emul_interfaces->connect_llcp_by_url = net_nfc_emul_controller_llcp_connect_by_url; - emul_interfaces->connect_llcp = net_nfc_emul_controller_llcp_connect; - emul_interfaces->disconnect_llcp = net_nfc_emul_controller_llcp_disconnect; - emul_interfaces->close_llcp_socket = net_nfc_emul_controller_llcp_socket_close; - emul_interfaces->recv_llcp = net_nfc_emul_controller_llcp_recv; - emul_interfaces->send_llcp = net_nfc_emul_controller_llcp_send; - emul_interfaces->recv_from_llcp = net_nfc_emul_controller_llcp_recv_from; - emul_interfaces->send_to_llcp = net_nfc_emul_controller_llcp_send_to; - emul_interfaces->reject_llcp = net_nfc_emul_controller_llcp_reject; - emul_interfaces->get_remote_config = net_nfc_emul_controller_llcp_get_remote_config; - emul_interfaces->get_remote_socket_info = net_nfc_emul_controller_llcp_get_remote_socket_info; - - emul_interfaces->support_nfc = net_nfc_emul_controller_support_nfc; - - emul_interfaces->secure_element_open = net_nfc_emul_controller_secure_element_open; - emul_interfaces->secure_element_get_atr = net_nfc_emul_controller_secure_element_get_atr; - emul_interfaces->secure_element_send_apdu = net_nfc_emul_controller_secure_element_send_apdu; - emul_interfaces->secure_element_close = net_nfc_emul_controller_secure_element_close; - - emul_interfaces->hce_response_apdu = NULL; - emul_interfaces->route_aid = NULL; - emul_interfaces->unroute_aid = NULL; - emul_interfaces->commit_routing = NULL; - emul_interfaces->set_default_route = NULL; - emul_interfaces->clear_aid_table = NULL; - emul_interfaces->get_aid_tablesize = NULL; - - DEBUG_EMUL_END(); - - return true; -} - static void _net_nfc_initialize_llcp(void) { DEBUG_EMUL_BEGIN(); if (Snep_Server_msg == NULL) { - Snep_Server_msg = (snep_msg_s *)calloc(1, sizeof(snep_msg_s)); + Snep_Server_msg = calloc(1, sizeof(snep_msg_s)); if (Snep_Server_msg == NULL) return; - Snep_Server_msg->data = (data_s *)calloc(1, sizeof(data_s)); + Snep_Server_msg->data = calloc(1, sizeof(data_s)); if (Snep_Server_msg->data == NULL) return; - Snep_Server_msg->data->buffer = (uint8_t *)calloc(1, sizeof(uint8_t) * BUFFER_LENGTH_MAX); + Snep_Server_msg->data->buffer = calloc(1, sizeof(uint8_t) * BUFFER_LENGTH_MAX); } DEBUG_EMUL_END(); @@ -625,29 +452,29 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag int index; int create_record_count = 0; - char emulMsg[BUFFER_LENGTH_MAX] = { 0, }; + char emulMsg[BUFFER_LENGTH_MAX] = {0}; - memcpy(emulMsg, emul_msg->file_data, sizeof(emulMsg)-1); + memcpy(emulMsg, emul_msg->file_data, sizeof(emulMsg) - 1); /* parsing data and create record to record structure */ - for (index = 0; index < record_count ; index++) { + for (index = 0; index < record_count; index++) { char *name_format; char *type_name; char *record_id; char *record_payload; - emulMsg_data_s record = { 0, }; - data_s filePayload = { NULL, 0 }; + emulMsg_data_s record = {0}; + data_s filePayload = {NULL, 0}; /* parse string */ if (index == 0) - name_format = strtok((char *) emulMsg, NET_NFC_EMUL_MSG_RECORD_SEPERATOR); + name_format = strtok((char *)emulMsg, NET_NFC_EMUL_MSG_RECORD_SEPERATOR); else name_format = strtok(NULL, NET_NFC_EMUL_MSG_RECORD_SEPERATOR); type_name = strtok(NULL, NET_NFC_EMUL_MSG_RECORD_SEPERATOR); record_id = strtok(NULL, NET_NFC_EMUL_MSG_RECORD_SEPERATOR); - if (index == record_count-1) { + if (index == record_count - 1) { /* the last payload : we have to read sentence fully */ record_payload = strtok(NULL, "\n"); } else { @@ -895,9 +722,9 @@ static bool _net_nfc_change_file_owner_permission(FILE *file) { char *buffer = NULL; size_t buffer_len = 0; - struct passwd pwd = { 0, }; + struct passwd pwd = {0}; struct passwd *pw_inhouse = NULL; - struct group grp = { 0, }; + struct group grp = {0}; struct group *gr_inhouse = NULL; if (file == NULL) @@ -941,7 +768,7 @@ static bool _net_nfc_change_file_owner_permission(FILE *file) static void _net_nfc_store_ndef_message(data_s *data) { - char file_name[1024] = { 0, }; + char file_name[1024] = {0}; FILE *fp = NULL; if (data == NULL) @@ -972,7 +799,7 @@ static void _net_nfc_store_ndef_message(data_s *data) static net_nfc_error_e _net_nfc_retrieve_ndef_message(data_s *data) { - char file_name[1024] = { 0, }; + char file_name[1024] = {0}; FILE *fp = NULL; net_nfc_error_e result = NET_NFC_OK; @@ -1036,9 +863,9 @@ static bool _net_nfc_create_ndef_from_emulMsg(emulMsg_s *emul_msg) int retval = true; net_nfc_error_e result = NET_NFC_OK; - data_s rawdata = { NULL, 0 }; + data_s rawdata = {NULL, 0}; - int record_count = emul_msg->record_count; + int record_count = emul_msg->record_count; if (record_count == 0) return false; @@ -1047,14 +874,14 @@ static bool _net_nfc_create_ndef_from_emulMsg(emulMsg_s *emul_msg) ndef_message_h ndef_message = NULL; int ndef_length = 0; - if ((result = net_nfc_util_create_ndef_message((ndef_message_s **) &ndef_message)) != NET_NFC_OK) + if ((result = net_nfc_util_create_ndef_message((ndef_message_s **)&ndef_message)) != NET_NFC_OK) DEBUG_MSG("failed to create ndef message [%d]", result); /* create records and append it to ndef_msg*/ - emul_msg->record_count = _net_nfc_create_records_from_emulMsg(emul_msg, (ndef_message_s **) &ndef_message, record_count); + emul_msg->record_count = _net_nfc_create_records_from_emulMsg(emul_msg, (ndef_message_s **)&ndef_message, record_count); /* convert ndef msg to raw data */ - ndef_length = net_nfc_util_get_ndef_message_length((ndef_message_s *) ndef_message); + ndef_length = net_nfc_util_get_ndef_message_length((ndef_message_s *)ndef_message); if (!ndef_length) DEBUG_MSG("ndef_message size is zero!"); @@ -1075,21 +902,21 @@ static bool _net_nfc_create_ndef_from_emulMsg(emulMsg_s *emul_msg) return retval; } -static bool _net_nfc_create_emulMsg(emulMsg_s **emul_msg, uint8_t * data, long int size) +static bool _net_nfc_create_emulMsg(emulMsg_s **emul_msg, uint8_t *data, long int size) { DEBUG_EMUL_BEGIN(); char *emulMsgID; char *emulMsgData; - *emul_msg = (emulMsg_s *)calloc(1, sizeof(emulMsg_s)); + *emul_msg = calloc(1, sizeof(emulMsg_s)); if (*emul_msg == NULL) return false; /* emulData => ID : MSG ex) 100:1,1,1,U,samsung,http://www.naver.com */ emulMsgID = strtok((char *)data, NET_NFC_EMUL_MSG_ID_SEPERATOR); if (emulMsgID != NULL) - (*emul_msg)->message_id = (emul_message_id) (atoi(emulMsgID)); + (*emul_msg)->message_id = (emul_message_id)(atoi(emulMsgID)); DEBUG_MSG("emul_msg->message_id >>>>[%d]", (*emul_msg)->message_id); @@ -1104,14 +931,14 @@ static bool _net_nfc_create_emulMsg(emulMsg_s **emul_msg, uint8_t * data, long i { /* get message : Tag Type, Record Count, Records */ int target_type = -1; - char file_data[BUFFER_LENGTH_MAX] = {0, }; + char file_data[BUFFER_LENGTH_MAX] = {0}; int length = 0; sscanf(emulMsgData, NET_NFC_EMUL_TAG_DISCOVERED_DATA_FORMAT, &target_type, &((*emul_msg)->record_count), file_data); - (*emul_msg)->target_type = (emul_target_type) target_type; + (*emul_msg)->target_type = (emul_target_type)target_type; - length = strlen(file_data)+1; + length = strlen(file_data) + 1; _nfc_emul_util_alloc_mem((*emul_msg)->file_data, length); memcpy((*emul_msg)->file_data, file_data, length); @@ -1230,7 +1057,7 @@ static void _net_nfc_target_discovered_cb(emulMsg_s *emul_msg) DEBUG_EMUL_BEGIN(); /* make handle */ - net_nfc_target_handle_s* handle = NULL; + net_nfc_target_handle_s *handle = NULL; int length = 0; __net_nfc_make_valid_target_handle(&handle); @@ -1238,13 +1065,13 @@ static void _net_nfc_target_discovered_cb(emulMsg_s *emul_msg) return; /* make msg */ - net_nfc_request_target_detected_t* target_detected = NULL; - uint8_t device_info[] = { 0x03, 0x55, 0x49, 0x44, 0x07, 0x04, 0x93, 0xB7, 0xD9, 0x5B, 0x02, 0x80, \ + net_nfc_request_target_detected_t *target_detected = NULL; + uint8_t device_info[] = {0x03, 0x55, 0x49, 0x44, 0x07, 0x04, 0x93, 0xB7, 0xD9, 0x5B, 0x02, 0x80, \ 0x08, 0x41, 0x50, 0x50, 0x5F, 0x44, 0x41, 0x54, 0x41, 0x00, 0x03, 0x53, 0x41, 0x4B, \ 0x01, 0x00, 0x04, 0x41, 0x54, 0x51, 0x41, 0x02, 0x44, 0x00, 0x0D, 0x4D, 0x41, 0x58, \ 0x5F, 0x44, 0x41, 0x54, 0x41, 0x5F, 0x52, 0x41, 0x54, 0x45, 0x01, 0x00, 0x08, 0x46, \ 0x57, 0x49, 0x5F, 0x53, 0x46, 0x47, 0x54, 0x01, 0x03, 0x49, 0x44, 0x6D, 0x07, 0x04, \ - 0x93, 0xB7, 0xD9, 0x5B, 0x02, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + 0x93, 0xB7, 0xD9, 0x5B, 0x02, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; length = sizeof(net_nfc_request_target_detected_t) + sizeof(device_info); @@ -1266,11 +1093,11 @@ static void _net_nfc_target_discovered_cb(emulMsg_s *emul_msg) target_detected->handle->connection_id = current_connection_id++; if (target_detected->devType == NET_NFC_NFCIP1_TARGET) { - DEBUG_MSG("set llcp connection type. remote device is target"); + DEBUG_MSG("set llcp connection type. remote device is target"); handle->connection_type = NET_NFC_P2P_CONNECTION_TARGET; _net_nfc_emul_set_is_p2p_attached(true); } else if (target_detected->devType == NET_NFC_NFCIP1_INITIATOR) { - DEBUG_MSG("set llcp connection type. remote device is initiator"); + DEBUG_MSG("set llcp connection type. remote device is initiator"); handle->connection_type = NET_NFC_P2P_CONNECTION_INITIATOR; _net_nfc_emul_set_is_p2p_attached(true); } else { @@ -1320,7 +1147,7 @@ static void _net_nfc_target_detached_cb(void) } } -static void _net_nfc_llcp_data_receive_cb(void* pContext) +static void _net_nfc_llcp_data_receive_cb(void *pContext) { DEBUG_EMUL_BEGIN(); @@ -1340,7 +1167,7 @@ static void _net_nfc_llcp_data_receive_cb(void* pContext) DEBUG_EMUL_END(); } -static void _net_nfc_llcp_data_receive_from_cb(void* pContext) +static void _net_nfc_llcp_data_receive_from_cb(void *pContext) { DEBUG_EMUL_BEGIN(); @@ -1364,11 +1191,11 @@ static void _net_nfc_llcp_create_snep_server_msg(snep_command_field_e resp_field { DEBUG_EMUL_BEGIN(); - uint8_t* temp = Snep_Server_msg->data->buffer; + uint8_t *temp = Snep_Server_msg->data->buffer; uint8_t response = (uint8_t)resp_field; uint8_t version = 0; uint32_t length_field = 0; - data_s rawdata = { NULL, 0 }; + data_s rawdata = {NULL, 0}; version = SNEP_MAJOR_VER; version = (((version << 4) & 0xf0) | (SNEP_MINOR_VER & 0x0f)); @@ -1401,7 +1228,7 @@ static void _net_nfc_llcp_create_snep_server_msg(snep_command_field_e resp_field DEBUG_EMUL_END(); } -static llcp_state_e _net_nfc_get_llcp_state(void* pContext) +static llcp_state_e _net_nfc_get_llcp_state(void *pContext) { DEBUG_EMUL_BEGIN(); llcp_state_e state; @@ -1416,7 +1243,7 @@ static llcp_state_e _net_nfc_get_llcp_state(void* pContext) static bool _net_nfc_make_llcp_data(emulMsg_s *emul_msg) { DEBUG_EMUL_BEGIN(); - data_s rawdata = { NULL, 0 }; + data_s rawdata = {NULL, 0}; _net_nfc_retrieve_ndef_message(&rawdata); _nfc_emul_util_free_mem(rawdata.buffer); @@ -1513,7 +1340,7 @@ static void _net_nfc_send_emulMsg_to_nfc_manager(emulMsg_s *emul_msg) DEBUG_EMUL_END(); } -static void _net_nfc_process_emulMsg(uint8_t * data, long int size) +static void _net_nfc_process_emulMsg(uint8_t *data, long int size) { DEBUG_EMUL_BEGIN(); @@ -1534,11 +1361,11 @@ static void _net_nfc_process_emulMsg(uint8_t * data, long int size) } #ifdef __USE_EPOLL_FOR_FILE__ -static void emul_ReaderThread(void * pArg) +static void emul_ReaderThread(void *pArg) { DEBUG_MSG("emul_ReaderThread START >>>>"); - char file_name[1024] = { 0, }; + char file_name[1024] = {0}; bool condition = true; int emulMsg_file_fd = -1; @@ -1550,7 +1377,7 @@ static void emul_ReaderThread(void * pArg) LOGE("file path : %s", file_name); /* open file for poll */ - emulMsg_file_fd = open(file_name, O_RDONLY|O_NONBLOCK); + emulMsg_file_fd = open(file_name, O_RDONLY | O_NONBLOCK); if (emulMsg_file_fd < 0) { DEBUG_MSG("file open error !!!!"); return; @@ -1563,7 +1390,7 @@ static void emul_ReaderThread(void * pArg) return; } - if ((emulMsg_poll_events = (struct epoll_event *)calloc(1, sizeof(struct epoll_event) * EPOLL_SIZE)) == NULL) { + if ((emulMsg_poll_events = calloc(1, sizeof(struct epoll_event) * EPOLL_SIZE)) == NULL) { DEBUG_MSG("calloc is occured"); close(emulMsg_file_fd); return; @@ -1640,12 +1467,12 @@ static void emul_ReaderThread(void * pArg) #else -static void emul_ReaderThread(void * pArg) +static void emul_ReaderThread(void *pArg) { DEBUG_MSG("emul_ReaderThread START >>>>"); FILE *fp = NULL; - char file_name[1024] = { 0, }; + char file_name[1024] = {0}; char readBuffer[READ_BUFFER_LENGTH_MAX]; @@ -1660,7 +1487,7 @@ static void emul_ReaderThread(void * pArg) LOGE("file path : %s", file_name); time(&curTime); - DEBUG_MSG("Start Current Time [%ld]", (unsigned long) curTime); + DEBUG_MSG("Start Current Time [%ld]", (unsigned long)curTime); /* polling 500 ms */ @@ -1674,14 +1501,14 @@ static void emul_ReaderThread(void * pArg) } else { /* get the modified time of the file */ if (stat(file_name, &st) == 0) { - if ((unsigned long) st.st_mtime <= (unsigned long) curTime) { + if ((unsigned long)st.st_mtime <= (unsigned long)curTime) { fclose(fp); continue; } else { - DEBUG_MSG("FILE Modified Time [%ld]", (unsigned long) st.st_mtime); + DEBUG_MSG("FILE Modified Time [%ld]", (unsigned long)st.st_mtime); /* update current time */ time(&curTime); - DEBUG_MSG("Get New Current Time [%ld]", (unsigned long) curTime); + DEBUG_MSG("Get New Current Time [%ld]", (unsigned long)curTime); } } else { @@ -1697,7 +1524,7 @@ static void emul_ReaderThread(void * pArg) DEBUG_MSG("get DATA >>>> readBuffer [%s]", readBuffer); /* process message */ - _net_nfc_process_emulMsg((uint8_t *) readBuffer, (long int) strlen(readBuffer)); + _net_nfc_process_emulMsg((uint8_t *)readBuffer, (long int)strlen(readBuffer)); fclose(fp); } @@ -1716,7 +1543,7 @@ static bool _net_nfc_emul_controller_start_thread(void) DEBUG_EMUL_BEGIN(); - ret = pthread_create(&gEmulThread, NULL, (emul_Nfc_thread_handler_t)emul_ReaderThread, (void*) "emul_read_thread"); + ret = pthread_create(&gEmulThread, NULL, (emul_Nfc_thread_handler_t)emul_ReaderThread, (void*)"emul_read_thread"); if (ret != 0) return false; @@ -1741,7 +1568,7 @@ static void _net_nfc_emul_controller_stop_thread(void) DEBUG_EMUL_END(); } -static bool net_nfc_emul_controller_init(net_nfc_error_e* result) +static bool net_nfc_emul_controller_init(net_nfc_error_e *result) { bool ret = true; @@ -1797,7 +1624,7 @@ static bool net_nfc_emul_controller_register_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) + net_nfc_error_e *result) { if (result == NULL) return false; @@ -1838,13 +1665,13 @@ static bool net_nfc_emul_controller_get_firmware_version(data_s **data, net_nfc_ DEBUG_EMUL_BEGIN(); - *data = (data_s *)calloc(1, sizeof(data_s)); + *data = calloc(1, sizeof(data_s)); if (*data == NULL) return false; (*data)->length = 10; - (*data)->buffer = (uint8_t *)calloc(1, (*data)->length); + (*data)->buffer = calloc(1, (*data)->length); if ((*data)->buffer == NULL) return false; @@ -1856,7 +1683,7 @@ static bool net_nfc_emul_controller_get_firmware_version(data_s **data, net_nfc_ return true; } -static bool net_nfc_emul_controller_check_firmware_version(net_nfc_error_e* result) +static bool net_nfc_emul_controller_check_firmware_version(net_nfc_error_e *result) { if (result == NULL) return false; @@ -1870,7 +1697,7 @@ static bool net_nfc_emul_controller_check_firmware_version(net_nfc_error_e* resu return true; } -static bool net_nfc_emul_controller_update_firmware(net_nfc_error_e* result) +static bool net_nfc_emul_controller_update_firmware(net_nfc_error_e *result) { if (result == NULL) return false; @@ -1884,7 +1711,7 @@ static bool net_nfc_emul_controller_update_firmware(net_nfc_error_e* result) return true; } -static bool net_nfc_emul_controller_get_stack_information(net_nfc_stack_information_s* stack_info, net_nfc_error_e* result) +static bool net_nfc_emul_controller_get_stack_information(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result) { if (result == NULL) return false; @@ -1898,7 +1725,7 @@ static bool net_nfc_emul_controller_get_stack_information(net_nfc_stack_informat return true; } -static bool net_nfc_emul_controller_configure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result) +static bool net_nfc_emul_controller_configure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result) { int idx; bool ret = true; @@ -1924,7 +1751,7 @@ static bool net_nfc_emul_controller_configure_discovery(net_nfc_discovery_mode_e /* reset socket_info */ for (idx = 0; idx < LLCP_NB_SOCKET_MAX; idx++) - _net_nfc_remove_socket_slot((net_nfc_llcp_socket_t) idx); + _net_nfc_remove_socket_slot((net_nfc_llcp_socket_t)idx); DEBUG_MSG("Kill Thread"); @@ -1942,7 +1769,7 @@ static bool net_nfc_emul_controller_configure_discovery(net_nfc_discovery_mode_e return ret; } -static bool net_nfc_emul_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result) +static bool net_nfc_emul_controller_get_secure_element_list(net_nfc_secure_element_info_s *list, int *count, net_nfc_error_e *result) { if (result == NULL) return false; @@ -1956,7 +1783,7 @@ static bool net_nfc_emul_controller_get_secure_element_list(net_nfc_secure_eleme return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_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 (result == NULL) return false; @@ -1970,14 +1797,14 @@ static bool net_nfc_emul_controller_set_secure_element_mode(net_nfc_secure_eleme return true; } -static bool net_nfc_emul_controller_check_target_presence(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +static bool net_nfc_emul_controller_check_target_presence(net_nfc_target_handle_s *handle, net_nfc_error_e *result) { if (result == NULL) return false; *result = NET_NFC_OK; - usleep(300*1000); + usleep(300 * 1000); if (_net_nfc_emul_get_is_tag_attached()) { return true; @@ -1987,7 +1814,7 @@ static bool net_nfc_emul_controller_check_target_presence(net_nfc_target_handle_ } } -static bool net_nfc_emul_controller_connect(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +static bool net_nfc_emul_controller_connect(net_nfc_target_handle_s *handle, net_nfc_error_e *result) { if (result == NULL) return false; @@ -2006,7 +1833,7 @@ static bool net_nfc_emul_controller_connect(net_nfc_target_handle_s* handle, net return true; } -static bool net_nfc_emul_controller_disconnect(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +static bool net_nfc_emul_controller_disconnect(net_nfc_target_handle_s *handle, net_nfc_error_e *result) { if (result == NULL) return false; @@ -2026,16 +1853,16 @@ static bool net_nfc_emul_controller_disconnect(net_nfc_target_handle_s* handle, /* reset socket_info */ int idx = 0; for (; idx < LLCP_NB_SOCKET_MAX; idx++) - _net_nfc_remove_socket_slot((net_nfc_llcp_socket_t) idx); + _net_nfc_remove_socket_slot((net_nfc_llcp_socket_t)idx); DEBUG_EMUL_END(); return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_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) { - data_s rawdata = { NULL, 0 }; + data_s rawdata = {NULL, 0}; if (result == NULL) return false; @@ -2071,7 +1898,7 @@ static bool net_nfc_emul_controller_check_ndef(net_nfc_target_handle_s* handle, return true; } -static bool net_nfc_emul_controller_make_read_only_ndef(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +static bool net_nfc_emul_controller_make_read_only_ndef(net_nfc_target_handle_s *handle, net_nfc_error_e *result) { if (result == NULL) return false; @@ -2090,10 +1917,10 @@ static bool net_nfc_emul_controller_make_read_only_ndef(net_nfc_target_handle_s* return true; } -static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, data_s** data, net_nfc_error_e* result) +static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result) { int real_data_size = 0; - data_s rawdata = { NULL, 0 }; + data_s rawdata = {NULL, 0}; DEBUG_EMUL_BEGIN(); @@ -2135,7 +1962,7 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d return false; } - *data = (data_s*) calloc(1, sizeof(data_s)); + *data = calloc(1, sizeof(data_s)); if (*data == NULL) { *result = NET_NFC_ALLOC_FAIL; @@ -2144,7 +1971,7 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d } (*data)->length = real_data_size; - (*data)->buffer = (uint8_t *)calloc(1, real_data_size); + (*data)->buffer = calloc(1, real_data_size); if ((*data)->buffer == NULL) { free(*data); @@ -2162,7 +1989,7 @@ static bool net_nfc_emul_controller_read_ndef(net_nfc_target_handle_s* handle, d return true; } -static bool net_nfc_emul_controller_write_ndef(net_nfc_target_handle_s* handle, data_s* data, net_nfc_error_e* result) +static bool net_nfc_emul_controller_write_ndef(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result) { if (result == NULL) return false; @@ -2217,7 +2044,7 @@ static bool net_nfc_emul_controller_transceive(net_nfc_target_handle_s *handle, return ret; } -static bool net_nfc_emul_controller_format_ndef(net_nfc_target_handle_s* handle, data_s* secure_key, net_nfc_error_e* result) +static bool net_nfc_emul_controller_format_ndef(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result) { if (result == NULL) return false; @@ -2252,7 +2079,7 @@ static bool net_nfc_emul_controller_exception_handler(void) return true; } -static bool net_nfc_emul_controller_is_ready(net_nfc_error_e* result) +static bool net_nfc_emul_controller_is_ready(net_nfc_error_e *result) { if (result == NULL) return false; @@ -2271,7 +2098,7 @@ static bool net_nfc_emul_controller_is_ready(net_nfc_error_e* result) * LLCP definition * ********************/ -static bool net_nfc_emul_controller_llcp_config(net_nfc_llcp_config_info_s * config, net_nfc_error_e * result) +static bool net_nfc_emul_controller_llcp_config(net_nfc_llcp_config_info_s *config, net_nfc_error_e *result) { if (result == NULL) return false; @@ -2285,7 +2112,7 @@ static bool net_nfc_emul_controller_llcp_config(net_nfc_llcp_config_info_s * con return true; } -static bool net_nfc_emul_controller_llcp_check_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +static bool net_nfc_emul_controller_llcp_check_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result) { if (result == NULL) return false; @@ -2304,7 +2131,7 @@ static bool net_nfc_emul_controller_llcp_check_llcp(net_nfc_target_handle_s* han return true; } -static bool net_nfc_emul_controller_llcp_activate_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +static bool net_nfc_emul_controller_llcp_activate_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result) { if (result == NULL) return false; @@ -2323,7 +2150,7 @@ static bool net_nfc_emul_controller_llcp_activate_llcp(net_nfc_target_handle_s* return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_controller_llcp_create_socket(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, void *user_param) { if (result == NULL) return false; @@ -2333,7 +2160,7 @@ static bool net_nfc_emul_controller_llcp_create_socket(net_nfc_llcp_socket_t* so DEBUG_EMUL_BEGIN(); /* get available socket */ - socket_info_s* socket_info = _net_nfc_get_available_socket_slot(); + socket_info_s *socket_info = _net_nfc_get_available_socket_slot(); if (socket_info == NULL) { DEBUG_ERR_MSG("The available socket is nothing!!"); return false; @@ -2354,19 +2181,19 @@ static bool net_nfc_emul_controller_llcp_create_socket(net_nfc_llcp_socket_t* so } else if (llcp_state == NET_NFC_STATE_EXCHANGER_SERVER_NPP) { DEBUG_MSG("NET_NFC_STATE_EXCHANGER_SERVER_NPP"); - *socket = NET_NFC_EMUL_NPP_SERVER_SOCKET_NUMBER; + *socket = NET_NFC_EMUL_NPP_SERVER_SOCKET_NUMBER; } else if (llcp_state == NET_NFC_STATE_EXCHANGER_CLIENT) { DEBUG_MSG("NET_NFC_STATE_EXCHANGER_CLIENT"); - *socket = NET_NFC_EMUL_CLIENT_SOCKET_NUMBER; + *socket = NET_NFC_EMUL_CLIENT_SOCKET_NUMBER; } else if (llcp_state == NET_NFC_STATE_CONN_HANDOVER_REQUEST) { DEBUG_MSG("NET_NFC_STATE_CONN_HANDOVER_REQUEST"); - *socket = NET_NFC_EMUL_HANDOVER_REQUEST_SOCKET_NUMBER; + *socket = NET_NFC_EMUL_HANDOVER_REQUEST_SOCKET_NUMBER; } else if (llcp_state == NET_NFC_STATE_CONN_HANDOVER_SELECT) { DEBUG_MSG("NET_NFC_STATE_CONN_HANDOVER_SELECT"); - *socket = NET_NFC_EMUL_HANDOVER_SELECT_SOCKET_NUMBER; + *socket = NET_NFC_EMUL_HANDOVER_SELECT_SOCKET_NUMBER; } else { DEBUG_MSG("we doesn't support.."); @@ -2376,14 +2203,14 @@ static bool net_nfc_emul_controller_llcp_create_socket(net_nfc_llcp_socket_t* so DEBUG_MSG("socket is created = [0x%x]", *socket); socket_info->socket_handle = *socket; - socket_info->user_context = (void *) user_param; + socket_info->user_context = (void *)user_param; DEBUG_EMUL_END(); return true; } -static bool net_nfc_emul_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result) +static bool net_nfc_emul_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result) { if (result == NULL) return false; @@ -2397,7 +2224,7 @@ static bool net_nfc_emul_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_controller_llcp_listen(net_nfc_target_handle_s *handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param) { if (result == NULL) return false; @@ -2455,7 +2282,7 @@ static bool net_nfc_emul_controller_llcp_listen(net_nfc_target_handle_s* handle, } /* below accept function does not used. */ -static bool net_nfc_emul_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void *user_param) +static bool net_nfc_emul_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param) { if (result == NULL) return false; @@ -2469,7 +2296,7 @@ static bool net_nfc_emul_controller_llcp_accept(net_nfc_llcp_socket_t socket, ne return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_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) { if (result == NULL) return false; @@ -2501,7 +2328,7 @@ static bool net_nfc_emul_controller_llcp_connect(net_nfc_target_handle_s* handle return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_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) { if (result == NULL) return false; @@ -2533,7 +2360,7 @@ static bool net_nfc_emul_controller_llcp_connect_by_url(net_nfc_target_handle_s* return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_controller_llcp_send(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param) { if (result == NULL) return false; @@ -2582,7 +2409,7 @@ static bool net_nfc_emul_controller_llcp_send(net_nfc_target_handle_s* handle, n return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_controller_llcp_send_to(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point, net_nfc_error_e *result, void *user_param) { if (result == NULL) return false; @@ -2632,7 +2459,7 @@ static bool net_nfc_emul_controller_llcp_send_to(net_nfc_target_handle_s* handle } -static bool net_nfc_emul_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) +static bool net_nfc_emul_controller_llcp_recv(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param) { if (result == NULL || data == NULL) return false; @@ -2678,14 +2505,14 @@ static bool net_nfc_emul_controller_llcp_recv(net_nfc_target_handle_s* handle, n DEBUG_MSG("send last segment >>>"); llcp_server_data->length = remained_size; - memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer+Snep_Server_msg->offset , remained_size); + memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer + Snep_Server_msg->offset, remained_size); Snep_Server_msg->isSegment = false; } else { DEBUG_MSG("send continue segment >>>"); llcp_server_data->length = SNEP_MAX_BUFFER; - memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer+Snep_Server_msg->offset, SNEP_MAX_BUFFER); + memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer + Snep_Server_msg->offset, SNEP_MAX_BUFFER); Snep_Server_msg->offset += SNEP_MAX_BUFFER; } @@ -2706,7 +2533,7 @@ static bool net_nfc_emul_controller_llcp_recv(net_nfc_target_handle_s* handle, n return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_controller_llcp_recv_from(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param) { if (result == NULL) return false; @@ -2752,14 +2579,14 @@ static bool net_nfc_emul_controller_llcp_recv_from(net_nfc_target_handle_s* hand DEBUG_MSG("send last segment >>>"); llcp_server_data->length = remained_size; - memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer+Snep_Server_msg->offset , remained_size); + memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer + Snep_Server_msg->offset, remained_size); Snep_Server_msg->isSegment = false; } else { DEBUG_MSG("send continue segment >>>"); llcp_server_data->length = SNEP_MAX_BUFFER; - memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer+Snep_Server_msg->offset, SNEP_MAX_BUFFER); + memcpy(llcp_server_data->buffer, Snep_Server_msg->data->buffer + Snep_Server_msg->offset, SNEP_MAX_BUFFER); Snep_Server_msg->offset += SNEP_MAX_BUFFER; } @@ -2785,7 +2612,7 @@ static bool net_nfc_emul_controller_llcp_recv_from(net_nfc_target_handle_s* hand return true; } -static bool net_nfc_emul_controller_llcp_disconnect(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param) +static bool net_nfc_emul_controller_llcp_disconnect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param) { if (result == NULL) return false; @@ -2829,14 +2656,15 @@ static bool net_nfc_emul_controller_llcp_disconnect(net_nfc_target_handle_s* han } /* reset socket_info */ - _net_nfc_remove_socket_slot((net_nfc_llcp_socket_t) socket); + _net_nfc_remove_socket_slot((net_nfc_llcp_socket_t)socket); DEBUG_EMUL_END(); return true; } -static bool net_nfc_emul_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e* result) +static bool net_nfc_emul_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, + net_nfc_error_e *result) { if (result == NULL) return false; @@ -2850,7 +2678,7 @@ static bool net_nfc_emul_controller_llcp_socket_close(net_nfc_llcp_socket_t sock return true; } -static bool net_nfc_emul_controller_llcp_reject(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result) +static bool net_nfc_emul_controller_llcp_reject(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result) { if (result == NULL) return false; @@ -2869,7 +2697,7 @@ static bool net_nfc_emul_controller_llcp_reject(net_nfc_target_handle_s* handle, return true; } -static bool net_nfc_emul_controller_llcp_get_remote_config(net_nfc_target_handle_s* handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e* result) +static bool net_nfc_emul_controller_llcp_get_remote_config(net_nfc_target_handle_s *handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e *result) { /* In llcp specification ver 1.1, default miu size is 128 */ const uint16_t default_miu = 128; @@ -2893,7 +2721,7 @@ static bool net_nfc_emul_controller_llcp_get_remote_config(net_nfc_target_handle return true; } -static bool net_nfc_emul_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) +static bool net_nfc_emul_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) { /* In llcp specification ver 1.1, default miu size is 128 */ const uint16_t default_miu = 128; @@ -2921,7 +2749,7 @@ static bool net_nfc_emul_controller_llcp_get_remote_socket_info(net_nfc_target_h static bool net_nfc_emul_controller_support_nfc(net_nfc_error_e *result) { bool ret = false; - struct stat st = { 0, }; + struct stat st = {0}; if (stat("/dev/nfc0", &st) == -1) { if (result) @@ -2946,7 +2774,7 @@ static bool net_nfc_emul_controller_secure_element_open(net_nfc_secure_element_t return true; } static bool net_nfc_emul_controller_secure_element_get_atr(net_nfc_target_handle_s *handle, - data_s **atr, net_nfc_error_e *result) + data_s **atr, net_nfc_error_e *result) { bool ret = true; char buffer[1024]; @@ -2959,9 +2787,9 @@ static bool net_nfc_emul_controller_secure_element_get_atr(net_nfc_target_handle strncpy(buffer, "getatr", sizeof(buffer)); - temp = (data_s *)calloc(1, sizeof(*temp)); + temp = calloc(1, sizeof(*temp)); if (temp != NULL) { - temp->buffer = (uint8_t *)calloc(1, length); + temp->buffer = calloc(1, length); if (temp->buffer != NULL) { memcpy(temp->buffer, buffer, length); temp->length = length; @@ -2980,7 +2808,7 @@ static bool net_nfc_emul_controller_secure_element_get_atr(net_nfc_target_handle return ret; } static bool net_nfc_emul_controller_secure_element_send_apdu(net_nfc_target_handle_s *handle, - data_s *command, data_s **response, net_nfc_error_e *result) + data_s *command, data_s **response, net_nfc_error_e *result) { bool ret = true; char buffer[1024]; @@ -2997,9 +2825,9 @@ static bool net_nfc_emul_controller_secure_element_send_apdu(net_nfc_target_hand length = strlen(buffer); - temp = (data_s *)calloc(1, sizeof(*temp)); + temp = calloc(1, sizeof(*temp)); if (temp != NULL) { - temp->buffer = (uint8_t *)calloc(1, length + 1); + temp->buffer = calloc(1, length + 1); if (temp->buffer != NULL) { memcpy(temp->buffer, buffer, sizeof(temp->buffer) - 1); temp->length = length; @@ -3012,15 +2840,15 @@ static bool net_nfc_emul_controller_secure_element_send_apdu(net_nfc_target_hand ret = false; } } else { - *result = NET_NFC_ALLOC_FAIL; - ret = false; + *result = NET_NFC_ALLOC_FAIL; + ret = false; } DEBUG_ERR_MSG("se send apdu end"); return ret; } static bool net_nfc_emul_controller_secure_element_close(net_nfc_target_handle_s *handle, - net_nfc_error_e *result) + net_nfc_error_e *result) { DEBUG_ERR_MSG("se close start"); *result = NET_NFC_OK; @@ -3028,4 +2856,68 @@ static bool net_nfc_emul_controller_secure_element_close(net_nfc_target_handle_s DEBUG_ERR_MSG("se close end"); } -////////////// INTERFACE END ////////// +__attribute__((visibility("default"))) bool onload(net_nfc_oem_interface_s *emul_interfaces) +{ + DEBUG_EMUL_BEGIN(); + + emul_interfaces->init = net_nfc_emul_controller_init; + emul_interfaces->deinit = net_nfc_emul_controller_deinit; + emul_interfaces->register_listener = net_nfc_emul_controller_register_listener; + emul_interfaces->unregister_listener = net_nfc_emul_controller_unregister_listener; + emul_interfaces->get_firmware_version = net_nfc_emul_controller_get_firmware_version; + emul_interfaces->check_firmware_version = net_nfc_emul_controller_check_firmware_version; + emul_interfaces->update_firmeware = net_nfc_emul_controller_update_firmware; + emul_interfaces->get_stack_information = net_nfc_emul_controller_get_stack_information; + emul_interfaces->configure_discovery = net_nfc_emul_controller_configure_discovery; + emul_interfaces->get_secure_element_list = net_nfc_emul_controller_get_secure_element_list; + emul_interfaces->set_secure_element_mode = net_nfc_emul_controller_set_secure_element_mode; + emul_interfaces->connect = net_nfc_emul_controller_connect; + emul_interfaces->disconnect = net_nfc_emul_controller_disconnect; + emul_interfaces->check_ndef = net_nfc_emul_controller_check_ndef; + emul_interfaces->check_presence = net_nfc_emul_controller_check_target_presence; + emul_interfaces->read_ndef = net_nfc_emul_controller_read_ndef; + emul_interfaces->write_ndef = net_nfc_emul_controller_write_ndef; + emul_interfaces->make_read_only_ndef = net_nfc_emul_controller_make_read_only_ndef; + emul_interfaces->transceive = net_nfc_emul_controller_transceive; + emul_interfaces->format_ndef = net_nfc_emul_controller_format_ndef; + emul_interfaces->exception_handler = net_nfc_emul_controller_exception_handler; + emul_interfaces->is_ready = net_nfc_emul_controller_is_ready; + + emul_interfaces->config_llcp = net_nfc_emul_controller_llcp_config; + emul_interfaces->check_llcp_status = net_nfc_emul_controller_llcp_check_llcp; + emul_interfaces->activate_llcp = net_nfc_emul_controller_llcp_activate_llcp; + emul_interfaces->create_llcp_socket = net_nfc_emul_controller_llcp_create_socket; + emul_interfaces->bind_llcp_socket = net_nfc_emul_controller_llcp_bind; + emul_interfaces->listen_llcp_socket = net_nfc_emul_controller_llcp_listen; + emul_interfaces->accept_llcp_socket = net_nfc_emul_controller_llcp_accept; + emul_interfaces->connect_llcp_by_url = net_nfc_emul_controller_llcp_connect_by_url; + emul_interfaces->connect_llcp = net_nfc_emul_controller_llcp_connect; + emul_interfaces->disconnect_llcp = net_nfc_emul_controller_llcp_disconnect; + emul_interfaces->close_llcp_socket = net_nfc_emul_controller_llcp_socket_close; + emul_interfaces->recv_llcp = net_nfc_emul_controller_llcp_recv; + emul_interfaces->send_llcp = net_nfc_emul_controller_llcp_send; + emul_interfaces->recv_from_llcp = net_nfc_emul_controller_llcp_recv_from; + emul_interfaces->send_to_llcp = net_nfc_emul_controller_llcp_send_to; + emul_interfaces->reject_llcp = net_nfc_emul_controller_llcp_reject; + emul_interfaces->get_remote_config = net_nfc_emul_controller_llcp_get_remote_config; + emul_interfaces->get_remote_socket_info = net_nfc_emul_controller_llcp_get_remote_socket_info; + + emul_interfaces->support_nfc = net_nfc_emul_controller_support_nfc; + + emul_interfaces->secure_element_open = net_nfc_emul_controller_secure_element_open; + emul_interfaces->secure_element_get_atr = net_nfc_emul_controller_secure_element_get_atr; + emul_interfaces->secure_element_send_apdu = net_nfc_emul_controller_secure_element_send_apdu; + emul_interfaces->secure_element_close = net_nfc_emul_controller_secure_element_close; + + emul_interfaces->hce_response_apdu = NULL; + emul_interfaces->route_aid = NULL; + emul_interfaces->unroute_aid = NULL; + emul_interfaces->commit_routing = NULL; + emul_interfaces->set_default_route = NULL; + emul_interfaces->clear_aid_table = NULL; + emul_interfaces->get_aid_tablesize = NULL; + + DEBUG_EMUL_END(); + + return true; +} -- 2.7.4 From 2fa0e80aed05754d6148152c42dd0485f41319f5 Mon Sep 17 00:00:00 2001 From: Youngjae Shin Date: Fri, 14 Aug 2020 15:42:13 +0900 Subject: [PATCH 14/16] increase code quality separate big function add storage class specifier(static) Change-Id: I680e8069fa9ce5ac25846a54cfa1e0559f10917a --- src/oem_emul.c | 386 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 211 insertions(+), 175 deletions(-) diff --git a/src/oem_emul.c b/src/oem_emul.c index b5acb0a..cd29c58 100644 --- a/src/oem_emul.c +++ b/src/oem_emul.c @@ -181,7 +181,7 @@ static llcp_event_listener_cb g_emul_controller_llcp_cb; static hce_apdu_listener_cb g_emul_controller_hce_cb; /* for emulator management */ -pthread_t gEmulThread; +static pthread_t gEmulThread; /* for stack management */ static net_nfc_target_handle_s *current_working_handle = NULL; @@ -191,12 +191,12 @@ static bool g_p2p_attached = 0; static int current_connection_id = 1; /* for llcp functionality */ -socket_info_s socket_info_array[LLCP_NB_SOCKET_MAX] = { {0, } }; +static socket_info_s socket_info_array[LLCP_NB_SOCKET_MAX] = {{0}}; -snep_msg_s *Snep_Server_msg; -data_s *llcp_server_data = NULL; +static snep_msg_s *Snep_Server_msg; +static data_s *llcp_server_data = NULL; -pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; /* Memory utils */ @@ -230,11 +230,9 @@ static void __nfc_emul_util_alloc_mem(void **mem, int size, char *filename, unsi if (*mem != NULL) LOGE("FILE: %s, LINE:%d, WARNING: Pointer is already allocated or it was not initialized with NULL", filename, line); - *mem = malloc(size); + *mem = calloc(1, size); - if (*mem != NULL) - memset(*mem, 0x0, size); - else + if (NULL == *mem) LOGE("FILE: %s, LINE:%d, Allocation is failed", filename, line); } @@ -446,6 +444,168 @@ static net_nfc_record_tnf_e _net_nfc_get_tnf_type(int name_format) } +static inline int _create_records_well_known(emulMsg_data_s *record, char *record_payload, ndef_record_h *new_record) +{ + if (!strncmp((char *)record->typeName.buffer, "U", 1)) { + DEBUG_MSG("URI Type "); + + data_s payload_data = {NULL, 0}; + + if (record->payload.buffer != NULL) { + payload_data.length = strlen(record_payload) + 1; + + _nfc_emul_util_alloc_mem(payload_data.buffer, payload_data.length); + if (payload_data.buffer == NULL) { + DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); + return -1; + } + + payload_data.buffer[0] = NET_NFC_SCHEMA_FULL_URI; /* first byte of payload is protocol scheme */ + memcpy(payload_data.buffer + 1, record->payload.buffer, payload_data.length - 1); + } + + if (net_nfc_util_create_record(record->tnf, &record->typeName, &record->id, &payload_data, (ndef_record_s**)new_record) != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_util_create_record is failed"); + return -1; + } + + if (payload_data.buffer != NULL) + _nfc_emul_util_free_mem(payload_data.buffer); + } else if (!strncmp((char *)record->typeName.buffer, "T", 1)) { + DEBUG_MSG("TEXT Type "); + + data_s payload_data = {NULL, 0}; + int offset = 0; + int controll_byte; + + if (record->payload.buffer != NULL) { + payload_data.length = strlen((char *)record_payload) + strlen("en-US") + 1; + + _nfc_emul_util_alloc_mem(payload_data.buffer, payload_data.length); + if (payload_data.buffer == NULL) { + DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); + return -1; + } + + controll_byte = strlen("en-US") & 0x3F; + + payload_data.buffer[0] = controll_byte; + + offset = 1; + memcpy(payload_data.buffer + offset, "en-US", strlen("en-US")); + + offset = offset + strlen("en-US"); + memcpy(payload_data.buffer + offset, record->payload.buffer, strlen(record_payload)); + } + + if (net_nfc_util_create_record(record->tnf, &record->typeName, &record->id, &payload_data, (ndef_record_s**)new_record) != NET_NFC_OK) { + DEBUG_ERR_MSG("net_nfc_util_create_record is failed"); + return -1; + } + + if (payload_data.buffer != NULL) + _nfc_emul_util_free_mem(payload_data.buffer); + } else { + DEBUG_ERR_MSG("NET_NFC_RECORD_WELL_KNOWN_TYPE >> typeName is wrong"); + return -1; + } + return 0; +} + +static inline int _create_records_mime(emulMsg_data_s *record, char *record_payload, ndef_record_h *new_record) +{ + FILE *file = NULL; + data_s filePayload = {NULL, 0}; + + /* open file : size limit? 10k? */ + file = fopen(record_payload, "r"); + if (file != NULL) { + long int file_len = 0, read_count = 0, read_total = 0; + uint8_t *file_data = NULL; + + fseek(file, 0, SEEK_END); + file_len = ftell(file); + fseek(file, 0, SEEK_SET); + + _nfc_emul_util_alloc_mem(file_data, file_len); + + if (file_data == NULL) { + DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); + fclose(file); + return -1; + } + + /* create payload */ + do { + read_count = fread(file_data + read_total, 1, file_len - read_total, file); + read_total += read_count; + } while (read_count != 0 && read_total < file_len); + + fclose(file); + + DEBUG_MSG("fread(%s) success, size %ld", record->payload.buffer, file_len); + + filePayload.length = file_len; + _nfc_emul_util_alloc_mem(filePayload.buffer, filePayload.length); + + if (filePayload.buffer == NULL) { + DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); + _nfc_emul_util_free_mem(file_data); + return -1; + } + memcpy(filePayload.buffer, file_data, filePayload.length); + + _nfc_emul_util_free_mem(file_data); + + /* set id */ + if (record->id.buffer == NULL) { + char *file_name = NULL; + + file_name = strrchr(record_payload, '/'); + if (file_name == NULL) + file_name = (char *)record_payload; + else + file_name++; + + record->id.length = strlen(file_name); + _nfc_emul_util_alloc_mem(record->id.buffer, record->id.length + 1); + + if (record->id.buffer == NULL) { + DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); + _nfc_emul_util_free_mem(filePayload.buffer); + return -1; + } + memcpy(record->id.buffer, file_name, sizeof(record->id.buffer) - 1); + } + } else { + DEBUG_MSG("file open error"); + return -1; + } + + /* create record */ + int ret = net_nfc_util_create_record(record->tnf, &record->typeName, &record->id, + &filePayload, (ndef_record_s **)new_record); + _nfc_emul_util_free_mem(filePayload.buffer); + if (ret != NET_NFC_OK) { + DEBUG_MSG("net_nfc_create_record failed[%d]", ret); + return -1; + } else { + return 0; + } +} + +static void _create_records_free(emulMsg_data_s *record) +{ + if (record->typeName.buffer) + _nfc_emul_util_free_mem(record->typeName.buffer); + + if (record->id.buffer) + _nfc_emul_util_free_mem(record->id.buffer); + + if (record->payload.buffer) + _nfc_emul_util_free_mem(record->payload.buffer); +} + static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_message_s **ndef_message, int record_count) { DEBUG_EMUL_BEGIN(); @@ -464,7 +624,6 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag char *record_payload; emulMsg_data_s record = {0}; - data_s filePayload = {NULL, 0}; /* parse string */ if (index == 0) @@ -491,7 +650,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag if (record.typeName.buffer == NULL) { DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); - goto ERROR; + return create_record_count; } memcpy(record.typeName.buffer, type_name, sizeof(record.typeName.buffer) - 1); @@ -502,7 +661,8 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag if (record.id.buffer == NULL) { DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); - goto ERROR; + _nfc_emul_util_free_mem(record.typeName.buffer); + return create_record_count; } memcpy(record.id.buffer, record_id, sizeof(record.id.buffer) - 1); @@ -513,7 +673,9 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag if (record.payload.buffer == NULL) { DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); - goto ERROR; + _nfc_emul_util_free_mem(record.typeName.buffer); + _nfc_emul_util_free_mem(record.id.buffer); + return create_record_count; } memcpy(record.payload.buffer, record_payload, sizeof(record.payload.buffer) - 1); @@ -530,187 +692,61 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag ndef_record_h new_record = NULL; net_nfc_error_e result = NET_NFC_OK; - if (record.tnf == NET_NFC_RECORD_EMPTY) { - if ((result = net_nfc_util_create_record(NET_NFC_RECORD_EMPTY, &record.typeName, &record.id, &record.payload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { + switch (record.tnf) { + case NET_NFC_RECORD_EMPTY: + result = net_nfc_util_create_record(NET_NFC_RECORD_EMPTY, &record.typeName, + &record.id, &record.payload, (ndef_record_s **)&new_record); + if (NET_NFC_OK != result) { DEBUG_MSG("net_nfc_create_record failed[%d]", result); - goto ERROR;; + _create_records_free(&record); + return create_record_count; } - } else if (record.tnf == NET_NFC_RECORD_UNKNOWN) { - if ((result = net_nfc_util_create_record(NET_NFC_RECORD_UNKNOWN, &record.typeName, &record.id, &record.payload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { + break; + case NET_NFC_RECORD_UNKNOWN: + result = net_nfc_util_create_record(NET_NFC_RECORD_UNKNOWN, &record.typeName, + &record.id, &record.payload, (ndef_record_s **)&new_record); + if (NET_NFC_OK != result) { DEBUG_MSG("net_nfc_create_record failed[%d]", result); - goto ERROR;; - } - } else if (record.tnf == NET_NFC_RECORD_WELL_KNOWN_TYPE) { - if (!strncmp((char *)record.typeName.buffer, "U", 1)) { - DEBUG_MSG("URI Type "); - - data_s payload_data = { NULL, 0 }; - - if (record.payload.buffer != NULL) { - payload_data.length = strlen((char *)record_payload) + 1; - - _nfc_emul_util_alloc_mem(payload_data.buffer, payload_data.length); - if (payload_data.buffer == NULL) { - DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); - goto ERROR; - } - - payload_data.buffer[0] = NET_NFC_SCHEMA_FULL_URI; /* first byte of payload is protocol scheme */ - memcpy(payload_data.buffer + 1, record.payload.buffer, payload_data.length - 1); - } - - if (net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &payload_data, (ndef_record_s**) &new_record) != NET_NFC_OK) { - DEBUG_ERR_MSG("net_nfc_util_create_record is failed"); - goto ERROR; - } - - if (payload_data.buffer != NULL) - _nfc_emul_util_free_mem(payload_data.buffer); - } else if (!strncmp((char *)record.typeName.buffer, "T", 1)) { - DEBUG_MSG("TEXT Type "); - - data_s payload_data = { NULL, 0 }; - int offset = 0; - int controll_byte; - - if (record.payload.buffer != NULL) { - payload_data.length = strlen((char *)record_payload) + strlen("en-US") + 1; - - _nfc_emul_util_alloc_mem(payload_data.buffer, payload_data.length); - if (payload_data.buffer == NULL) { - DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); - goto ERROR; - } - - controll_byte = strlen("en-US") & 0x3F; - - payload_data.buffer[0] = controll_byte; - - offset = 1; - memcpy(payload_data.buffer + offset, "en-US", strlen("en-US")); - - offset = offset + strlen("en-US"); - memcpy(payload_data.buffer + offset, record.payload.buffer, strlen(record_payload)); - } - - if (net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &payload_data, (ndef_record_s**) &new_record) != NET_NFC_OK) { - DEBUG_ERR_MSG("net_nfc_util_create_record is failed"); - goto ERROR; - } - - if (payload_data.buffer != NULL) - _nfc_emul_util_free_mem(payload_data.buffer); - } else { - DEBUG_ERR_MSG("NET_NFC_RECORD_WELL_KNOWN_TYPE >> typeName is wrong"); - goto ERROR; + _create_records_free(&record); + return create_record_count; } - } else if ((record.tnf == NET_NFC_RECORD_MIME_TYPE)) { - FILE *file = NULL; - - /* open file : size limit? 10k? */ - file = fopen(record_payload, "r"); - if (file != NULL) { - long int file_len = 0, read_count = 0, read_total = 0; - uint8_t *file_data = NULL; - - fseek(file, 0, SEEK_END); - file_len = ftell(file); - fseek(file, 0, SEEK_SET); - - _nfc_emul_util_alloc_mem(file_data, file_len); - - if (file_data == NULL) { - DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); - fclose(file); - goto ERROR; - } - - /* create payload */ - do { - read_count = fread(file_data + read_total, 1, file_len - read_total, file); - read_total += read_count; - } while (read_count != 0 && read_total < file_len); - - fclose(file); - - DEBUG_MSG("fread(%s) success, size %ld", record.payload.buffer, file_len); - - filePayload.length = file_len; - _nfc_emul_util_alloc_mem(filePayload.buffer, filePayload.length); - - if (filePayload.buffer == NULL) { - DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); - _nfc_emul_util_free_mem(file_data); - goto ERROR; - } - memcpy(filePayload.buffer, file_data, filePayload.length); - - _nfc_emul_util_free_mem(file_data); - - /* set id */ - if (record.id.buffer == NULL) { - char *file_name = NULL; - - file_name = strrchr(record_payload, '/'); - if (file_name == NULL) - file_name = (char *) record_payload; - else - file_name++; - - record.id.length = strlen(file_name); - _nfc_emul_util_alloc_mem(record.id.buffer, record.id.length + 1); - - if (record.id.buffer == NULL) { - DEBUG_MSG("_nfc_emul_util_alloc_mem failed"); - _nfc_emul_util_free_mem(filePayload.buffer); - goto ERROR; - } - memcpy(record.id.buffer, file_name, sizeof(record.id.buffer) - 1); - } - } else { - DEBUG_MSG("file open error"); - goto ERROR;; + break; + case NET_NFC_RECORD_WELL_KNOWN_TYPE: + if (_create_records_well_known(&record, record_payload, &new_record) < 0) { + _create_records_free(&record); + return create_record_count; } - - /* create record */ - if ((result = net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &filePayload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { - DEBUG_MSG("net_nfc_create_record failed[%d]", result); - goto ERROR;; + break; + case NET_NFC_RECORD_MIME_TYPE: + if (_create_records_mime(&record, record_payload, &new_record) < 0) { + _create_records_free(&record); + return create_record_count; } - } else { + break; + default: /* NET_NFC_RECORD_URI or NET_NFC_RECORD_EXTERNAL_RTD */ - if ((result = net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &record.payload, (ndef_record_s **) &new_record)) != NET_NFC_OK) { + result = net_nfc_util_create_record(record.tnf, &record.typeName, + &record.id, &record.payload, (ndef_record_s **)&new_record); + if (NET_NFC_OK != result) { DEBUG_MSG("net_nfc_create_record failed[%d]", result); - goto ERROR;; + _create_records_free(&record); + return create_record_count; } + break; } /* append record to ndef msg */ - if ((result = net_nfc_util_append_record((ndef_message_s*) *ndef_message, (ndef_record_s *) new_record)) != NET_NFC_OK) { + if ((result = net_nfc_util_append_record((ndef_message_s*)*ndef_message, (ndef_record_s *)new_record)) != NET_NFC_OK) { DEBUG_MSG("net_nfc_util_append_record failed[%d]", result); - goto ERROR;; + _create_records_free(&record); + return create_record_count; } create_record_count++; DEBUG_MSG("Create Record Sucess. Create Record Count[%d]", create_record_count); - continue; -ERROR: - - /* free data */ - if (record.typeName.buffer != NULL) - _nfc_emul_util_free_mem(record.typeName.buffer); - - if (record.id.buffer != NULL) - _nfc_emul_util_free_mem(record.id.buffer); - - if (record.payload.buffer != NULL) - _nfc_emul_util_free_mem(record.payload.buffer); - - if (filePayload.buffer != NULL) - _nfc_emul_util_free_mem(filePayload.buffer); + _create_records_free(&record); DEBUG_MSG("Create Record Loop End"); - break; } DEBUG_EMUL_END(); -- 2.7.4 From 35d77b9e8c200cd2ee788df25877afab02d346a4 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Mon, 15 Feb 2021 17:23:36 +0900 Subject: [PATCH 15/16] NFC hal : Change for nfc backend operation - And, Remove dependency with nfc fw Change-Id: I38bdbe42a22f64c89223edc9b9aad89d59658d67 Signed-off-by: Jihoon Jung --- CMakeLists.txt | 8 +- packaging/nfc-plugin-emul.spec | 8 +- src/oem_emul.c | 563 +++++++++++++++++++++++++++++++++++------ 3 files changed, 489 insertions(+), 90 deletions(-) mode change 100644 => 100755 src/oem_emul.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7388580..871cbea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,12 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(nfc-plugin C) +PROJECT(hal-backend-nfc C) INCLUDE(FindPkgConfig) SET(EXTRA_FLAGS "-Wall -Werror -fvisibility=hidden") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS}") -pkg_check_modules(pkgs REQUIRED dlog nfc-common-lib vconf) +pkg_check_modules(pkgs REQUIRED dlog vconf hal-api-nfc hal-api-common) INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS}) LINK_DIRECTORIES(${pkgs_LIBRARY_DIRS}) @@ -14,5 +14,5 @@ FILE(GLOB SRCS src/*.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_COMPILE_OPTIONS(${PROJECT_NAME} PUBLIC ${pkgs_CFLAGS_OTHER}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LIBRARIES} pthread) -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib/nfc) -INSTALL(FILES 98-${PROJECT_NAME}-emul.rules DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/udev/rules.d/) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_PATH}) +INSTALL(FILES 98-nfc-plugin-emul.rules DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/udev/rules.d/) diff --git a/packaging/nfc-plugin-emul.spec b/packaging/nfc-plugin-emul.spec index 2424e16..f0ca530 100644 --- a/packaging/nfc-plugin-emul.spec +++ b/packaging/nfc-plugin-emul.spec @@ -8,8 +8,9 @@ Source0: %{name}-%{version}.tar.gz Source1001: %{name}.manifest BuildRequires: cmake BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(nfc-common-lib) BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(hal-api-nfc) +BuildRequires: pkgconfig(hal-api-common) %description NFC Plugin Emul @@ -19,7 +20,8 @@ NFC Plugin Emul cp %{SOURCE1001} ./%{name}.manifest %build -%cmake . -DCMAKE_VERBOSE_MAKEFILE=OFF +%cmake . -DCMAKE_VERBOSE_MAKEFILE=OFF \ + -DHAL_PATH=%{_hal_libdir} make %{?_smp_mflags} %install @@ -27,6 +29,6 @@ make %{?_smp_mflags} %files %manifest %{name}.manifest -/usr/lib/nfc/libnfc-plugin.so +%{_hal_libdir}/*.so* %{_prefix}/lib/udev/rules.d/98-%{name}.rules %license LICENSE.APLv2 diff --git a/src/oem_emul.c b/src/oem_emul.c old mode 100644 new mode 100755 index cd29c58..8d55576 --- a/src/oem_emul.c +++ b/src/oem_emul.c @@ -26,13 +26,21 @@ #include #include -#include -#include -#include -#include -#include +#include +#include #include "nfc_debug_private.h" +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility("default"))) +#endif + +#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. */ + typedef enum { EMUL_NFC_TAG_DISCOVERED = 100, EMUL_NFC_TAG_DETACHED, @@ -57,7 +65,8 @@ typedef enum { EMUL_NDEF_TNF_MIME_MEDIA, EMUL_NDEF_TNF_ABSOLUTE_URI, EMUL_NDEF_TNF_EXTERNAL, - EMUL_NDEF_TNF_UNKNOWN + EMUL_NDEF_TNF_UNKNOWN, + EMUL_NDEF_TNF_UNCHANGED } emul_ndef_name_format; typedef enum { @@ -236,6 +245,371 @@ static void __nfc_emul_util_alloc_mem(void **mem, int size, char *filename, unsi LOGE("FILE: %s, LINE:%d, Allocation is failed", filename, line); } +static bool _net_nfc_util_init_data(data_s * data, uint32_t length) +{ + if (data == NULL || length == 0) + return false; + + _nfc_emul_util_alloc_mem(data->buffer, length); + if (data->buffer == NULL) + return false; + + data->length = length; + + return true; +} + +static void _net_nfc_util_clear_data(data_s * data) +{ + if (data == NULL) + return; + + if (data->buffer != NULL) { + _nfc_emul_util_free_mem(data->buffer); + data->buffer = NULL; + } + + data->length = 0; +} + +static 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); + + _nfc_emul_util_free_mem(record); + + return NET_NFC_OK; +} + +static 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); + } + + _nfc_emul_util_free_mem(msg); + + return NET_NFC_OK; +} + +static 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; + } + + _nfc_emul_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) { + _nfc_emul_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); + _nfc_emul_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); + _nfc_emul_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; +} + +static 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; +} + +static 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 != EMUL_NDEF_TNF_EMPTY && Record->TNF != EMUL_NDEF_TNF_UNKNOWN && Record->TNF != EMUL_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 != EMUL_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; +} + +static 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; +} + +static net_nfc_error_e _net_nfc_util_create_ndef_message(ndef_message_s ** ndef_message) +{ + if (ndef_message == NULL) + return NET_NFC_NULL_PARAMETER; + + _nfc_emul_util_alloc_mem(*ndef_message, sizeof(ndef_message_s)); + if (*ndef_message == NULL) + return NET_NFC_ALLOC_FAIL; + + return NET_NFC_OK; +} + +static 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 == EMUL_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 == EMUL_NDEF_TNF_UNKNOWN || record->TNF == EMUL_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 != EMUL_NDEF_TNF_UNKNOWN) && (record->TNF != EMUL_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; +} + static bool __net_nfc_is_valide_target_handle(net_nfc_target_handle_s *handle) { bool result = (current_working_handle == handle); @@ -464,7 +838,7 @@ static inline int _create_records_well_known(emulMsg_data_s *record, char *recor memcpy(payload_data.buffer + 1, record->payload.buffer, payload_data.length - 1); } - if (net_nfc_util_create_record(record->tnf, &record->typeName, &record->id, &payload_data, (ndef_record_s**)new_record) != NET_NFC_OK) { + if (_net_nfc_util_create_record(record->tnf, &record->typeName, &record->id, &payload_data, (ndef_record_s**)new_record) != NET_NFC_OK) { DEBUG_ERR_MSG("net_nfc_util_create_record is failed"); return -1; } @@ -498,7 +872,7 @@ static inline int _create_records_well_known(emulMsg_data_s *record, char *recor memcpy(payload_data.buffer + offset, record->payload.buffer, strlen(record_payload)); } - if (net_nfc_util_create_record(record->tnf, &record->typeName, &record->id, &payload_data, (ndef_record_s**)new_record) != NET_NFC_OK) { + if (_net_nfc_util_create_record(record->tnf, &record->typeName, &record->id, &payload_data, (ndef_record_s**)new_record) != NET_NFC_OK) { DEBUG_ERR_MSG("net_nfc_util_create_record is failed"); return -1; } @@ -583,7 +957,7 @@ static inline int _create_records_mime(emulMsg_data_s *record, char *record_payl } /* create record */ - int ret = net_nfc_util_create_record(record->tnf, &record->typeName, &record->id, + int ret = _net_nfc_util_create_record(record->tnf, &record->typeName, &record->id, &filePayload, (ndef_record_s **)new_record); _nfc_emul_util_free_mem(filePayload.buffer); if (ret != NET_NFC_OK) { @@ -694,7 +1068,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag switch (record.tnf) { case NET_NFC_RECORD_EMPTY: - result = net_nfc_util_create_record(NET_NFC_RECORD_EMPTY, &record.typeName, + result = _net_nfc_util_create_record(NET_NFC_RECORD_EMPTY, &record.typeName, &record.id, &record.payload, (ndef_record_s **)&new_record); if (NET_NFC_OK != result) { DEBUG_MSG("net_nfc_create_record failed[%d]", result); @@ -703,7 +1077,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag } break; case NET_NFC_RECORD_UNKNOWN: - result = net_nfc_util_create_record(NET_NFC_RECORD_UNKNOWN, &record.typeName, + result = _net_nfc_util_create_record(NET_NFC_RECORD_UNKNOWN, &record.typeName, &record.id, &record.payload, (ndef_record_s **)&new_record); if (NET_NFC_OK != result) { DEBUG_MSG("net_nfc_create_record failed[%d]", result); @@ -725,7 +1099,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag break; default: /* NET_NFC_RECORD_URI or NET_NFC_RECORD_EXTERNAL_RTD */ - result = net_nfc_util_create_record(record.tnf, &record.typeName, + result = _net_nfc_util_create_record(record.tnf, &record.typeName, &record.id, &record.payload, (ndef_record_s **)&new_record); if (NET_NFC_OK != result) { DEBUG_MSG("net_nfc_create_record failed[%d]", result); @@ -736,7 +1110,7 @@ static int _net_nfc_create_records_from_emulMsg(emulMsg_s *emul_msg, ndef_messag } /* append record to ndef msg */ - if ((result = net_nfc_util_append_record((ndef_message_s*)*ndef_message, (ndef_record_s *)new_record)) != NET_NFC_OK) { + if ((result = _net_nfc_util_append_record((ndef_message_s*)*ndef_message, (ndef_record_s *)new_record)) != NET_NFC_OK) { DEBUG_MSG("net_nfc_util_append_record failed[%d]", result); _create_records_free(&record); return create_record_count; @@ -775,24 +1149,24 @@ static bool _net_nfc_change_file_owner_permission(FILE *file) if (buffer_len == -1) buffer_len = 16384; - _net_nfc_util_alloc_mem(buffer, buffer_len); + _nfc_emul_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); + _nfc_emul_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); + _nfc_emul_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); + _nfc_emul_util_free_mem(buffer); if ((pw_inhouse != NULL) && (gr_inhouse != NULL)) { if (fchown(fileno(file), pw_inhouse->pw_uid, gr_inhouse->gr_gid) < 0) @@ -857,7 +1231,7 @@ static net_nfc_error_e _net_nfc_retrieve_ndef_message(data_s *data) DEBUG_MSG("message length = [%ld]", size); if (size > 0) { - if (net_nfc_util_init_data(data, size) == true) { + if (_net_nfc_util_init_data(data, size) == true) { int current; size_t offset = 0; @@ -910,14 +1284,14 @@ static bool _net_nfc_create_ndef_from_emulMsg(emulMsg_s *emul_msg) ndef_message_h ndef_message = NULL; int ndef_length = 0; - if ((result = net_nfc_util_create_ndef_message((ndef_message_s **)&ndef_message)) != NET_NFC_OK) + if ((result = _net_nfc_util_create_ndef_message((ndef_message_s **)&ndef_message)) != NET_NFC_OK) DEBUG_MSG("failed to create ndef message [%d]", result); /* create records and append it to ndef_msg*/ emul_msg->record_count = _net_nfc_create_records_from_emulMsg(emul_msg, (ndef_message_s **)&ndef_message, record_count); /* convert ndef msg to raw data */ - ndef_length = net_nfc_util_get_ndef_message_length((ndef_message_s *)ndef_message); + ndef_length = _net_nfc_util_get_ndef_message_length((ndef_message_s *)ndef_message); if (!ndef_length) DEBUG_MSG("ndef_message size is zero!"); @@ -925,13 +1299,13 @@ static bool _net_nfc_create_ndef_from_emulMsg(emulMsg_s *emul_msg) rawdata.length = ndef_length; _nfc_emul_util_alloc_mem(rawdata.buffer, ndef_length); - if ((result = net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s*)ndef_message, &rawdata)) != NET_NFC_OK) + if ((result = _net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s*)ndef_message, &rawdata)) != NET_NFC_OK) DEBUG_MSG("net_nfc_util_convert_ndef_message_to_rawdata is failed![%d]", result); _net_nfc_store_ndef_message(&rawdata); _nfc_emul_util_free_mem(rawdata.buffer); - net_nfc_util_free_ndef_message(ndef_message); + _net_nfc_util_free_ndef_message(ndef_message); DEBUG_EMUL_END(); @@ -2892,68 +3266,91 @@ static bool net_nfc_emul_controller_secure_element_close(net_nfc_target_handle_s DEBUG_ERR_MSG("se close end"); } -__attribute__((visibility("default"))) bool onload(net_nfc_oem_interface_s *emul_interfaces) -{ - DEBUG_EMUL_BEGIN(); - - emul_interfaces->init = net_nfc_emul_controller_init; - emul_interfaces->deinit = net_nfc_emul_controller_deinit; - emul_interfaces->register_listener = net_nfc_emul_controller_register_listener; - emul_interfaces->unregister_listener = net_nfc_emul_controller_unregister_listener; - emul_interfaces->get_firmware_version = net_nfc_emul_controller_get_firmware_version; - emul_interfaces->check_firmware_version = net_nfc_emul_controller_check_firmware_version; - emul_interfaces->update_firmeware = net_nfc_emul_controller_update_firmware; - emul_interfaces->get_stack_information = net_nfc_emul_controller_get_stack_information; - emul_interfaces->configure_discovery = net_nfc_emul_controller_configure_discovery; - emul_interfaces->get_secure_element_list = net_nfc_emul_controller_get_secure_element_list; - emul_interfaces->set_secure_element_mode = net_nfc_emul_controller_set_secure_element_mode; - emul_interfaces->connect = net_nfc_emul_controller_connect; - emul_interfaces->disconnect = net_nfc_emul_controller_disconnect; - emul_interfaces->check_ndef = net_nfc_emul_controller_check_ndef; - emul_interfaces->check_presence = net_nfc_emul_controller_check_target_presence; - emul_interfaces->read_ndef = net_nfc_emul_controller_read_ndef; - emul_interfaces->write_ndef = net_nfc_emul_controller_write_ndef; - emul_interfaces->make_read_only_ndef = net_nfc_emul_controller_make_read_only_ndef; - emul_interfaces->transceive = net_nfc_emul_controller_transceive; - emul_interfaces->format_ndef = net_nfc_emul_controller_format_ndef; - emul_interfaces->exception_handler = net_nfc_emul_controller_exception_handler; - emul_interfaces->is_ready = net_nfc_emul_controller_is_ready; - - emul_interfaces->config_llcp = net_nfc_emul_controller_llcp_config; - emul_interfaces->check_llcp_status = net_nfc_emul_controller_llcp_check_llcp; - emul_interfaces->activate_llcp = net_nfc_emul_controller_llcp_activate_llcp; - emul_interfaces->create_llcp_socket = net_nfc_emul_controller_llcp_create_socket; - emul_interfaces->bind_llcp_socket = net_nfc_emul_controller_llcp_bind; - emul_interfaces->listen_llcp_socket = net_nfc_emul_controller_llcp_listen; - emul_interfaces->accept_llcp_socket = net_nfc_emul_controller_llcp_accept; - emul_interfaces->connect_llcp_by_url = net_nfc_emul_controller_llcp_connect_by_url; - emul_interfaces->connect_llcp = net_nfc_emul_controller_llcp_connect; - emul_interfaces->disconnect_llcp = net_nfc_emul_controller_llcp_disconnect; - emul_interfaces->close_llcp_socket = net_nfc_emul_controller_llcp_socket_close; - emul_interfaces->recv_llcp = net_nfc_emul_controller_llcp_recv; - emul_interfaces->send_llcp = net_nfc_emul_controller_llcp_send; - emul_interfaces->recv_from_llcp = net_nfc_emul_controller_llcp_recv_from; - emul_interfaces->send_to_llcp = net_nfc_emul_controller_llcp_send_to; - emul_interfaces->reject_llcp = net_nfc_emul_controller_llcp_reject; - emul_interfaces->get_remote_config = net_nfc_emul_controller_llcp_get_remote_config; - emul_interfaces->get_remote_socket_info = net_nfc_emul_controller_llcp_get_remote_socket_info; - - emul_interfaces->support_nfc = net_nfc_emul_controller_support_nfc; - - emul_interfaces->secure_element_open = net_nfc_emul_controller_secure_element_open; - emul_interfaces->secure_element_get_atr = net_nfc_emul_controller_secure_element_get_atr; - emul_interfaces->secure_element_send_apdu = net_nfc_emul_controller_secure_element_send_apdu; - emul_interfaces->secure_element_close = net_nfc_emul_controller_secure_element_close; - - emul_interfaces->hce_response_apdu = NULL; - emul_interfaces->route_aid = NULL; - emul_interfaces->unroute_aid = NULL; - emul_interfaces->commit_routing = NULL; - emul_interfaces->set_default_route = NULL; - emul_interfaces->clear_aid_table = NULL; - emul_interfaces->get_aid_tablesize = NULL; +static int nfc_backend_init(void **data) +{ + hal_backend_nfc_funcs *nfc_funcs; + + nfc_funcs = calloc(1, sizeof(hal_backend_nfc_funcs)); + if (!nfc_funcs) + return -ENOMEM; + + nfc_funcs->start = net_nfc_emul_controller_init; + nfc_funcs->stop = net_nfc_emul_controller_deinit; + nfc_funcs->register_listener = net_nfc_emul_controller_register_listener; + nfc_funcs->unregister_listener = net_nfc_emul_controller_unregister_listener; + nfc_funcs->get_firmware_version = net_nfc_emul_controller_get_firmware_version; + nfc_funcs->check_firmware_version = net_nfc_emul_controller_check_firmware_version; + nfc_funcs->update_firmware = net_nfc_emul_controller_update_firmware; + nfc_funcs->get_stack_information = net_nfc_emul_controller_get_stack_information; + nfc_funcs->configure_discovery = net_nfc_emul_controller_configure_discovery; + nfc_funcs->get_secure_element_list = net_nfc_emul_controller_get_secure_element_list; + nfc_funcs->set_secure_element_mode = net_nfc_emul_controller_set_secure_element_mode; + nfc_funcs->connect = net_nfc_emul_controller_connect; + nfc_funcs->disconnect = net_nfc_emul_controller_disconnect; + nfc_funcs->check_ndef = net_nfc_emul_controller_check_ndef; + nfc_funcs->check_target_presence = net_nfc_emul_controller_check_target_presence; + nfc_funcs->read_ndef = net_nfc_emul_controller_read_ndef; + nfc_funcs->write_ndef = net_nfc_emul_controller_write_ndef; + nfc_funcs->make_read_only_ndef = net_nfc_emul_controller_make_read_only_ndef; + nfc_funcs->transceive = net_nfc_emul_controller_transceive; + nfc_funcs->format_ndef = net_nfc_emul_controller_format_ndef; + nfc_funcs->exception_handler = net_nfc_emul_controller_exception_handler; + nfc_funcs->is_ready = net_nfc_emul_controller_is_ready; + + nfc_funcs->llcp_config = net_nfc_emul_controller_llcp_config; + nfc_funcs->llcp_check_llcp = net_nfc_emul_controller_llcp_check_llcp; + nfc_funcs->llcp_activate_llcp = net_nfc_emul_controller_llcp_activate_llcp; + nfc_funcs->llcp_create_socket = net_nfc_emul_controller_llcp_create_socket; + nfc_funcs->llcp_bind = net_nfc_emul_controller_llcp_bind; + nfc_funcs->llcp_listen = net_nfc_emul_controller_llcp_listen; + nfc_funcs->llcp_accept = net_nfc_emul_controller_llcp_accept; + nfc_funcs->llcp_connect_by_url = net_nfc_emul_controller_llcp_connect_by_url; + nfc_funcs->llcp_connect = net_nfc_emul_controller_llcp_connect; + nfc_funcs->llcp_disconnect = net_nfc_emul_controller_llcp_disconnect; + nfc_funcs->llcp_socket_close = net_nfc_emul_controller_llcp_socket_close; + nfc_funcs->llcp_recv = net_nfc_emul_controller_llcp_recv; + nfc_funcs->llcp_send = net_nfc_emul_controller_llcp_send; + nfc_funcs->llcp_recv_from = net_nfc_emul_controller_llcp_recv_from; + nfc_funcs->llcp_send_to = net_nfc_emul_controller_llcp_send_to; + nfc_funcs->llcp_reject = net_nfc_emul_controller_llcp_reject; + nfc_funcs->llcp_get_remote_config = net_nfc_emul_controller_llcp_get_remote_config; + nfc_funcs->llcp_get_remote_socket_info = net_nfc_emul_controller_llcp_get_remote_socket_info; + + nfc_funcs->support_nfc = net_nfc_emul_controller_support_nfc; + + nfc_funcs->secure_element_open = net_nfc_emul_controller_secure_element_open; + nfc_funcs->secure_element_get_atr = net_nfc_emul_controller_secure_element_get_atr; + nfc_funcs->secure_element_send_apdu = net_nfc_emul_controller_secure_element_send_apdu; + nfc_funcs->secure_element_close = net_nfc_emul_controller_secure_element_close; + + nfc_funcs->hce_response_apdu = NULL; + nfc_funcs->secure_element_route_aid = NULL; + nfc_funcs->secure_element_unroute_aid = NULL; + nfc_funcs->secure_element_commit_routing = NULL; + nfc_funcs->secure_element_set_default_route = NULL; + nfc_funcs->secure_element_clear_aid_table = NULL; + nfc_funcs->secure_element_get_aid_table_size = NULL; DEBUG_EMUL_END(); - return true; + *data = (void *)nfc_funcs; + + return 0; } + +static int nfc_backend_exit(void *data) +{ + if (!data) + return -EINVAL; + free(data); + + return 0; +} + +EXPORT hal_backend hal_backend_nfc_data = { + .name = "nfc-backend", + .vendor = "Emulator", + .abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .init = nfc_backend_init, + .exit = nfc_backend_exit, +}; -- 2.7.4 From d82f57eca2f24bf0cb88571e9c51b635db22215f Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Wed, 14 Apr 2021 14:04:07 +0900 Subject: [PATCH 16/16] [TSYSTEM-1043] Change install path to hal folder Change-Id: I48b4aab302dfb2544a4480c0865123f4e1eac4cd Signed-off-by: Jihoon Jung --- CMakeLists.txt | 3 ++- packaging/nfc-plugin-emul.spec | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 871cbea..2fb5fdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,4 +15,5 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_COMPILE_OPTIONS(${PROJECT_NAME} PUBLIC ${pkgs_CFLAGS_OTHER}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LIBRARIES} pthread) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_PATH}) -INSTALL(FILES 98-nfc-plugin-emul.rules DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/udev/rules.d/) +INSTALL(FILES 98-nfc-plugin-emul.rules DESTINATION ${HAL_PATH}/udev/rules.d/) +INSTALL(FILES LICENSE.APLv2 DESTINATION ${HAL_LICENSE_PATH}) diff --git a/packaging/nfc-plugin-emul.spec b/packaging/nfc-plugin-emul.spec index f0ca530..e60ef17 100644 --- a/packaging/nfc-plugin-emul.spec +++ b/packaging/nfc-plugin-emul.spec @@ -21,7 +21,8 @@ cp %{SOURCE1001} ./%{name}.manifest %build %cmake . -DCMAKE_VERBOSE_MAKEFILE=OFF \ - -DHAL_PATH=%{_hal_libdir} + -DHAL_PATH=%{_hal_libdir} \ + -DHAL_LICENSE_PATH=%{_hal_licensedir} make %{?_smp_mflags} %install @@ -30,5 +31,5 @@ make %{?_smp_mflags} %files %manifest %{name}.manifest %{_hal_libdir}/*.so* -%{_prefix}/lib/udev/rules.d/98-%{name}.rules -%license LICENSE.APLv2 +%{_hal_libdir}/udev/rules.d/98-%{name}.rules +%license %{_hal_licensedir}/LICENSE.APLv2 -- 2.7.4