#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);
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;
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;
#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
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__ */
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")) {