ecs: handle device capabilities
authorJinhyung Choi <jinh0.choi@samsung.com>
Mon, 24 Oct 2016 06:36:22 +0000 (15:36 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 2 Nov 2016 10:32:10 +0000 (19:32 +0900)
* capability values are set by emulator daemon
|-------|          |-----|           |---------|
| emuld | -------> | ECS | --------> | clients |
|-------|   set    |-----|  result   |---------|

* ECS stores the value and send it when ECP requests.
|-----|            |-----|           |---------|
| ECP | -------->  | ECS | --------> | clients |
|-----|  request   |-----|  result   |---------|

check sensor & nfc device status additionally.

Change-Id: Icebefa564f0263afff0f0e1b139335c7c6f2ba3d
Signed-off-by: Jinhyung Choi <jinh0.choi@samsung.com>
tizen/src/ecs/ecs.c
tizen/src/ecs/ecs.h
tizen/src/ecs/ecs_msg.c
tizen/src/ecs/ecs_msg_device.c
tizen/src/ecs/ecs_msg_injector.c
tizen/src/hw/virtio/maru_virtio_sensor.c
tizen/src/hw/virtio/maru_virtio_sensor.h

index c77b6c0..7585792 100644 (file)
@@ -51,6 +51,9 @@
 #include "ecs.h"
 #include "emul_state.h"
 
+#include "hw/virtio/maru_virtio_sensor.h"
+#include "hw/virtio/maru_virtio_nfc.h"
+
 #include "debug_ch.h"
 MULTI_DEBUG_CHANNEL(qemu, ecs);
 
@@ -77,6 +80,40 @@ static QemuThread ecs_thread_id;
 
 static int suspend_state = 1;
 
+static char device_capabilities [16];
+
+enum ecs_check_cap_list {
+    CHECK_CAP_BATTERY = 0,
+    CHECK_CAP_LOCATION,
+    CHECK_CAP_NFC,
+    CHECK_CAP_TELEPHONY,
+    CHECK_CAP_ACCEL,
+    CHECK_CAP_GYRO,
+    CHECK_CAP_GEO,
+    CHECK_CAP_PROXI,
+    CHECK_CAP_LIGHT,
+    CHECK_CAP_PRESSURE,
+    CHECK_CAP_HEARTRATE,
+    CHECK_CAP_UV,
+    CHECK_CAP_PEDO
+};
+
+static int cap_device_list[] = {
+    0x0001,             // Battery
+    0x0002,             // Location
+    0x0004,             // NFC
+    0x0008,             // Telephony
+    0x0010,             // Accelerometer
+    0x0020,             // Gyroscope
+    0x0040,             // Magnetometer
+    0x0080,             // Proximity
+    0x0100,             // Light
+    0x0200,             // Pressure
+    0x0400,             // HeartRate
+    0x0800,             // Ultraviolet
+    0x1000,             // Pedometer
+};
+
 void ecs_set_suspend_state(int state)
 {
     suspend_state = state;
@@ -87,6 +124,78 @@ int ecs_get_suspend_state(void)
     return suspend_state;
 }
 
+static void check_sensor_capability(int* capacity)
+{
+    int sensor_cap = get_sensor_capability();
+    if ((sensor_cap & sensor_cap_accel) == 0) {
+        *capacity &= ~cap_device_list[CHECK_CAP_ACCEL];
+    }
+    if ((sensor_cap & sensor_cap_geo) == 0) {
+        *capacity &= ~cap_device_list[CHECK_CAP_GEO];
+    }
+
+    if ((sensor_cap & sensor_cap_gyro) == 0) {
+        *capacity &= ~cap_device_list[CHECK_CAP_GYRO];
+    }
+
+    if ((sensor_cap & sensor_cap_proxi) == 0) {
+        *capacity &= ~cap_device_list[CHECK_CAP_PROXI];
+    }
+
+    if ((sensor_cap & sensor_cap_light) == 0) {
+        *capacity &= ~cap_device_list[CHECK_CAP_LIGHT];
+    }
+
+    if ((sensor_cap & sensor_cap_pressure) == 0) {
+        *capacity &= ~cap_device_list[CHECK_CAP_PRESSURE];
+    }
+
+    if ((sensor_cap & sensor_cap_uv) == 0) {
+        *capacity &= ~cap_device_list[CHECK_CAP_UV];
+    }
+
+    if ((sensor_cap & sensor_cap_hrm) == 0) {
+        *capacity &= ~cap_device_list[CHECK_CAP_HEARTRATE];
+    }
+
+    if ((sensor_cap & sensor_cap_pedo) == 0) {
+        *capacity &= ~cap_device_list[CHECK_CAP_PEDO];
+    }
+}
+
+extern VirtIONFC *vio_nfc;
+static void check_nfc_capability(int* capacity)
+{
+    if (!vio_nfc) {
+        *capacity &= ~cap_device_list[CHECK_CAP_NFC];
+    }
+}
+
+void ecs_set_device_capabilities(const char* cap)
+{
+    int capability = 0;
+
+    memset(device_capabilities, 0, sizeof(device_capabilities));
+
+    if (cap != NULL) {
+        capability = atoi(cap);
+        // check sensor capability
+        check_sensor_capability(&capability);
+        // check nfc capability
+        check_nfc_capability(&capability);
+
+        LOG_INFO("check_sensor_capability: %04x\n", capability);
+        snprintf(device_capabilities, sizeof(device_capabilities), "%d", capability);
+    }
+
+    make_send_device_ntf((char*)MSG_TYPE_CAP, MSG_GROUP_STATUS, 0, device_capabilities);
+}
+
+const char* ecs_get_device_capabilities(void)
+{
+    return device_capabilities;
+}
+
 int ecs_write(int fd, const uint8_t *buf, int len)
 {
     int ret, remain;
index 028c2f0..3458dfa 100644 (file)
@@ -55,6 +55,7 @@
 #define MSG_TYPE_HDS            "hds"
 #define MSG_TYPE_PACKAGE        "package"
 #define MSG_TYPE_SYSTEM         "system"
+#define MSG_TYPE_CAP            "cap"
 
 #define MSG_GROUP_STATUS        15
 
@@ -95,4 +96,8 @@ int ecs_get_suspend_state(void);
 void ecs_set_suspend_state(int state);
 void ecs_suspend_lock_state(int state);
 
+/* Device capabilities check */
+const char* ecs_get_device_capabilities(void);
+void ecs_set_device_capabilities(const char* cap);
+
 #endif /* __ECS_H__ */
index 3eb3148..305eb77 100644 (file)
@@ -197,6 +197,8 @@ void send_shutdown_request(int action)
     if (!ret) {
         LOG_SEVERE("fail to send evdi shutdown system call to emuld.\n");
     }
+
+    ecs_set_device_capabilities(NULL);
 }
 
 bool ntf_to_injector(const char *data, const int len)
index 1cdbe91..4e7f5c1 100644 (file)
@@ -436,6 +436,9 @@ bool msgproc_device_req(ECS_Client *ccli, ECS__DeviceReq *msg)
         g_snprintf(vminfo, sizeof(vminfo) - 1, "%s %s %s",
                 get_vm_name(), get_profile_name(), get_platform_version());
         msgproc_device_ans(ccli, cmd, true, vminfo);
+    } else if (!strcmp(cmd, MSG_TYPE_CAP)) {
+        const char* cap = ecs_get_device_capabilities();
+        make_send_device_ntf(cmd, MSG_GROUP_STATUS, 0, (char*)cap);
     } else if (!strcmp(cmd, "nfc")) {
         msgproc_device_req_nfc(ccli, msg);
     } else if (!strcmp(cmd, "sdcard")) {
index a65f70c..c577ea3 100644 (file)
@@ -463,6 +463,10 @@ static bool injector_req_handle(char *cat, type_action action, const char *data)
         LOG_WARNING("VirtFS is not enabled.\n");
         return false;
 #endif
+    } else if (!strcmp(cat, MSG_TYPE_CAP)) {
+        LOG_INFO("set capabilities: %s\n", data);
+        ecs_set_device_capabilities(data);
+        return true;
     } else if (!strcmp(cat, MSG_TYPE_PACKAGE)) {
         do_package(cat, action, data);
         return true;
index b6522ac..94d892d 100644 (file)
@@ -726,6 +726,11 @@ static void parse_sensor_capability(char *lists)
     LOG_INFO("sensor device capabilty enabled with %02x\n", sensor_capability);
 }
 
+int get_sensor_capability(void)
+{
+    return sensor_capability;
+}
+
 static void virtio_sensor_realize(DeviceState *dev, Error **errp)
 {
     LOG_INFO("initialize virtio-sensor device\n");
index 1c0a743..1cb5b19 100644 (file)
@@ -143,6 +143,8 @@ typedef struct VirtIOSENSOR {
     char            *sensors;
 } VirtIOSENSOR;
 
+int get_sensor_capability(void);
+
 void req_sensor_data(enum sensor_types type, enum request_cmd req, char *data, int len);
 
 #define get_sensor_accel()  \