} 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,
NET_NFC_STATE_UNKNOWN
} llcp_state_e;
-typedef enum{
+typedef enum {
SNEP_REQ_CONTINUE = 0x00,
SNEP_REQ_GET = 0x01,
SNEP_REQ_PUT = 0x02,
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;
} net_nfc_oem_llcp_state_t;
-typedef struct _snep_msg_s{
+typedef struct _snep_msg_s {
data_s *data;
int offset;
bool isSegment;
/* 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);
/****************************** 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;
/*************************** 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,
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);
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,
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);
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]);
}
}
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");
////////////// 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();
{
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);
{
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;
}
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;
}
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);
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;
/* 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);
}
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");
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");
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");
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;
}
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;
}
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? */
_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) {
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");
}
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");
}
/* 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)
/* 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)
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;
FILE *fp = NULL;
if (data == NULL)
- {
return;
- }
/* create file */
snprintf(file_name, sizeof(file_name), "%s/%s/%s", "/opt/usr/share/nfc-manager-daemon",
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);
}
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 */
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;
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;
}
{
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;
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);
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);
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;
}
}
{
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);
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);
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;
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;
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);
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);
}
_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;
_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 */
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);
_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;
}
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);
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;
}
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 */
}
/* 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;
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;
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;
}
close(emulMsg_file_fd);
+ if (emulMsg_poll_events != NULL)
+ free(emulMsg_poll_events);
+
DEBUG_MSG("emul_ReaderThread END >>>>");
}
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);
/* 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;
/* 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));
}
#endif
-static bool _net_nfc_emul_controller_start_thread (void)
+static bool _net_nfc_emul_controller_start_thread(void)
{
bool ret = true;
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();
return true;
}
-static void _net_nfc_emul_controller_stop_thread (void)
+static void _net_nfc_emul_controller_stop_thread(void)
{
DEBUG_EMUL_BEGIN();
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;
}
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;
}
hce_apdu_listener_cb hce_apdu_listener,
net_nfc_error_e* result)
{
- if (result == NULL) {
+ if (result == NULL)
return false;
- }
*result = NET_NFC_OK;
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;
*data = (data_s *)calloc(1, sizeof(data_s));
- if(*data == NULL)
+ if (*data == NULL)
return false;
(*data)->length = 10;
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;
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;
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;
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");
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;
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;
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;
if (_net_nfc_emul_get_is_tag_attached()) {
return true;
- }
- else {
+ } else {
DEBUG_MSG("TAG Detached");
return false;
}
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;
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;
}
// 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();
{
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;
}
_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");
}
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;
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;
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);
*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;
(*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);
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;
{
bool ret = false;
- if (result == NULL) {
+ if (result == NULL)
return ret;
- }
if (info == NULL || info->trans_data.buffer == NULL ||
info->trans_data.length == 0) {
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;
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);
}
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;
* 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;
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;
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;
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;
/* 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;
}
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;
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;
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;
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;
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);
}
/* 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;
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;
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;
}
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;
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;
}
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;
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;
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;
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;
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;
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;
}
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");
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;
}
_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..");
}
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;
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;
}
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");
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;
}
_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..");
}
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;
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;
}
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;
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;
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;
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;
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;
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;
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;
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;
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;