nfc: make nfc prodesure on ecs 55/10855/1
authormunkyu.im <munkyu.im@samsung.com>
Mon, 14 Oct 2013 08:35:59 +0000 (17:35 +0900)
committermunkyu.im <munkyu.im@samsung.com>
Mon, 14 Oct 2013 08:38:06 +0000 (17:38 +0900)
It helps to communicate between ecs and nfc event injectors.

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

index 6840e4c..be54ddc 100644 (file)
@@ -749,6 +749,14 @@ bool handle_protobuf_msg(ECS_Client* cli, char* data, int len)
             goto fail;
         msgproc_device_req(cli, msg);
     }
+    else if (master->type == ECS__MASTER__TYPE__NFC_REQ)
+    {
+        ECS__NfcReq* msg = master->nfc_req;
+        if (!msg)
+            goto fail;
+        msgproc_nfc_req(cli, msg);
+    }
+
     ecs__master__free_unpacked(master, NULL);
     return true;
 fail:
index 29a22d7..fe56349 100644 (file)
@@ -171,6 +171,7 @@ bool send_to_ecp(ECS__Master* master);
 bool send_injector_ntf(const char* data, const int len);
 bool send_monitor_ntf(const char* data, const int len);
 bool send_device_ntf(const char* data, const int len);
+bool send_nfc_ntf(const char* data, const int len);
 
 bool send_to_all_client(const char* data, const int len);
 void send_to_client(int fd, const char* data, const int len) ;
@@ -186,6 +187,7 @@ void read_val_str(const char* data, char* ret_val, int len);
 bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg);
 bool msgproc_monitor_req(ECS_Client *ccli, ECS__MonitorReq* msg);
 bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg);
+bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg);
 
 /* request */
 int accel_min_max(double value);
index 2b139cd..f2acac1 100644 (file)
@@ -61,6 +61,7 @@
 #include "hw/maru_virtio_nfc.h"
 #include "skin/maruskin_operation.h"
 
+#define MAX_BUF_SIZE  255
 // utility functions
 
 static void* build_master(ECS__Master* master, int* payloadsize)
@@ -219,18 +220,30 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
             set_sensor_data(length, data);
         }
     }
-    else if (!strncmp(cmd, MSG_TYPE_NFC, 3)) {
-        if (group == MSG_GROUP_STATUS) {
-            send_to_nfc(request_nfc_get, data, length);
-        }
-        else
-        {
-            send_to_nfc(request_nfc_set, data, length);
-        }
+
+    return true;
+}
+
+
+bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg)
+{
+    char cmd[10];
+    char* data = NULL;
+    memset(cmd, 0, 10);
+    strcpy(cmd, msg->category);
+
+    if (msg->has_data && msg->data.len > 0)
+    {
+        data = (char*)msg->data.data;
+    }
+
+    if (!strncmp(cmd, MSG_TYPE_NFC, 3)) {
+        send_to_nfc(request_nfc_set, data, msg->data.len);
     }
 
     return true;
 }
+
 #if 0
 bool msgproc_screen_dump_req(ECS_Client *ccli, ECS__ScreenDumpReq* msg)
 {
@@ -470,3 +483,45 @@ bool send_device_ntf(const char* data, const int len)
     return true;
 }
 
+bool send_nfc_ntf(const char* data, const int len)
+{
+    const int catsize = 10;
+    char cat[catsize + 1];
+    memset(cat, 0, catsize + 1);
+
+    read_val_str(data, cat, catsize);
+
+    const char* ijdata = (data + catsize + 2);
+
+    LOG("<< header cat = %s", cat);
+
+    ECS__Master master = ECS__MASTER__INIT;
+    ECS__NfcNtf ntf = ECS__NFC_NTF__INIT;
+
+    ntf.category = (char*) g_malloc(catsize + 1);
+    strncpy(ntf.category, cat, 10);
+
+    ntf.has_data = 1;
+
+    ntf.data.data = g_malloc(MAX_BUF_SIZE);
+    ntf.data.len = MAX_BUF_SIZE;
+    memcpy(ntf.data.data, ijdata, MAX_BUF_SIZE);
+
+    LOG("data = %s, length = %d", ijdata, len);
+
+    master.type = ECS__MASTER__TYPE__NFC_NTF;
+    master.nfc_ntf = &ntf;
+
+    send_to_ecp(&master);
+
+    if (ntf.data.data && ntf.data.len > 0)
+    {
+        g_free(ntf.data.data);
+    }
+
+    if (ntf.category)
+        g_free(ntf.category);
+
+    return true;
+}
+
index d40ac50..aaccc8b 100755 (executable)
@@ -36,7 +36,7 @@
 MULTI_DEBUG_CHANNEL(qemu, virtio-nfc);
 
 #define NFC_DEVICE_NAME "virtio-nfc"
-
+#define MAX_BUF_SIZE  255
 
 enum {
     IOTYPE_INPUT = 0,
@@ -48,9 +48,6 @@ enum {
 #define min(a,b) ((a)<(b)?(a):(b))
 #endif
 
-#define MAX_BUF_SIZE    4096
-
-
 VirtIONFC* vio_nfc;
 
 
@@ -183,11 +180,9 @@ static void virtio_nfc_recv(VirtIODevice *vdev, VirtQueue *vq)
 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;
+    int buf_len = MAX_BUF_SIZE;
+    int message_len =  buf_len + 10;
 
     char* ecs_message = (char*) malloc(message_len + 1);
     if (!ecs_message)
@@ -198,14 +193,11 @@ static void send_to_ecs(struct msg_info* msg)
     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);
+    memcpy(ecs_message + 10, msg->buf, buf_len);
 
-    INFO("ntf_to_injector- len: %d, group: %d, action: %d, data: %s\n", length, group, action, msg->buf);
+    INFO("ntf_to_injector- len: %d, data: %s\n", length , msg->buf);
 
-    send_device_ntf(ecs_message, message_len);
+    send_nfc_ntf(ecs_message, message_len);
 
     if (ecs_message)
         free(ecs_message);