/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define _GNU_SOURCE
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#define NET_NFC_EMUL_MSG_ID_SEPERATOR "\n:"
#define NET_NFC_EMUL_MSG_DATA_SEPERATOR "\n\0"
#define NET_NFC_EMUL_MSG_RECORD_SEPERATOR "\n,"
-#define NET_NFC_EMUL_TAG_DISCOVERED_DATA_FORMAT "%d,%d,%[^\n]"
#ifdef __USE_EPOLL_FOR_FILE__
#define EPOLL_SIZE 128
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].socket_handle == socket)
{
socket_info_array [idx].isValid = false;
socket_info_array [idx].socket_handle = 0;
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;
-
}
DEBUG_MSG("retval [%d]", retval);
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;
}
}
+static inline void _set_emulMsg_p2p_send(char *emulMsgData)
+{
+ /* get message : Tag Type, Record Count, Records */
+ int target_type = -1;
+ char file_data[BUFFER_LENGTH_MAX]={0};
+ char *buf = NULL;
+ int length =0;
+
+ sscanf(emulMsgData, "%d,%d,%a[^\n]", &target_type, &gSdkMsg.record_count,
+ &buf);
+
+ gSdkMsg.target_type = (emul_target_type) target_type;
+
+ if (buf)
+ {
+ snprintf(file_data, sizeof(file_data), "%s", buf);
+ free(buf);
+ }
+
+ length = strlen(file_data)+1;
+ _nfc_emul_util_alloc_mem(gSdkMsg.file_data, length);
+ memcpy(gSdkMsg.file_data, file_data, length);
+
+ DEBUG_ERR_MSG("EMUL MESSAGE DATA START >>>>>>>>>>>>>>>>>>>>>>>>");
+ DEBUG_MSG("message_id >>>>[%d]", gSdkMsg.message_id);
+ DEBUG_MSG("target_type >>>>[%d]", gSdkMsg.target_type);
+ DEBUG_MSG("record_count >>>>[%d]", gSdkMsg.record_count);
+ DEBUG_MSG("file_data >>>>[%s]", (char *)gSdkMsg.file_data);
+ DEBUG_ERR_MSG("EMUL MESSAGE DATA END >>>>>>>>>>>>>>>>>>>>>>>>");
+}
+
static bool _net_nfc_set_emulMsg(uint8_t * emulData, long int messageSize)
{
DEBUG_EMUL_BEGIN();
DEBUG_MSG("emulMsgData >>>>[%s]", emulMsgData);
switch (gSdkMsg.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, &gSdkMsg.record_count, file_data);
-
- gSdkMsg.target_type = (emul_target_type) target_type;
-
- length = strlen(file_data)+1;
- _nfc_emul_util_alloc_mem(gSdkMsg.file_data, length);
- memcpy(gSdkMsg.file_data, file_data, length);
-
- DEBUG_ERR_MSG("EMUL MESSAGE DATA START >>>>>>>>>>>>>>>>>>>>>>>>");
- DEBUG_MSG("message_id >>>>[%d]", gSdkMsg.message_id);
- DEBUG_MSG("target_type >>>>[%d]", gSdkMsg.target_type);
- DEBUG_MSG("record_count >>>>[%d]", gSdkMsg.record_count);
- DEBUG_MSG("file_data >>>>[%s]", (char *)gSdkMsg.file_data);
- DEBUG_ERR_MSG("EMUL MESSAGE DATA END >>>>>>>>>>>>>>>>>>>>>>>>");
- }
+ case EMUL_NFC_TAG_DISCOVERED :
+ case EMUL_NFC_P2P_SEND :
+ _set_emulMsg_p2p_send(emulMsgData);
break;
-
- default : {
- /* exception case */
- DEBUG_ERR_MSG("_net_nfc_set_emulMsg error. Data is currupted");
- return false;
- }
- break;
-
+ default :
+ /* exception case */
+ DEBUG_ERR_MSG("_net_nfc_set_emulMsg error. Data is currupted");
+ return false;
}
}
- else {
+ else
+ {
switch (gSdkMsg.message_id) {
- case EMUL_NFC_P2P_DISCOVERED :{
- gSdkMsg.target_type = EMUL_NFC_TARGET;
- }
- break;
-
- case EMUL_NFC_TAG_DETACHED :
- case EMUL_NFC_P2P_DETACHED :
- DEBUG_MSG("TAG or TARGET DETACHED");
+ case EMUL_NFC_P2P_DISCOVERED :
+ gSdkMsg.target_type = EMUL_NFC_TARGET;
break;
-
- default : {
- /* exception case */
- DEBUG_ERR_MSG("_net_nfc_set_emulMsg error. Data is currupted");
- return false;
- }
+ case EMUL_NFC_TAG_DETACHED :
+ case EMUL_NFC_P2P_DETACHED :
+ DEBUG_MSG("TAG or TARGET DETACHED");
break;
+ default :
+ /* exception case */
+ DEBUG_ERR_MSG("_net_nfc_set_emulMsg error. Data is currupted");
+ return false;
}
}
DEBUG_EMUL_END();
-
return true;
}
}
/* assign data to record structure */
- record.tnf = _net_nfc_get_tnf_type(atoi(name_format));
+ if (name_format)
+ record.tnf = _net_nfc_get_tnf_type(atoi(name_format));
- if (strcmp(type_name, "Null")) {
+ if (type_name && strcmp(type_name, "Null")) {
DEBUG_MSG("Data : type_name ");
record.typeName.length = strlen(type_name);
memcpy(record.typeName.buffer, type_name, record.typeName.length);
}
- if (strcmp(record_id, "Null")) {
+ if (record_id && strcmp(record_id, "Null")) {
DEBUG_MSG("Data : record_id ");
record.id.length = strlen(record_id);
memcpy(record.id.buffer, record_id, record.id.length);
}
- if (strcmp(record_payload, "Null")) {
+ if (record_payload && strcmp(record_payload, "Null")) {
DEBUG_MSG("Data : record_payload ");
record.payload.length = strlen(record_payload);
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;
}
/* 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, \
- 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 };
+ 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 };
length = sizeof(net_nfc_request_target_detected_t) + sizeof(device_info);
{
return NULL;
}
- /* version response length payload*/
+ /* version response length payload*/
snep_msg->length = sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t) + information->length;
if((snep_msg->buffer = (uint8_t *)calloc(snep_msg->length, sizeof(uint8_t))) == NULL)
DEBUG_EMUL_BEGIN();
switch (gSdkMsg.message_id) {
- case EMUL_NFC_TAG_DISCOVERED :{
- /* create ndef */
- if ( !_net_nfc_create_ndef_from_emulMsg()) {
- DEBUG_ERR_MSG("create ndef_msg is failed >>>");
- return false;
- }
-
- _net_nfc_target_discovered_cb();
+ case EMUL_NFC_TAG_DISCOVERED :
+ /* create ndef */
+ if ( !_net_nfc_create_ndef_from_emulMsg()) {
+ DEBUG_ERR_MSG("create ndef_msg is failed >>>");
+ return false;
}
+
+ _net_nfc_target_discovered_cb();
+
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_target_discovered_cb();
- }
+ case EMUL_NFC_P2P_DISCOVERED :
+ _net_nfc_target_discovered_cb();
+
break;
- case EMUL_NFC_P2P_SEND : {
- if(_net_nfc_make_llcp_data()) {
+ case EMUL_NFC_P2P_SEND :
+ if(_net_nfc_make_llcp_data()) {
- /* find snep server*/
- socket_info_s *socket_info = _net_nfc_find_server_socket((net_nfc_llcp_socket_t)NET_NFC_EMUL_SNEP_SERVER_SOCKET_NUMBER);
- if (socket_info == NULL) {
- DEBUG_ERR_MSG ("socket_info is NULL");
- return false;
- }
+ /* find snep server*/
+ socket_info_s *socket_info = _net_nfc_find_server_socket((net_nfc_llcp_socket_t)NET_NFC_EMUL_SNEP_SERVER_SOCKET_NUMBER);
+ if (socket_info == 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");
- 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");
+ return false;
+ }
- if (llcp_state == NET_NFC_STATE_EXCHANGER_SERVER) {
- _net_nfc_llcp_data_receive_cb(socket_info->user_context); /* call callback */
- }
- else {
- DEBUG_ERR_MSG("getting snep server handle is failed.");
- return false;
- }
+ if (llcp_state == NET_NFC_STATE_EXCHANGER_SERVER) {
+ _net_nfc_llcp_data_receive_cb(socket_info->user_context); /* call callback */
}
else {
- DEBUG_ERR_MSG("make_p2p_data is fail!!");
+ DEBUG_ERR_MSG("getting snep server handle is failed.");
return false;
}
}
+ else {
+ DEBUG_ERR_MSG("make_p2p_data is fail!!");
+ return false;
+ }
+
break;
- case EMUL_NFC_P2P_DETACHED : {
- _net_nfc_target_detached_cb();
- }
+ case EMUL_NFC_P2P_DETACHED :
+ _net_nfc_target_detached_cb();
+
break;
- default :
- DEBUG_ERR_MSG("message_id is wrong!!");
+ default :
+ DEBUG_ERR_MSG("message_id is wrong!!");
break;
}
FILE *fp = NULL;
char file_name[1024] = { 0, };
-
- char readBuffer[READ_BUFFER_LENGTH_MAX];
-
+ char *buf=NULL;
struct stat st;
-
time_t curTime;
-
bool condition = true;
/* make file name */
}
/* read data */
- memset(readBuffer, 0x00, READ_BUFFER_LENGTH_MAX);
+ buf = NULL;
+ if (fscanf(fp, "%a[^\n]", &buf))
+ {
+ if (buf)
+ {
+ DEBUG_MSG("get DATA >>>> buf [%s]", buf);
- if (fscanf(fp, "%[^\n]", readBuffer)) {
- DEBUG_MSG("get DATA >>>> readBuffer [%s]", readBuffer);
+ /* process message */
+ _net_nfc_process_emulMsg((uint8_t *) buf, (long int) strlen(buf));
+ free(buf);
+ }
}
- /* process message */
- _net_nfc_process_emulMsg((uint8_t *) readBuffer, (long int) strlen(readBuffer));
-
fclose(fp);
}
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)
+ net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result)
{
bool ret = false;
}
if (info == NULL || info->trans_data.buffer == NULL ||
- info->trans_data.length == 0) {
+ info->trans_data.length == 0) {
*result = NET_NFC_INVALID_PARAM;
return ret;
}
/* check ISO-DEP formatable in DesFire */
if (info->trans_data.buffer[0] == (uint8_t)0x90 &&
- info->trans_data.buffer[1] == (uint8_t)0x60) {
+ info->trans_data.buffer[1] == (uint8_t)0x60) {
data_s *temp;
/*******************
-* LLCP definition *
-********************/
+ * LLCP definition *
+ ********************/
static bool net_nfc_emul_controller_llcp_config (net_nfc_llcp_config_info_s * config, net_nfc_error_e * result)
{