qemu: fixed bug(message format) and added boilerplate 22/10722/1
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Wed, 25 Sep 2013 11:45:25 +0000 (20:45 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Thu, 10 Oct 2013 07:23:53 +0000 (16:23 +0900)
Change-Id: I018b69a1f647fbcab03410beb0abd21b4b7419e5
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
tizen/src/ecs/ecs.c
tizen/src/ecs/ecs.h
tizen/src/ecs/ecs_msg.c
tizen/src/ecs/ecs_sensor.c
tizen/src/hw/maru_virtio_nfc.c
tizen/src/hw/maru_virtio_sensor.c

index 1e17d91..b5c2c8f 100644 (file)
@@ -1,3 +1,33 @@
+/*
+ * Emulator Control Server
+ *
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ *  Jinhyung choi   <jinhyung2.choi@samsung.com>
+ *  MunKyu Im       <munkyu.im@samsung.com>
+ *  Daiyoung Kim    <daiyoung777.kim@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
+ *
+ */
+
 #include <stdbool.h>
 #include <pthread.h>
 #include <stdlib.h>
@@ -881,7 +911,6 @@ static Monitor *monitor_create(void) {
         LOG("monitor allocation failed.");
         return NULL;
     }
-    memset(mon, 0, sizeof(*mon));
 
     return mon;
 }
index 9283747..efab4db 100644 (file)
@@ -1,3 +1,33 @@
+/*
+ * Emulator Control Server
+ *
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ *  Jinhyung choi   <jinhyung2.choi@samsung.com>
+ *  MunKyu Im       <munkyu.im@samsung.com>
+ *  Daiyoung Kim    <daiyoung777.kim@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 __ECS_H__
 #define __ECS_H__
 
index 864c1a6..68b2e46 100644 (file)
@@ -1,3 +1,32 @@
+/* Emulator Control Server
+ *
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ *  Jinhyung choi   <jinhyung2.choi@samsung.com>
+ *  MunKyu Im       <munkyu.im@samsung.com>
+ *  Daiyoung Kim    <daiyoung777.kim@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
+ *
+ */
+
 #include <stdbool.h>
 #include <pthread.h>
 
@@ -426,6 +455,8 @@ bool send_device_ntf(const char* data, const int len)
         ntf.data.data = g_malloc(length);
         ntf.data.len = length;
         memcpy(ntf.data.data, ijdata, length);
+
+        LOG("data = %s, length = %hu", ijdata, length);
     }
 
     master.type = ECS__MASTER__TYPE__DEVICE_NTF;
index 666eff7..ccb04c3 100644 (file)
@@ -1,10 +1,11 @@
 /*
  * Emulator Control Server - Sensor Device Handler
  *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Contact:
  *  Jinhyung choi   <jinhyung2.choi@samsung.com>
+ *  MunKyu Im       <munkyu.im@samsung.com>
  *  Daiyoung Kim    <daiyoung777.kim@samsung.com>
  *  YeongKyoon Lee  <yeongkyoon.lee@samsung.com>
  *
index 7a38d8c..d40ac50 100755 (executable)
-/*\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
-#include <pthread.h>\r
-\r
-#include "maru_device_ids.h"\r
-#include "maru_virtio_nfc.h"\r
-#include "debug_ch.h"\r
-#include "../ecs/ecs.h"\r
-\r
-MULTI_DEBUG_CHANNEL(qemu, virtio-nfc);\r
-\r
-#define NFC_DEVICE_NAME "virtio-nfc"\r
-\r
-\r
-enum {\r
-       IOTYPE_INPUT = 0,\r
-       IOTYPE_OUTPUT = 1\r
-};\r
-\r
-\r
-#ifndef min\r
-#define min(a,b) ((a)<(b)?(a):(b))\r
-#endif\r
-\r
-#define MAX_BUF_SIZE    4096\r
-\r
-\r
-VirtIONFC* vio_nfc;\r
-\r
-\r
-typedef unsigned int CSCliSN;\r
-\r
-typedef struct msg_info {\r
-       char buf[MAX_BUF_SIZE];\r
-\r
-       uint32_t route;\r
-       uint32_t use;\r
-       uint16_t count;\r
-       uint16_t index;\r
-\r
-       CSCliSN cclisn;\r
-}msg_info;\r
-\r
-//\r
-\r
-typedef struct MsgInfo\r
-{\r
-       msg_info info;\r
-       QTAILQ_ENTRY(MsgInfo) next;\r
-}MsgInfo;\r
-\r
-static QTAILQ_HEAD(MsgInfoRecvHead , MsgInfo) nfc_recv_msg_queue =\r
-    QTAILQ_HEAD_INITIALIZER(nfc_recv_msg_queue);\r
-\r
-\r
-static QTAILQ_HEAD(MsgInfoSendHead , MsgInfo) nfc_send_msg_queue =\r
-    QTAILQ_HEAD_INITIALIZER(nfc_send_msg_queue);\r
-\r
-\r
-//\r
-\r
-typedef struct NFCBuf {\r
-    VirtQueueElement elem;\r
-\r
-    QTAILQ_ENTRY(NFCBuf) next;\r
-} NFCBuf;\r
-\r
-static QTAILQ_HEAD(NFCMsgHead , NFCBuf) nfc_in_queue =\r
-    QTAILQ_HEAD_INITIALIZER(nfc_in_queue);\r
-\r
-static int count = 0;\r
-\r
-static pthread_mutex_t recv_buf_mutex = PTHREAD_MUTEX_INITIALIZER;\r
-\r
-bool send_to_nfc(enum request_cmd_nfc req, const char* data, const uint32_t len)\r
-{\r
-    MsgInfo* _msg = (MsgInfo*) malloc(sizeof(MsgInfo));\r
-    if (!_msg)\r
-        return false;\r
-\r
-    memset(&_msg->info, 0, sizeof(msg_info));\r
-\r
-    memcpy(_msg->info.buf, data, len);\r
-    _msg->info.use = len;\r
-    _msg->info.index = count++;\r
-    _msg->info.route = req;\r
-    pthread_mutex_lock(&recv_buf_mutex);\r
-\r
-    QTAILQ_INSERT_TAIL(&nfc_recv_msg_queue, _msg, next);\r
-\r
-    pthread_mutex_unlock(&recv_buf_mutex);\r
-\r
-       qemu_bh_schedule(vio_nfc->bh);\r
-\r
-       return true;\r
-}\r
-\r
-\r
-static int g_cnt = 0;\r
-\r
-static void flush_nfc_recv_queue(void)\r
-{\r
-       int index;\r
-\r
-    if (unlikely(!virtio_queue_ready(vio_nfc->rvq))) {\r
-        INFO("virtio queue is not ready\n");\r
-        return;\r
-    }\r
-\r
-       if (unlikely(virtio_queue_empty(vio_nfc->rvq))) {\r
-               TRACE("virtqueue is empty\n");\r
-               return;\r
-       }\r
-\r
-\r
-       pthread_mutex_lock(&recv_buf_mutex);\r
-\r
-       while (!QTAILQ_EMPTY(&nfc_recv_msg_queue))\r
-       {\r
-                MsgInfo* msginfo = QTAILQ_FIRST(&nfc_recv_msg_queue);\r
-                if (!msginfo)\r
-                        break;\r
-\r
-                VirtQueueElement elem;\r
-                index = virtqueue_pop(vio_nfc->rvq, &elem);\r
-                if (index == 0)\r
-                {\r
-                        //ERR("unexpected empty queue");\r
-                        break;\r
-                }\r
-\r
-                INFO(">> virtqueue_pop. index: %d, out_num : %d, in_num : %d\n", index, elem.out_num, elem.in_num);\r
-\r
-                memcpy(elem.in_sg[0].iov_base, &msginfo->info, sizeof(struct msg_info));\r
-\r
-                INFO(">> send to guest count = %d, use = %d, msg = %s, iov_len = %d \n",\r
-                                ++g_cnt, msginfo->info.use, msginfo->info.buf, elem.in_sg[0].iov_len);\r
-\r
-                virtqueue_push(vio_nfc->rvq, &elem, sizeof(msg_info));\r
-                virtio_notify(&vio_nfc->vdev, vio_nfc->rvq);\r
-\r
-                QTAILQ_REMOVE(&nfc_recv_msg_queue, msginfo, next);\r
-                if (msginfo)\r
-                        free(msginfo);\r
-       }\r
-\r
-       pthread_mutex_unlock(&recv_buf_mutex);\r
-\r
-}\r
-\r
-\r
-static void virtio_nfc_recv(VirtIODevice *vdev, VirtQueue *vq)\r
-{\r
-       flush_nfc_recv_queue();\r
-}\r
-\r
-static void send_to_ecs(struct msg_info* msg)\r
-{\r
-       int buf_len;\r
-       char data_len [2];\r
-       char group [1] = { 15 }; \r
-       char action [1];\r
-       int message_len = 0;\r
-\r
-       char* ecs_message = NULL;\r
-       \r
-       buf_len = strlen(msg->buf);\r
-       message_len =  buf_len + 14;\r
-\r
-       ecs_message = (char*) malloc(message_len + 1);\r
-       if (!ecs_message)\r
-               return;\r
-\r
-       memset(ecs_message, 0, message_len + 1);\r
-\r
-       data_len[0] = buf_len;\r
-       action[0] = 0;\r
-\r
-       memcpy(ecs_message, "nfc", 10);\r
-       memcpy(ecs_message + 10, &data_len, 2);\r
-       memcpy(ecs_message + 12, &group, 1);\r
-       memcpy(ecs_message + 13, &action, 1);\r
-       memcpy(ecs_message + 14, msg->buf, buf_len);\r
-\r
-       INFO("ntf_to_injector- bufnum: %s, group: %s, action: %s, data: %s\n", data_len, group, action, msg->buf);\r
-\r
-       //ntf_to_injector(ecs_message, message_len);\r
-       send_device_ntf(ecs_message, message_len);\r
-\r
-       if (ecs_message)\r
-               free(ecs_message);\r
-}\r
-\r
-static void virtio_nfc_send(VirtIODevice *vdev, VirtQueue *vq)\r
-{\r
-       VirtIONFC *vnfc = (VirtIONFC *)vdev;\r
-    int index = 0;\r
-    struct msg_info _msg;\r
-\r
-    if (virtio_queue_empty(vnfc->svq)) {\r
-        INFO("<< virtqueue is empty.\n");\r
-        return;\r
-    }\r
-\r
-    VirtQueueElement elem;\r
-\r
-    while ((index = virtqueue_pop(vq, &elem))) {\r
-\r
-               INFO("<< virtqueue pop. index: %d, out_num : %d, in_num : %d\n", index,  elem.out_num, elem.in_num);\r
-\r
-               if (index == 0) {\r
-                       INFO("<< virtqueue break\n");\r
-                       break;\r
-               }\r
-\r
-               INFO("<< use=%d, iov_len = %d\n", _msg.use, elem.out_sg[0].iov_len);\r
-\r
-               memset(&_msg, 0x00, sizeof(_msg));\r
-               memcpy(&_msg, elem.out_sg[0].iov_base, elem.out_sg[0].iov_len);\r
-\r
-               INFO("<< recv from guest len = %d, msg = %s \n", _msg.use, _msg.buf);\r
-\r
-        send_to_ecs(&_msg);\r
-\r
-    }\r
-\r
-       virtqueue_push(vq, &elem, sizeof(VirtIONFC));\r
-       virtio_notify(&vio_nfc->vdev, vq);\r
-}\r
-\r
-static uint32_t virtio_nfc_get_features(VirtIODevice *vdev,\r
-                                            uint32_t request_feature)\r
-{\r
-    TRACE("virtio_nfc_get_features.\n");\r
-    return 0;\r
-}\r
-\r
-static void maru_nfc_bh(void *opaque)\r
-{\r
-       flush_nfc_recv_queue();\r
-}\r
-\r
-static int virtio_nfc_init(VirtIODevice* vdev)\r
-{\r
-    INFO("initialize nfc device\n");\r
-    vio_nfc = VIRTIO_NFC(vdev);\r
-\r
-    virtio_init(vdev, NFC_DEVICE_NAME, VIRTIO_ID_NFC, 0);\r
-\r
-    if (vio_nfc == NULL) {\r
-        ERR("failed to initialize nfc device\n");\r
-        return -1;\r
-    }\r
-\r
-    vio_nfc->rvq = virtio_add_queue(&vio_nfc->vdev, 256, virtio_nfc_recv);\r
-    vio_nfc->svq = virtio_add_queue(&vio_nfc->vdev, 256, virtio_nfc_send);\r
-\r
-    vio_nfc->bh = qemu_bh_new(maru_nfc_bh, vio_nfc);\r
-\r
-    return 0;\r
-}\r
-\r
-static int virtio_nfc_exit(DeviceState* dev)\r
-{\r
-    INFO("destroy nfc device\n");\r
-    VirtIODevice *vdev = VIRTIO_DEVICE(dev);\r
-\r
-    if (vio_nfc->bh) {\r
-            qemu_bh_delete(vio_nfc->bh);\r
-        }\r
-\r
-    virtio_cleanup(vdev);\r
-\r
-    return 0;\r
-}\r
-\r
-static void virtio_nfc_reset(VirtIODevice *vdev)\r
-{\r
-    TRACE("virtio_sensor_reset.\n");\r
-}\r
-\r
-\r
-static void virtio_nfc_class_init(ObjectClass *klass, void *data)\r
-{\r
-    DeviceClass *dc = DEVICE_CLASS(klass);\r
-    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);\r
-    dc->exit = virtio_nfc_exit;\r
-    vdc->init = virtio_nfc_init;\r
-    vdc->get_features = virtio_nfc_get_features;\r
-    vdc->reset = virtio_nfc_reset;\r
-}\r
-\r
-\r
-\r
-static const TypeInfo virtio_device_info = {\r
-    .name = TYPE_VIRTIO_NFC,\r
-    .parent = TYPE_VIRTIO_DEVICE,\r
-    .instance_size = sizeof(VirtIONFC),\r
-    .class_init = virtio_nfc_class_init,\r
-};\r
-\r
-static void virtio_register_types(void)\r
-{\r
-    type_register_static(&virtio_device_info);\r
-}\r
-\r
-type_init(virtio_register_types)\r
-\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
+ *
+ */
+
+#include <pthread.h>
+
+#include "maru_device_ids.h"
+#include "maru_virtio_nfc.h"
+#include "debug_ch.h"
+#include "../ecs/ecs.h"
+
+MULTI_DEBUG_CHANNEL(qemu, virtio-nfc);
+
+#define NFC_DEVICE_NAME "virtio-nfc"
+
+
+enum {
+    IOTYPE_INPUT = 0,
+    IOTYPE_OUTPUT = 1
+};
+
+
+#ifndef min
+#define min(a,b) ((a)<(b)?(a):(b))
+#endif
+
+#define MAX_BUF_SIZE    4096
+
+
+VirtIONFC* vio_nfc;
+
+
+typedef unsigned int CSCliSN;
+
+typedef struct msg_info {
+    char buf[MAX_BUF_SIZE];
+
+    uint32_t route;
+    uint32_t use;
+    uint16_t count;
+    uint16_t index;
+
+    CSCliSN cclisn;
+}msg_info;
+
+//
+
+typedef struct MsgInfo
+{
+    msg_info info;
+    QTAILQ_ENTRY(MsgInfo) next;
+}MsgInfo;
+
+static QTAILQ_HEAD(MsgInfoRecvHead , MsgInfo) nfc_recv_msg_queue =
+    QTAILQ_HEAD_INITIALIZER(nfc_recv_msg_queue);
+
+
+static QTAILQ_HEAD(MsgInfoSendHead , MsgInfo) nfc_send_msg_queue =
+    QTAILQ_HEAD_INITIALIZER(nfc_send_msg_queue);
+
+
+//
+
+typedef struct NFCBuf {
+    VirtQueueElement elem;
+
+    QTAILQ_ENTRY(NFCBuf) next;
+} NFCBuf;
+
+static QTAILQ_HEAD(NFCMsgHead , NFCBuf) nfc_in_queue =
+    QTAILQ_HEAD_INITIALIZER(nfc_in_queue);
+
+static int count = 0;
+
+static pthread_mutex_t recv_buf_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+bool send_to_nfc(enum request_cmd_nfc req, const char* data, const uint32_t len)
+{
+    MsgInfo* _msg = (MsgInfo*) malloc(sizeof(MsgInfo));
+    if (!_msg)
+        return false;
+
+    memset(&_msg->info, 0, sizeof(msg_info));
+
+    memcpy(_msg->info.buf, data, len);
+    _msg->info.use = len;
+    _msg->info.index = count++;
+    _msg->info.route = req;
+    pthread_mutex_lock(&recv_buf_mutex);
+
+    QTAILQ_INSERT_TAIL(&nfc_recv_msg_queue, _msg, next);
+
+    pthread_mutex_unlock(&recv_buf_mutex);
+
+    qemu_bh_schedule(vio_nfc->bh);
+
+    return true;
+}
+
+
+static int g_cnt = 0;
+
+static void flush_nfc_recv_queue(void)
+{
+    int index;
+
+    if (unlikely(!virtio_queue_ready(vio_nfc->rvq))) {
+        INFO("virtio queue is not ready\n");
+        return;
+    }
+
+    if (unlikely(virtio_queue_empty(vio_nfc->rvq))) {
+        TRACE("virtqueue is empty\n");
+        return;
+    }
+
+
+    pthread_mutex_lock(&recv_buf_mutex);
+
+    while (!QTAILQ_EMPTY(&nfc_recv_msg_queue))
+    {
+         MsgInfo* msginfo = QTAILQ_FIRST(&nfc_recv_msg_queue);
+         if (!msginfo)
+             break;
+
+         VirtQueueElement elem;
+         index = virtqueue_pop(vio_nfc->rvq, &elem);
+         if (index == 0)
+         {
+             //ERR("unexpected empty queue");
+             break;
+         }
+
+         INFO(">> virtqueue_pop. index: %d, out_num : %d, in_num : %d\n", index, elem.out_num, elem.in_num);
+
+         memcpy(elem.in_sg[0].iov_base, &msginfo->info, sizeof(struct msg_info));
+
+         INFO(">> send to guest count = %d, use = %d, msg = %s, iov_len = %d \n",
+                 ++g_cnt, msginfo->info.use, msginfo->info.buf, elem.in_sg[0].iov_len);
+
+         virtqueue_push(vio_nfc->rvq, &elem, sizeof(msg_info));
+         virtio_notify(&vio_nfc->vdev, vio_nfc->rvq);
+
+         QTAILQ_REMOVE(&nfc_recv_msg_queue, msginfo, next);
+         if (msginfo)
+             free(msginfo);
+    }
+
+    pthread_mutex_unlock(&recv_buf_mutex);
+
+}
+
+
+static void virtio_nfc_recv(VirtIODevice *vdev, VirtQueue *vq)
+{
+    flush_nfc_recv_queue();
+}
+
+static void send_to_ecs(struct msg_info* msg)
+{
+    type_length length = 0;
+    type_group group = 15;
+    type_action action = 0;
+
+    int buf_len = strlen(msg->buf);
+    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;
+
+    memcpy(ecs_message, "nfc", 10);
+    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, msg->buf, buf_len);
+
+    INFO("ntf_to_injector- len: %d, group: %d, action: %d, data: %s\n", length, group, action, msg->buf);
+
+    send_device_ntf(ecs_message, message_len);
+
+    if (ecs_message)
+        free(ecs_message);
+}
+
+static void virtio_nfc_send(VirtIODevice *vdev, VirtQueue *vq)
+{
+    VirtIONFC *vnfc = (VirtIONFC *)vdev;
+    int index = 0;
+    struct msg_info _msg;
+
+    if (virtio_queue_empty(vnfc->svq)) {
+        INFO("<< virtqueue is empty.\n");
+        return;
+    }
+
+    VirtQueueElement elem;
+
+    while ((index = virtqueue_pop(vq, &elem))) {
+
+        INFO("<< virtqueue pop. index: %d, out_num : %d, in_num : %d\n", index,  elem.out_num, elem.in_num);
+
+        if (index == 0) {
+            INFO("<< virtqueue break\n");
+            break;
+        }
+
+        INFO("<< use=%d, iov_len = %d\n", _msg.use, elem.out_sg[0].iov_len);
+
+        memset(&_msg, 0x00, sizeof(_msg));
+        memcpy(&_msg, elem.out_sg[0].iov_base, elem.out_sg[0].iov_len);
+
+        INFO("<< recv from guest len = %d, msg = %s \n", _msg.use, _msg.buf);
+
+        send_to_ecs(&_msg);
+
+    }
+
+    virtqueue_push(vq, &elem, sizeof(VirtIONFC));
+    virtio_notify(&vio_nfc->vdev, vq);
+}
+
+static uint32_t virtio_nfc_get_features(VirtIODevice *vdev,
+                                            uint32_t request_feature)
+{
+    TRACE("virtio_nfc_get_features.\n");
+    return 0;
+}
+
+static void maru_nfc_bh(void *opaque)
+{
+    flush_nfc_recv_queue();
+}
+
+static int virtio_nfc_init(VirtIODevice* vdev)
+{
+    INFO("initialize nfc device\n");
+    vio_nfc = VIRTIO_NFC(vdev);
+
+    virtio_init(vdev, NFC_DEVICE_NAME, VIRTIO_ID_NFC, 0);
+
+    if (vio_nfc == NULL) {
+        ERR("failed to initialize nfc device\n");
+        return -1;
+    }
+
+    vio_nfc->rvq = virtio_add_queue(&vio_nfc->vdev, 256, virtio_nfc_recv);
+    vio_nfc->svq = virtio_add_queue(&vio_nfc->vdev, 256, virtio_nfc_send);
+
+    vio_nfc->bh = qemu_bh_new(maru_nfc_bh, vio_nfc);
+
+    return 0;
+}
+
+static int virtio_nfc_exit(DeviceState* dev)
+{
+    INFO("destroy nfc device\n");
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+
+    if (vio_nfc->bh) {
+            qemu_bh_delete(vio_nfc->bh);
+        }
+
+    virtio_cleanup(vdev);
+
+    return 0;
+}
+
+static void virtio_nfc_reset(VirtIODevice *vdev)
+{
+    TRACE("virtio_sensor_reset.\n");
+}
+
+
+static void virtio_nfc_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->exit = virtio_nfc_exit;
+    vdc->init = virtio_nfc_init;
+    vdc->get_features = virtio_nfc_get_features;
+    vdc->reset = virtio_nfc_reset;
+}
+
+
+
+static const TypeInfo virtio_device_info = {
+    .name = TYPE_VIRTIO_NFC,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIONFC),
+    .class_init = virtio_nfc_class_init,
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_device_info);
+}
+
+type_init(virtio_register_types)
+
index a651a63..a89272d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Virtio Sensor Device
  *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Contact:
  *  Jinhyung Choi <jinhyung2.choi@samsung.com>
 
 MULTI_DEBUG_CHANNEL(qemu, virtio-sensor);
 
-#define SENSOR_DEVICE_NAME     "sensor"
-#define _MAX_BUF                                       1024
+#define SENSOR_DEVICE_NAME  "sensor"
+#define _MAX_BUF                    1024
 
 
 VirtIOSENSOR* vsensor;
 
 typedef struct msg_info {
-       char buf[_MAX_BUF];
+    char buf[_MAX_BUF];
 
-       uint16_t type;
-       uint16_t req;
+    uint16_t type;
+    uint16_t req;
 
-       QTAILQ_ENTRY(msg_info) next;
+    QTAILQ_ENTRY(msg_info) next;
 } msg_info;
 
 
@@ -61,163 +61,158 @@ static pthread_mutex_t buf_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static void add_msg_queue(msg_info* msg)
 {
-       pthread_mutex_lock(&buf_mutex);
-       QTAILQ_INSERT_TAIL(&sensor_msg_queue, msg, next);
-       pthread_mutex_unlock(&buf_mutex);
+    pthread_mutex_lock(&buf_mutex);
+    QTAILQ_INSERT_TAIL(&sensor_msg_queue, msg, next);
+    pthread_mutex_unlock(&buf_mutex);
 
-       qemu_bh_schedule(vsensor->bh);
+    qemu_bh_schedule(vsensor->bh);
 }
 
 void req_sensor_data (enum sensor_types type, enum request_cmd req, char* data, int len)
 {
-       if (type >= sensor_type_max || (req != request_get && req != request_set)) {
-               ERR("unavailable sensor type request.\n");
-       }
-
-       msg_info* msg = (msg_info*) malloc(sizeof(msg_info));
-       if (!msg) {
-               ERR("The allocation of msg_info is failed.\n");
-               return;
-       }
-
-       memset(msg, 0, sizeof(msg_info));
-
-       if (req == request_set) {
-               if (len > _MAX_BUF) {
-                       ERR("The data is too big to send.\n");
-                       return;
-               }
-               memcpy(msg->buf, data, len);
-       }
-
-       msg->type = type;
-       msg->req = req;
-
-       add_msg_queue(msg);
+    if (type >= sensor_type_max || (req != request_get && req != request_set)) {
+        ERR("unavailable sensor type request.\n");
+    }
+
+    msg_info* msg = (msg_info*) malloc(sizeof(msg_info));
+    if (!msg) {
+        ERR("The allocation of msg_info is failed.\n");
+        return;
+    }
+
+    memset(msg, 0, sizeof(msg_info));
+
+    if (req == request_set) {
+        if (len > _MAX_BUF) {
+            ERR("The data is too big to send.\n");
+            return;
+        }
+        memcpy(msg->buf, data, len);
+    }
+
+    msg->type = type;
+    msg->req = req;
+
+    add_msg_queue(msg);
 }
 
 static void flush_sensor_recv_queue(void)
 {
-       int index;
+    int index;
 
     if (unlikely(!virtio_queue_ready(vsensor->rvq))) {
         INFO("virtio queue is not ready\n");
         return;
     }
 
-       if (unlikely(virtio_queue_empty(vsensor->rvq))) {
-               INFO("virtqueue is empty\n");
-               return;
-       }
-
-       pthread_mutex_lock(&buf_mutex);
-       while (!QTAILQ_EMPTY(&sensor_msg_queue))
-       {
-               msg_info* msginfo = QTAILQ_FIRST(&sensor_msg_queue);
-               if (!msginfo) {
-                       ERR("msginfo is NULL!\n");
-                       break;
-               }
-
-               INFO("sending message: %s, type: %d, req: %d\n", msginfo->buf, msginfo->type, msginfo->req);
-
-               VirtQueueElement elem;
-               index = virtqueue_pop(vsensor->rvq, &elem);
-               if (index == 0)
-                       break;
-
-               memcpy(elem.in_sg[0].iov_base, msginfo, sizeof(struct msg_info));
-
-               virtqueue_push(vsensor->rvq, &elem, sizeof(msg_info));
-               virtio_notify(&vsensor->vdev, vsensor->rvq);
-
-               QTAILQ_REMOVE(&sensor_msg_queue, msginfo, next);
-               if (msginfo)
-                       free(msginfo);
-       }
-       pthread_mutex_unlock(&buf_mutex);
+    if (unlikely(virtio_queue_empty(vsensor->rvq))) {
+        INFO("virtqueue is empty\n");
+        return;
+    }
+
+    pthread_mutex_lock(&buf_mutex);
+    while (!QTAILQ_EMPTY(&sensor_msg_queue))
+    {
+        msg_info* msginfo = QTAILQ_FIRST(&sensor_msg_queue);
+        if (!msginfo) {
+            ERR("msginfo is NULL!\n");
+            break;
+        }
+
+        INFO("sending message: %s, type: %d, req: %d\n", msginfo->buf, msginfo->type, msginfo->req);
+
+        VirtQueueElement elem;
+        index = virtqueue_pop(vsensor->rvq, &elem);
+        if (index == 0)
+            break;
+
+        memcpy(elem.in_sg[0].iov_base, msginfo, sizeof(struct msg_info));
+
+        virtqueue_push(vsensor->rvq, &elem, sizeof(msg_info));
+        virtio_notify(&vsensor->vdev, vsensor->rvq);
+
+        QTAILQ_REMOVE(&sensor_msg_queue, msginfo, next);
+        if (msginfo)
+            free(msginfo);
+    }
+    pthread_mutex_unlock(&buf_mutex);
 }
 
 static void virtio_sensor_recv(VirtIODevice *vdev, VirtQueue *vq)
 {
-       flush_sensor_recv_queue();
+    flush_sensor_recv_queue();
 }
 
 static void maru_sensor_bh(void *opaque)
 {
-       flush_sensor_recv_queue();
+    flush_sensor_recv_queue();
 }
 
-static int get_action(enum sensor_types type)
+static type_action get_action(enum sensor_types type)
 {
-       int action = 0;
-
-       switch (type) {
-       case sensor_type_accel:
-               action = ACTION_ACCEL;
-               break;
-       case sensor_type_gyro:
-               action = ACTION_GYRO;
-               break;
-       case sensor_type_mag:
-               action = ACTION_MAG;
-               break;
-       case sensor_type_light:
-               action = ACTION_LIGHT;
-               break;
-       case sensor_type_proxi:
-               action = ACTION_PROXI;
-               break;
-       default:
-               break;
-       }
-
-       return action;
+    type_action action = 0;
+
+    switch (type) {
+    case sensor_type_accel:
+        action = ACTION_ACCEL;
+        break;
+    case sensor_type_gyro:
+        action = ACTION_GYRO;
+        break;
+    case sensor_type_mag:
+        action = ACTION_MAG;
+        break;
+    case sensor_type_light:
+        action = ACTION_LIGHT;
+        break;
+    case sensor_type_proxi:
+        action = ACTION_PROXI;
+        break;
+    default:
+        break;
+    }
+
+    return action;
 }
 
 static void send_to_ecs(struct msg_info* msg)
 {
-       int buf_len;
-       char data_len [2];
-       char group [1] = { GROUP_STATUS };
-       char action [1];
-       int message_len = 0;
+    type_length length = 0;
+    type_group group = GROUP_STATUS;
+    type_action action = 0;
 
-       char* ecs_message = NULL;
+    int buf_len = strlen(msg->buf);
+    int message_len =  buf_len + 14;
 
-       buf_len = strlen(msg->buf);
-       message_len =  buf_len + 14;
-
-       ecs_message = (char*) malloc(message_len + 1);
-       if (!ecs_message)
-               return;
+    char* ecs_message = (char*) malloc(message_len + 1);
+    if (!ecs_message)
+        return;
 
-       memset(ecs_message, 0, message_len + 1);
+    memset(ecs_message, 0, message_len + 1);
 
-       data_len[0] = buf_len;
-       action[0] = get_action(msg->type);
+    length = (unsigned short) buf_len;
+    action = get_action(msg->type);
 
-       memcpy(ecs_message, MESSAGE_TYPE_SENSOR, 10);
-       memcpy(ecs_message + 10, &data_len, 2);
-       memcpy(ecs_message + 12, &group, 1);
-       memcpy(ecs_message + 13, &action, 1);
-       memcpy(ecs_message + 14, msg->buf, buf_len);
+    memcpy(ecs_message, MESSAGE_TYPE_SENSOR, 10);
+    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, msg->buf, buf_len);
 
-       INFO("ntf_to_injector- bufnum: %s, group: %s, action: %s, data: %s\n", data_len, group, action, msg->buf);
+    INFO("ntf_to_injector- len: %d, group: %d, action: %d, data: %s\n", length, group, action, msg->buf);
 
-       //ntf_to_injector(ecs_message, message_len);
-       send_device_ntf(ecs_message, message_len);
+    send_device_ntf(ecs_message, message_len);
 
-       if (ecs_message)
-               free(ecs_message);
+    if (ecs_message)
+        free(ecs_message);
 }
 
 static void virtio_sensor_send(VirtIODevice *vdev, VirtQueue *vq)
 {
-       VirtIOSENSOR *vsensor = (VirtIOSENSOR*)vdev;
-       struct msg_info msg;
+    VirtIOSENSOR *vsensor = (VirtIOSENSOR*)vdev;
+    struct msg_info msg;
     VirtQueueElement elem;
-       int index = 0;
+    int index = 0;
 
     if (virtio_queue_empty(vsensor->svq)) {
         INFO("<< virtqueue is empty.\n");
@@ -226,15 +221,15 @@ static void virtio_sensor_send(VirtIODevice *vdev, VirtQueue *vq)
 
     while ((index = virtqueue_pop(vq, &elem))) {
 
-               memset(&msg, 0x00, sizeof(msg));
-               memcpy(&msg, elem.out_sg[0].iov_base, elem.out_sg[0].iov_len);
+        memset(&msg, 0x00, sizeof(msg));
+        memcpy(&msg, elem.out_sg[0].iov_base, elem.out_sg[0].iov_len);
 
-               INFO("send to ecs: %s, len: %d, type: %d, req: %d\n", msg.buf, strlen(msg.buf), msg.type, msg.req);
-               send_to_ecs(&msg);
+        INFO("send to ecs: %s, len: %d, type: %d, req: %d\n", msg.buf, strlen(msg.buf), msg.type, msg.req);
+        send_to_ecs(&msg);
     }
 
-       virtqueue_push(vq, &elem, sizeof(VirtIOSENSOR));
-       virtio_notify(&vsensor->vdev, vq);
+    virtqueue_push(vq, &elem, sizeof(VirtIOSENSOR));
+    virtio_notify(&vsensor->vdev, vq);
 }
 
 
@@ -261,11 +256,11 @@ static int virtio_sensor_init(VirtIODevice *vdev)
 
 static int virtio_sensor_exit(DeviceState *dev)
 {
-       VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     INFO("destroy sensor device\n");
 
-       if (vsensor->bh)
-               qemu_bh_delete(vsensor->bh);
+    if (vsensor->bh)
+        qemu_bh_delete(vsensor->bh);
 
     virtio_cleanup(vdev);