nfc: Add getting status 40/26640/2
authorMunkyu Im <munkyu.im@samsung.com>
Wed, 27 Aug 2014 07:28:51 +0000 (16:28 +0900)
committerMunkyu Im <munkyu.im@samsung.com>
Thu, 28 Aug 2014 08:36:39 +0000 (17:36 +0900)
Client can get nfc status from nfc device.

Change-Id: I1a10cfccebe6031aa6b70da3ad93dd834803029a
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
tizen/src/ecs/ecs_msg.c
tizen/src/hw/virtio/maru_virtio_nfc.c
tizen/src/hw/virtio/maru_virtio_nfc.h

index 2e84435825ee24d58249ddbb369c409a38c3b1bf..d7a8b34f3f38cb5425c537cdcff058f02dc8eadb 100644 (file)
@@ -615,8 +615,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);
index ce632e63d339809611553e30e7314212913e5111..df589f0614651707de0847bf0d065e417355bf66 100644 (file)
@@ -63,8 +63,46 @@ 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 +134,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);
index 17c539aba8f87dcbdbf2676f129757337a69bb74..5a991b6be888642cb0a39e6fccbf59a6da3a0c43 100644 (file)
@@ -1,72 +1,73 @@
-/*\r
- * Virtio NFC Device\r
- *\r
- * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
- *\r
- * Contact:\r
- *  Munkyu Im <munkyu.im@samsung.com>\r
- *  YeongKyoon Lee <yeongkyoon.lee@samsung.com>\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-\r
-#ifndef MARU_VIRTIO_NFC_H_\r
-#define MARU_VIRTIO_NFC_H_\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-#include "hw/virtio/virtio.h"\r
-\r
-enum request_cmd_nfc {\r
-       request_nfc_get = 0,\r
-       request_nfc_set,\r
-       request_nfc_answer\r
-};\r
-\r
-\r
-/* device protocol */\r
-\r
-#define __MAX_BUF_SIZE 1024\r
-\r
-\r
-typedef struct VirtIONFC{\r
-    VirtIODevice    vdev;\r
-    VirtQueue       *rvq;\r
-    VirtQueue          *svq;\r
-    DeviceState     *qdev;\r
-\r
-    QEMUBH *bh;\r
-} VirtIONFC;\r
-\r
-\r
-#define TYPE_VIRTIO_NFC "virtio-nfc-device"\r
-#define VIRTIO_NFC(obj) \\r
-        OBJECT_CHECK(VirtIONFC, (obj), TYPE_VIRTIO_NFC)\r
-\r
-\r
-bool send_to_nfc(unsigned char id, unsigned char type, const char* data, const uint32_t len);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-\r
-#endif /* MARU_VIRTIO_NFC_H_ */\r
+/*
+ * Virtio NFC Device
+ *
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ *  Munkyu Im <munkyu.im@samsung.com>
+ *  YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * 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_ */