From eb6ec3a5ba60cb7aaefec374c3cb19f73cbffb6d Mon Sep 17 00:00:00 2001 From: Munkyu Im Date: Wed, 27 Aug 2014 16:05:24 +0900 Subject: [PATCH] nfc: Add getting status Client can get nfc status from nfc device. Change-Id: I7cbc237ed221dd8f62e28f52a98e86f5518d92bd Signed-off-by: Munkyu Im --- tizen/src/ecs/ecs_msg.c | 7 +- tizen/src/hw/maru_virtio_nfc.c | 41 +++++++++- tizen/src/hw/maru_virtio_nfc.h | 145 +++++++++++++++++---------------- 3 files changed, 116 insertions(+), 77 deletions(-) diff --git a/tizen/src/ecs/ecs_msg.c b/tizen/src/ecs/ecs_msg.c index 9503a3d483..5bec9ce809 100644 --- a/tizen/src/ecs/ecs_msg.c +++ b/tizen/src/ecs/ecs_msg.c @@ -287,7 +287,7 @@ bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg) } //TRACE(">> count= %d", ++ijcount); - TRACE(">> header = cmd = %s, length = %d, action=%d, group=%d, data= %s\n", cmd, length, + TRACE(">> injector_req: header = cmd = %s, length = %d, action=%d, group=%d, data= %s\n", cmd, length, action, group, msg->data.data); /*SD CARD msg process*/ @@ -478,7 +478,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg) memcpy(data, msg->data.data, msg->data.len); } - TRACE(">> header = cmd = %s, length = %d, action=%d, group=%d\n", cmd, length, + TRACE(">> device_req: header = cmd = %s, length = %d, action=%d, group=%d\n", cmd, length, action, group); if (!strcmp(cmd, MSG_TYPE_SENSOR)) { @@ -610,8 +610,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg) msgproc_device_ans(ccli, cmd, true, vmname); } else if (!strcmp(cmd, "nfc")) { if (group == MSG_GROUP_STATUS) { - //TODO: - INFO("get nfc data: do nothing\n"); + get_nfc_data(); } else { if (data != NULL) { send_to_nfc(ccli->client_id, ccli->client_type, data, msg->data.len); diff --git a/tizen/src/hw/maru_virtio_nfc.c b/tizen/src/hw/maru_virtio_nfc.c index 83fdae3b52..18cae64945 100644 --- a/tizen/src/hw/maru_virtio_nfc.c +++ b/tizen/src/hw/maru_virtio_nfc.c @@ -63,8 +63,47 @@ typedef struct NFCBuf { QTAILQ_ENTRY(NFCBuf) next; } NFCBuf; + +static char nfc_data [NFC_MAX_BUF_SIZE] = {'0',}; + static pthread_mutex_t recv_buf_mutex = PTHREAD_MUTEX_INITIALIZER; +static void send_nfc_data_to_ecs(const char* data) +{ + type_length length = 0; + type_group group = 15; + type_action action = 0; + int buf_len = strlen(data); + int message_len = buf_len + 14; + + char* ecs_message = (char*) malloc(message_len + 1); + if (!ecs_message) + return; + + memset(ecs_message, 0, message_len + 1); + + length = (unsigned short) buf_len; + action = 0; + + memcpy(ecs_message, MESSAGE_TYPE_NFC, 3); + memcpy(ecs_message + 10, &length, sizeof(unsigned short)); + memcpy(ecs_message + 12, &group, sizeof(unsigned char)); + memcpy(ecs_message + 13, &action, sizeof(unsigned char)); + memcpy(ecs_message + 14, data, buf_len); + + TRACE("ntf_to_injector- len: %d, group: %d, action: %d, data: %s\n", length, group, action, data); + + send_device_ntf(ecs_message, message_len); + + if (ecs_message) + free(ecs_message); +} + +void get_nfc_data(void) +{ + send_nfc_data_to_ecs(nfc_data); +} + bool send_to_nfc(unsigned char id, unsigned char type, const char* data, const uint32_t len) { if(vio_nfc == NULL) { @@ -96,7 +135,7 @@ bool send_to_nfc(unsigned char id, unsigned char type, const char* data, const u _msg->info.client_type = type; pthread_mutex_lock(&recv_buf_mutex); - + strcpy(nfc_data, data); QTAILQ_INSERT_TAIL(&nfc_recv_msg_queue, _msg, next); pthread_mutex_unlock(&recv_buf_mutex); diff --git a/tizen/src/hw/maru_virtio_nfc.h b/tizen/src/hw/maru_virtio_nfc.h index 17c539aba8..5a991b6be8 100644 --- a/tizen/src/hw/maru_virtio_nfc.h +++ b/tizen/src/hw/maru_virtio_nfc.h @@ -1,72 +1,73 @@ -/* - * Virtio NFC Device - * - * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: - * Munkyu Im - * YeongKyoon Lee - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Contributors: - * - S-Core Co., Ltd - * - */ - -#ifndef MARU_VIRTIO_NFC_H_ -#define MARU_VIRTIO_NFC_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "hw/virtio/virtio.h" - -enum request_cmd_nfc { - request_nfc_get = 0, - request_nfc_set, - request_nfc_answer -}; - - -/* device protocol */ - -#define __MAX_BUF_SIZE 1024 - - -typedef struct VirtIONFC{ - VirtIODevice vdev; - VirtQueue *rvq; - VirtQueue *svq; - DeviceState *qdev; - - QEMUBH *bh; -} VirtIONFC; - - -#define TYPE_VIRTIO_NFC "virtio-nfc-device" -#define VIRTIO_NFC(obj) \ - OBJECT_CHECK(VirtIONFC, (obj), TYPE_VIRTIO_NFC) - - -bool send_to_nfc(unsigned char id, unsigned char type, const char* data, const uint32_t len); - -#ifdef __cplusplus -} -#endif - - -#endif /* MARU_VIRTIO_NFC_H_ */ +/* + * Virtio NFC Device + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: + * Munkyu Im + * YeongKyoon Lee + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef MARU_VIRTIO_NFC_H_ +#define MARU_VIRTIO_NFC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "hw/virtio/virtio.h" + +enum request_cmd_nfc { + request_nfc_get = 0, + request_nfc_set, + request_nfc_answer +}; + + +/* device protocol */ + +#define __MAX_BUF_SIZE 1024 +#define MESSAGE_TYPE_NFC "nfc" + +typedef struct VirtIONFC{ + VirtIODevice vdev; + VirtQueue *rvq; + VirtQueue *svq; + DeviceState *qdev; + + QEMUBH *bh; +} VirtIONFC; + + +#define TYPE_VIRTIO_NFC "virtio-nfc-device" +#define VIRTIO_NFC(obj) \ + OBJECT_CHECK(VirtIONFC, (obj), TYPE_VIRTIO_NFC) + + +bool send_to_nfc(unsigned char id, unsigned char type, const char* data, const uint32_t len); +void get_nfc_data(void); + +#ifdef __cplusplus +} +#endif + + +#endif /* MARU_VIRTIO_NFC_H_ */ -- 2.34.1