From: Jinhyung Choi Date: Mon, 13 Oct 2014 09:07:59 +0000 (+0900) Subject: hds: added "Host Directory Sharing" feature X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~233 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=10afaf788805f6323748631d0d1fad2d483d9dca;p=sdk%2Femulator%2Fqemu.git hds: added "Host Directory Sharing" feature Change-Id: Ic75e1c907d7a47bbb4cf3a42b8d084e709790541 Signed-off-by: Jinhyung Choi --- diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index b54adceb40..59df7fef4c 100644 --- a/fsdev/qemu-fsdev.c +++ b/fsdev/qemu-fsdev.c @@ -101,3 +101,20 @@ FsDriverEntry *get_fsdev_fsentry(char *id) } return NULL; } + +void qemu_fsdev_remove(const char * const id) +{ + if (id) { + struct FsDriverListEntry *fsle; + + QTAILQ_FOREACH(fsle, &fsdriver_entries, next) { + if (strcmp(fsle->fse.fsdev_id, id) == 0) { + QTAILQ_REMOVE(&fsdriver_entries, fsle, next); + g_free(fsle->fse.fsdev_id); + g_free(fsle); + break; + } + } + } +} + diff --git a/fsdev/qemu-fsdev.h b/fsdev/qemu-fsdev.h index 9fa45bf510..df69094a37 100644 --- a/fsdev/qemu-fsdev.h +++ b/fsdev/qemu-fsdev.h @@ -40,6 +40,7 @@ typedef struct FsDriverListEntry { } FsDriverListEntry; int qemu_fsdev_add(QemuOpts *opts); +void qemu_fsdev_remove(const char * const id); FsDriverEntry *get_fsdev_fsentry(char *id); extern FileOperations local_ops; extern FileOperations handle_ops; diff --git a/tizen/src/ecs/Makefile.tizen b/tizen/src/ecs/Makefile.tizen index 0d1a74f86c..a2359dfbc5 100644 --- a/tizen/src/ecs/Makefile.tizen +++ b/tizen/src/ecs/Makefile.tizen @@ -6,6 +6,8 @@ QEMU_CFLAGS += -I$(SRC_PATH)/tizen/distrib/protobuf QEMU_CFLAGS += -I$(SRC_PATH)/tizen/src/ecs/genmsg obj-y += ecs.pb-c.o ecs_ids.pb-c.o protobuf-c.o -obj-y += ecs_msg.o ecs.o ecs_sensor.o +obj-y += ecs.o ecs_msg.o ecs_msg_injector.o ecs_msg_device.o obj-y += ecs_mon.o ecs-json-streamer.o obj-y += ecs_tethering.o +obj-y += ecs_sensor.o +obj-y += ecs_nfc.o diff --git a/tizen/src/ecs/ecs.h b/tizen/src/ecs/ecs.h index 4d208b4696..67c1f10f64 100644 --- a/tizen/src/ecs/ecs.h +++ b/tizen/src/ecs/ecs.h @@ -178,7 +178,14 @@ bool ntf_to_injector(const char* data, const int len); bool ntf_to_control(const char* data, const int len); bool ntf_to_monitor(const char* data, const int len); -bool send_to_ecp(ECS__Master* master); +bool send_msg_to_guest(ECS_Client* ccli, char* cmd, int group, int action, + char* data, int data_len); +//TODO: clean up +void make_send_device_ntf (char* cmd, int group, int action, char* data); +bool do_virtfs_detach(void); //TODO: move it. + +bool pb_to_all_clients(ECS__Master* master); +bool pb_to_single_client(ECS__Master* master, ECS_Client *clii); bool send_injector_ntf(const char* data, const int len); bool send_monitor_ntf(const char* data, const int len); diff --git a/tizen/src/ecs/ecs_mon.c b/tizen/src/ecs/ecs_mon.c index 1161e0750b..a51fa1005e 100644 --- a/tizen/src/ecs/ecs_mon.c +++ b/tizen/src/ecs/ecs_mon.c @@ -112,7 +112,7 @@ bool send_monitor_ntf(const char* data, int size) master.type = ECS__MASTER__TYPE__MONITOR_NTF; master.monitor_ntf = &ntf; - send_to_ecp(&master); + pb_to_all_clients(&master); if (ntf.command) g_free(ntf.command); diff --git a/tizen/src/ecs/ecs_msg.c b/tizen/src/ecs/ecs_msg.c index 8cf336244f..55aef098ce 100644 --- a/tizen/src/ecs/ecs_msg.c +++ b/tizen/src/ecs/ecs_msg.c @@ -42,7 +42,6 @@ #include "qapi/qmp/json-parser.h" #include "ui/qemu-spice.h" #include "qemu/queue.h" -#include "qemu/option.h" #include "sysemu/char.h" #include "qemu/main-loop.h" @@ -55,36 +54,14 @@ #include "ecs-json-streamer.h" #include "qmp-commands.h" -#include "ecs.h" -#include "mloop_event.h" -#ifndef CONFIG_USE_SHM -#include "maru_finger.h" -#endif - -#include "hw/maru_virtio_evdi.h" -#include "hw/maru_virtio_sensor.h" -#include "hw/maru_virtio_jack.h" -#include "hw/maru_virtio_power.h" -#include "hw/maru_virtio_nfc.h" #include "hw/maru_virtio_vmodem.h" -#include "skin/maruskin_operation.h" -#include "skin/maruskin_server.h" -#include "emulator.h" -#include "emul_state.h" +#include "hw/maru_virtio_evdi.h" + +#include "ecs.h" #include "debug_ch.h" -MULTI_DEBUG_CHANNEL(qemu, ecs); -// utility functions -static int guest_connection = 0; -extern QemuMutex mutex_guest_connection; -extern QemuMutex mutex_location_data; -static bool is_sdcard_attached = false; -static char location_data[MAX_INJECTOR_REQ_DATA]; -/*static function define*/ -static bool handle_sdcard(char* dataBuf, size_t dataLen); -static char* get_emulator_sdcard_path(void); -static char *get_old_tizen_sdk_data_path(void); +MULTI_DEBUG_CHANNEL(qemu, ecs); static void* build_master(ECS__Master* master, int* payloadsize) { @@ -103,26 +80,7 @@ static void* build_master(ECS__Master* master, int* payloadsize) return buf; } -static bool send_single_msg(ECS__Master* master, ECS_Client *clii) -{ - int payloadsize = 0; - void* buf = build_master(master, &payloadsize); - if (!buf) - { - ERR("invalid buf\n"); - return false; - } - - send_to_single_client(clii, buf, payloadsize); - - if (buf) - { - g_free(buf); - } - return true; -} - -bool send_to_ecp(ECS__Master* master) +bool pb_to_all_clients(ECS__Master* master) { int payloadsize = 0; void* buf = build_master(master, &payloadsize); @@ -141,8 +99,8 @@ bool send_to_ecp(ECS__Master* master) } return true; } -#if 0 -static bool send_to_single_client(ECS__Master* master, ECS_Client *ccli) + +bool pb_to_single_client(ECS__Master* master, ECS_Client *clii) { int payloadsize = 0; void* buf = build_master(master, &payloadsize); @@ -152,8 +110,7 @@ static bool send_to_single_client(ECS__Master* master, ECS_Client *ccli) return false; } - if (!send_to_client(ccli->client_fd, buf, payloadsize)) - return false; + send_to_single_client(clii, buf, payloadsize); if (buf) { @@ -161,197 +118,72 @@ static bool send_to_single_client(ECS__Master* master, ECS_Client *ccli) } return true; } -#endif - -static void send_gen_injector_ntf(const char* cmd, int cmdlen, int grp, int act, char* on) -{ - int msglen = 0, datalen = 0; - type_length length = 0; - type_group group = grp; - type_action action = act; - - if (cmd == NULL || cmdlen > 10) - return; - - if (on == NULL) { - msglen = 14; - } else { - datalen = strlen(on); - length = (unsigned short)datalen; - - msglen = datalen + 15; - } - - char* status_msg = (char*) malloc(msglen); - if(!status_msg) - return; - - memset(status_msg, 0, msglen); - - memcpy(status_msg, cmd, cmdlen); - memcpy(status_msg + 10, &length, sizeof(unsigned short)); - memcpy(status_msg + 12, &group, sizeof(unsigned char)); - memcpy(status_msg + 13, &action, sizeof(unsigned char)); - - if (on != NULL) { - memcpy(status_msg + 14, on, datalen); - } - - send_injector_ntf(status_msg, msglen); - - if (status_msg) - free(status_msg); -} -static void send_status_injector_ntf(const char* cmd, int cmdlen, int act, char* on) +void msgproc_keepalive_ans (ECS_Client* ccli, ECS__KeepAliveAns* msg) { - int msglen = 0, datalen = 0; - type_length length = 0; - type_group group = GROUP_STATUS; - type_action action = act; - - if (cmd == NULL || cmdlen > 10) - return; - - if (on == NULL) { - msglen = 14; - } else { - datalen = strlen(on); - length = (unsigned short)datalen; - - msglen = datalen + 15; - } - - char* status_msg = (char*) malloc(msglen); - if(!status_msg) - return; - - memset(status_msg, 0, msglen); - - memcpy(status_msg, cmd, cmdlen); - memcpy(status_msg + 10, &length, sizeof(unsigned short)); - memcpy(status_msg + 12, &group, sizeof(unsigned char)); - memcpy(status_msg + 13, &action, sizeof(unsigned char)); - - if (on != NULL) { - memcpy(status_msg + 14, on, datalen); - } - - send_injector_ntf(status_msg, msglen); - - if (status_msg) - free(status_msg); + ccli->keep_alive = 0; } -static void msgproc_injector_ans(ECS_Client* ccli, const char* category, bool succeed) +void make_send_device_ntf (char* cmd, int group, int action, char* data) { - if (ccli == NULL) { - return; + int msg_length = 15; + type_length length = 0; + if (data != NULL) { + length = strlen(data); } - int catlen = 0; - ECS__Master master = ECS__MASTER__INIT; - ECS__InjectorAns ans = ECS__INJECTOR_ANS__INIT; - - TRACE("injector ans - category : %s, succed : %d\n", category, succeed); - catlen = strlen(category); - ans.category = (char*) g_malloc0(catlen + 1); - memcpy(ans.category, category, catlen); + msg_length += length; - ans.errcode = !succeed; - master.type = ECS__MASTER__TYPE__INJECTOR_ANS; - master.injector_ans = &ans; - - send_to_ecp(&master); - - if (ans.category) - g_free(ans.category); -} - -static void msgproc_device_ans(ECS_Client* ccli, const char* category, bool succeed, char* data) -{ - if (ccli == NULL) { + char* send_msg = (char*) malloc(msg_length); + if(!send_msg) return; - } - int catlen = 0; - ECS__Master master = ECS__MASTER__INIT; - ECS__DeviceAns ans = ECS__DEVICE_ANS__INIT; - - TRACE("device ans - category : %s, succed : %d\n", category, succeed); - - catlen = strlen(category); - ans.category = (char*) g_malloc0(catlen + 1); - memcpy(ans.category, category, catlen); - - ans.errcode = !succeed; + memcpy(send_msg, cmd, 10); + memcpy(send_msg + 10, &length, sizeof(unsigned short)); + memcpy(send_msg + 12, &group, sizeof(unsigned char)); + memcpy(send_msg + 13, &action, sizeof(unsigned char)); if (data != NULL) { - ans.length = strlen(data); - - if (ans.length > 0) { - ans.has_data = 1; - ans.data.data = g_malloc(ans.length); - ans.data.len = ans.length; - memcpy(ans.data.data, data, ans.length); - TRACE("data = %s, length = %hu\n", data, ans.length); - } + memcpy(send_msg + 14, data, strlen(data)); } - master.type = ECS__MASTER__TYPE__DEVICE_ANS; - master.device_ans = &ans; - - send_to_ecp(&master); + send_device_ntf(send_msg, msg_length); - if (ans.category) - g_free(ans.category); + free(send_msg); } -#define STATUS_RSSI_LEVEL 104 - -static bool injector_send(ECS_Client* ccli, ECS__InjectorReq* msg, char* cmd) +bool send_msg_to_guest(ECS_Client* ccli, char* cmd, int group, int action, char* data, int data_len) { int sndlen = 15; // HEADER(CMD + LENGTH + GROUP + ACTION) + 1 - const char* msg_data; char* sndbuf; bool ret = false; - type_group group; - group = (type_group) (msg->group & 0xff); - - if (msg->has_data && msg->data.data && msg->data.len > 0) - sndlen += msg->data.len; + if (data != NULL) + sndlen += data_len; sndbuf = (char*) g_malloc0(sndlen); if (!sndbuf) { - msgproc_injector_ans(ccli, cmd, false); return false; } memcpy(sndbuf, cmd, 10); - memcpy(sndbuf + 10, &msg->length, 2); - memcpy(sndbuf + 12, &msg->group, 1); - memcpy(sndbuf + 13, &msg->action, 1); + memcpy(sndbuf + 10, &data_len, 2); + memcpy(sndbuf + 12, &group, 1); + memcpy(sndbuf + 13, &action, 1); - if (msg->has_data && msg->data.data && msg->data.len > 0) { - msg_data = (const char*)msg->data.data; - memcpy(sndbuf + 14, msg_data, msg->data.len); - TRACE(">> print len = %zd, data\" %s\"\n", msg->data.len, msg_data); + if (data != NULL) { + memcpy(sndbuf + 14, data, data_len); } if(strcmp(cmd, "telephony") == 0) { TRACE("telephony msg >>"); ret = send_to_vmodem(route_ij, sndbuf, sndlen); } else { - TRACE("evdi msg >> %s", cmd); + INFO("evdi msg >> %s", cmd); ret = send_to_evdi(route_ij, sndbuf, sndlen); } g_free(sndbuf); - if (group != MSG_GROUP_STATUS) { - msgproc_injector_ans(ccli, cmd, ret); - } - if (!ret) { return false; } @@ -359,382 +191,6 @@ static bool injector_send(ECS_Client* ccli, ECS__InjectorReq* msg, char* cmd) return true; } -static bool injector_req_sdcard(ECS_Client* ccli, ECS__InjectorReq* msg, char *cmd) -{ - if (msg->has_data) { - TRACE("msg(%zu) : %s\n", msg->data.len, msg->data.data); - if (handle_sdcard((char*) msg->data.data, msg->data.len) > 0) { - return false; - } - } else { - ERR("has no msg\n"); - } - - return injector_send(ccli, msg, cmd); -} - -static bool injector_req_sensor(ECS_Client* ccli, ECS__InjectorReq* msg, char *cmd) -{ - char data[MAX_INJECTOR_REQ_DATA]; - type_group group; - type_action action; - - memset(data, 0, MAX_INJECTOR_REQ_DATA); - group = (type_group) (msg->group & 0xff); - action = (type_action) (msg->action & 0xff); - - if (group == MSG_GROUP_STATUS) { - switch (action) { - case MSG_ACT_BATTERY_LEVEL: - sprintf(data, "%d", get_power_capacity()); - break; - case MSG_ACT_BATTERY_CHARGER: - sprintf(data, "%d", get_jack_charger()); - break; - case MSG_ACT_USB: - sprintf(data, "%d", get_jack_usb()); - break; - case MSG_ACT_EARJACK: - sprintf(data, "%d", get_jack_earjack()); - break; - case MSG_ACT_LOCATION: - qemu_mutex_lock(&mutex_location_data); - sprintf(data, "%s", location_data); - qemu_mutex_unlock(&mutex_location_data); - break; - default: - return injector_send(ccli, msg, cmd); - } - TRACE("status : %s\n", data); - send_status_injector_ntf(MSG_TYPE_SENSOR, 6, action, data); - return true; - } else if (msg->data.data && msg->data.len > 0) { - set_injector_data((char*) msg->data.data); - return injector_send(ccli, msg, cmd); - } - - return false; -} - -static bool injector_req_guest(void) -{ - int value = 0; - qemu_mutex_lock(&mutex_guest_connection); - value = guest_connection; - qemu_mutex_unlock(&mutex_guest_connection); - send_status_injector_ntf(MSG_TYPE_GUEST, 5, value, NULL); - return true; -} - -static bool injector_req_location(ECS_Client* ccli, ECS__InjectorReq* msg, char *cmd) -{ - if (msg->data.data != NULL && msg->data.len > 0) { - qemu_mutex_lock(&mutex_location_data); - snprintf(location_data, msg->data.len + 1, "%s", (char*)msg->data.data); - qemu_mutex_unlock(&mutex_location_data); - return injector_send(ccli, msg, cmd); - } - - return false; -} - -bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg) -{ - char cmd[11]; - bool ret = false; - - strncpy(cmd, msg->category, sizeof(cmd) - 1); - - if (!strcmp(cmd, MSG_TYPE_SDCARD)) { - ret = injector_req_sdcard(ccli, msg, cmd); - } else if (!strcmp(cmd, MSG_TYPE_SENSOR)) { - ret = injector_req_sensor(ccli, msg, cmd); - } else if (!strcmp(cmd, MSG_TYPE_GUEST)) { - ret = injector_req_guest(); - } else if (!strcmp(cmd, MSG_TYPE_LOCATION)) { - ret = injector_req_location(ccli, msg, cmd); - } else { - ret = injector_send(ccli, msg, cmd); - } - - return ret; -} - -void ecs_suspend_lock_state(int state) -{ - int catlen; - - ECS__InjectorReq msg = ECS__INJECTOR_REQ__INIT; - const char* category = "suspend"; - - catlen = strlen(category); - msg.category = (char*) g_malloc0(catlen + 1); - memcpy(msg.category, category, catlen); - - msg.group = 5; - msg.action = state; - - msgproc_injector_req(NULL, &msg); -} - - -void msgproc_keepalive_ans (ECS_Client* ccli, ECS__KeepAliveAns* msg) -{ - ccli->keep_alive = 0; -} - -void send_host_keyboard_ntf (int on) -{ - type_length length = (unsigned short)1; - type_group group = GROUP_STATUS; - type_action action = 122; - - char* keyboard_msg = (char*) malloc(15); - if(!keyboard_msg) - return; - - memcpy(keyboard_msg, "HKeyboard", 10); - memcpy(keyboard_msg + 10, &length, sizeof(unsigned short)); - memcpy(keyboard_msg + 12, &group, sizeof(unsigned char)); - memcpy(keyboard_msg + 13, &action, sizeof(unsigned char)); - memcpy(keyboard_msg + 14, ((on == 1) ? "1":"0"), 1); - - send_device_ntf(keyboard_msg, 15); - - if (keyboard_msg) - free(keyboard_msg); -} - -extern char tizen_target_img_path[]; -void send_target_image_information(ECS_Client* ccli) { - ECS__Master master = ECS__MASTER__INIT; - ECS__DeviceAns ans = ECS__DEVICE_ANS__INIT; - int length = strlen(tizen_target_img_path); // ?? - - ans.category = (char*) g_malloc(10 + 1); - strncpy(ans.category, "info", 10); - - ans.errcode = 0; - ans.length = length; - ans.group = 1; - ans.action = 1; - - if (length > 0) - { - ans.has_data = 1; - - ans.data.data = g_malloc(length); - ans.data.len = length; - memcpy(ans.data.data, tizen_target_img_path, length); - - TRACE("data = %s, length = %hu\n", tizen_target_img_path, length); - } - - master.type = ECS__MASTER__TYPE__DEVICE_ANS; - master.device_ans = &ans; - - send_single_msg(&master, ccli); - - if (ans.data.len > 0) - { - g_free(ans.data.data); - } - - g_free(ans.category); - -} - -bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg) -{ - int is_on = 0; - char cmd[10]; - char* data = NULL; - memset(cmd, 0, 10); - strcpy(cmd, msg->category); - type_length length = (type_length) msg->length; - type_group group = (type_group) (msg->group & 0xff); - type_action action = (type_action) (msg->action & 0xff); - - if (msg->has_data && msg->data.len > 0) - { - data = (char*) g_malloc0(msg->data.len + 1); - memcpy(data, msg->data.data, msg->data.len); - } - - TRACE(">> device_req: header = cmd = %s, length = %d, action=%d, group=%d\n", cmd, length, - action, group); - - if (!strcmp(cmd, MSG_TYPE_SENSOR)) { - if (group == MSG_GROUP_STATUS) { - if (action == MSG_ACT_ACCEL) { - get_sensor_accel(); - } else if (action == MSG_ACT_GYRO) { - get_sensor_gyro(); - } else if (action == MSG_ACT_MAG) { - get_sensor_mag(); - } else if (action == MSG_ACT_LIGHT) { - get_sensor_light(); - } else if (action == MSG_ACT_PROXI) { - get_sensor_proxi(); - } - } else { - if (data != NULL) { - set_injector_data(data); - } else { - ERR("sensor set data is null\n"); - } - } - msgproc_device_ans(ccli, cmd, true, NULL); - } else if (!strcmp(cmd, "Network")) { - if (data != NULL) { - TRACE(">>> Network msg: '%s'\n", data); - if(net_slirp_redir(data) < 0) { - ERR( "redirect [%s] fail\n", data); - } else { - TRACE("redirect [%s] success\n", data); - } - } else { - ERR("Network redirection data is null.\n"); - } - } else if (!strcmp(cmd, "HKeyboard")) { - if (group == MSG_GROUP_STATUS) { - send_host_keyboard_ntf(mloop_evcmd_get_hostkbd_status()); - } else { - if (data == NULL) { - ERR("HKeyboard data is NULL\n"); - return false; - } - - if (!strcmp(data, "1")) { - is_on = 1; - } - do_host_kbd_enable(is_on); - notify_host_kbd_state(is_on); - } - } else if (!strcmp(cmd, "TGesture")) { - /* release multi-touch */ -#ifndef CONFIG_USE_SHM - if (get_multi_touch_enable() != 0) { - clear_finger_slot(false); - } -#else - // TODO: -#endif - - if (data == NULL) { - ERR("touch gesture data is NULL\n"); - return false; - } - - TRACE("%s\n", data); - - char token[] = "#"; - - if (group == 1) { /* HW key event */ - char *section = strtok(data, token); - int event_type = atoi(section); - - section = strtok(NULL, token); - int keycode = atoi(section); - - do_hw_key_event(event_type, keycode); - } else { /* touch event */ - char *section = strtok(data, token); - int event_type = atoi(section); - - section = strtok(NULL, token); - int xx = atoi(section); - - section = strtok(NULL, token); - int yy = atoi(section); - - section = strtok(NULL, token); - int zz = atoi(section); - - do_mouse_event(1/* LEFT */, event_type, 0, 0, xx, yy, zz); - } - } else if (!strcmp(cmd, "info")) { - // check to emulator target image path - TRACE("receive info message %s\n", tizen_target_img_path); - send_target_image_information(ccli); - - } else if (!strcmp(cmd, "input")) { - // cli input - TRACE("receive input message [%s]\n", data); - - if (group == 0) { - - TRACE("input keycode data : [%s]\n", data); - - char token[] = " "; - char *section = strtok(data, token); - int keycode = atoi(section); - if (action == 1) { - //action 1 press - do_hw_key_event(KEY_PRESSED, keycode); - - } else if (action == 2) { - //action 2 released - do_hw_key_event(KEY_RELEASED, keycode); - - } else { - ERR("unknown action : [%d]\n", (int)action); - } - } else if (group == 1) { - //spec out - TRACE("input category's group 1 is spec out\n"); - } else { - ERR("unknown group [%d]\n", (int)group); - } - msgproc_device_ans(ccli, cmd, true, NULL); - - } else if (!strcmp(cmd, "vmname")) { - char* vmname = get_emul_vm_name(); - msgproc_device_ans(ccli, cmd, true, vmname); - } else if (!strcmp(cmd, "nfc")) { - if (group == MSG_GROUP_STATUS) { - get_nfc_data(); - } else { - if (data != NULL) { - send_to_nfc(ccli->client_id, ccli->client_type, data, msg->data.len); - } else { - ERR("nfc data is null\n"); - } - } - } else { - ERR("unknown cmd [%s]\n", cmd); - } - - if (data) { - g_free(data); - } - - return true; -} - -bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg) -{ - int datalen = msg->data.len; - void* data = (void*)g_malloc(datalen); - if(!data) { - ERR("g_malloc failed!\n"); - return false; - } - - memset(data, 0, datalen); - memcpy(data, msg->data.data, msg->data.len); - - if (msg->has_data && msg->data.len > 0) - { - TRACE("recv from nfc injector: %s, %z\n", msg->has_data, msg->data.len); - print_binary(data, datalen); - } - - send_to_nfc(ccli->client_id, ccli->client_type, data, msg->data.len); - g_free(data); - return true; -} - bool ntf_to_injector(const char* data, const int len) { type_length length = 0; type_group group = 0; @@ -798,459 +254,3 @@ bool ntf_to_injector(const char* data, const int len) { return true; } -static bool injector_req_handle(const char* cat, type_action action) -{ - /*SD CARD msg process*/ - if (!strcmp(cat, MSG_TYPE_SDCARD)) { - return false; - - } else if (!strcmp(cat, "suspend")) { - ecs_suspend_lock_state(ecs_get_suspend_state()); - return true; - } else if (!strcmp(cat, MSG_TYPE_GUEST)) { - INFO("emuld connection is %d\n", action); - qemu_mutex_lock(&mutex_guest_connection); - guest_connection = action; - qemu_mutex_unlock(&mutex_guest_connection); - return false; - } - - return false; -} - -bool send_injector_ntf(const char* data, const int len) -{ - type_length length = 0; - type_group group = 0; - type_action action = 0; - - const int catsize = 10; - char cat[catsize + 1]; - memset(cat, 0, catsize + 1); - - read_val_str(data, cat, catsize); - read_val_short(data + catsize, &length); - read_val_char(data + catsize + 2, &group); - read_val_char(data + catsize + 2 + 1, &action); - - if (injector_req_handle(cat, action)) { - return true; - } - - const char* ijdata = (data + catsize + 2 + 1 + 1); - - TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group); - - ECS__Master master = ECS__MASTER__INIT; - ECS__InjectorNtf ntf = ECS__INJECTOR_NTF__INIT; - - ntf.category = (char*) g_malloc(catsize + 1); - strncpy(ntf.category, cat, 10); - - ntf.length = length; - ntf.group = group; - ntf.action = action; - - if (length > 0) - { - ntf.has_data = 1; - - ntf.data.data = g_malloc(length); - ntf.data.len = length; - memcpy(ntf.data.data, ijdata, length); - } - - master.type = ECS__MASTER__TYPE__INJECTOR_NTF; - master.injector_ntf = &ntf; - - send_to_ecp(&master); - - if (ntf.data.len > 0) - { - g_free(ntf.data.data); - } - - g_free(ntf.category); - - return true; -} - -bool send_device_ntf(const char* data, const int len) -{ - type_length length = 0; - type_group group = 0; - type_action action = 0; - - const int catsize = 10; - char cat[catsize + 1]; - memset(cat, 0, catsize + 1); - - read_val_str(data, cat, catsize); - read_val_short(data + catsize, &length); - read_val_char(data + catsize + 2, &group); - read_val_char(data + catsize + 2 + 1, &action); - - const char* ijdata = (data + catsize + 2 + 1 + 1); - - TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group); - - ECS__Master master = ECS__MASTER__INIT; - ECS__DeviceNtf ntf = ECS__DEVICE_NTF__INIT; - - ntf.category = (char*) g_malloc(catsize + 1); - strncpy(ntf.category, cat, 10); - - - ntf.length = length; - ntf.group = group; - ntf.action = action; - - if (length > 0) - { - ntf.has_data = 1; - - ntf.data.data = g_malloc(length); - ntf.data.len = length; - memcpy(ntf.data.data, ijdata, length); - - TRACE("data = %s, length = %hu\n", ijdata, length); - } - - master.type = ECS__MASTER__TYPE__DEVICE_NTF; - master.device_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; -} - -bool send_nfc_ntf(struct nfc_msg_info* msg) -{ - const int catsize = 10; - char cat[catsize + 1]; - ECS_Client *clii; - memset(cat, 0, catsize + 1); - - print_binary((char*)msg->buf, msg->use); - TRACE("id: %02x, type: %02x, use: %d\n", msg->client_id, msg->client_type, msg->use); - clii = find_client(msg->client_id, msg->client_type); - if (clii) { - if(clii->client_type == TYPE_SIMUL_NFC) { - strncpy(cat, MSG_TYPE_NFC, 3); - } else if (clii->client_type == TYPE_ECP) { - strncpy(cat, MSG_TYPE_SIMUL_NFC, 9); - }else { - ERR("cannot find type! : %d\n", clii->client_type); - } - TRACE("header category = %s\n", cat); - } - else { - ERR("cannot find client!\n"); - } - - 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(NFC_MAX_BUF_SIZE); - ntf.data.len = NFC_MAX_BUF_SIZE; - memcpy(ntf.data.data, msg->buf, NFC_MAX_BUF_SIZE); - - TRACE("send to nfc injector: \n"); - 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; -} - -static bool handle_sdcard(char* dataBuf, size_t dataLen) -{ - int err_no = 0; - char ret = 0; - INFO("handle_sdcard() data: %s\n", dataBuf); - if (dataBuf != NULL) { - ret = dataBuf[0]; - - if (ret == '0' ) { - /* umount sdcard */ - //mloop_evcmd_usbdisk(NULL); - char sdcard_img_path[256]; - char* sdcard_path = NULL; - - sdcard_path = get_emulator_sdcard_path(); - if (sdcard_path) { - g_strlcpy(sdcard_img_path, sdcard_path, - sizeof(sdcard_img_path)); - - /* emulator_sdcard_img_path + sdcard img name */ - char* sdcard_img_name = dataBuf+2; - if (dataLen > 3 && sdcard_img_name != NULL) { - char* pLinechange = strchr(sdcard_img_name, '\n'); - if(pLinechange != NULL){ - sdcard_img_name = g_strndup(sdcard_img_name, pLinechange - sdcard_img_name); - } - - g_strlcat(sdcard_img_path, sdcard_img_name, sizeof(sdcard_img_path)); - INFO("sdcard path: [%s]\n", sdcard_img_path); - - /*if using strndup than free string*/ - if (pLinechange != NULL && sdcard_img_name!= NULL) { - free(sdcard_img_name); - } - } - g_free(sdcard_path); - - } - err_no = remove_sdcard_lock_os(sdcard_img_path); - INFO("umount err_no: %d\n", err_no); - if (errno == 0 && is_sdcard_attached) { - mloop_evcmd_sdcard(NULL); - is_sdcard_attached = false; - } else { - ERR("failed to umount: %s\n", sdcard_img_path); - send_gen_injector_ntf(MSG_TYPE_SDCARD, 6, 11, err_no, NULL); - return err_no; - } - } - else if (ret == '1') { - /* mount sdcard */ - char sdcard_img_path[256]; - char* sdcard_path = NULL; - - sdcard_path = get_emulator_sdcard_path(); - if (sdcard_path) { - g_strlcpy(sdcard_img_path, sdcard_path, - sizeof(sdcard_img_path)); - - /* emulator_sdcard_img_path + sdcard img name */ - char* sdcard_img_name = dataBuf+2; - if (dataLen > 3 && sdcard_img_name != NULL) { - char* pLinechange = strchr(sdcard_img_name, '\n'); - if(pLinechange != NULL){ - sdcard_img_name = g_strndup(sdcard_img_name, pLinechange - sdcard_img_name); - } - - g_strlcat(sdcard_img_path, sdcard_img_name, sizeof(sdcard_img_path)); - TRACE("sdcard path: [%s]\n", sdcard_img_path); - - //mloop_evcmd_usbdisk(sdcard_img_path); - if (!is_sdcard_attached && make_sdcard_lock_os(sdcard_img_path)) { - mloop_evcmd_sdcard(sdcard_img_path); - is_sdcard_attached = true; - } else { - send_gen_injector_ntf(MSG_TYPE_SDCARD, 6, 11, 5, NULL); - return ERR_LCK; - } - /*if using strndup than free string*/ - if (pLinechange != NULL && sdcard_img_name!= NULL) { - free(sdcard_img_name); - } - - } - - g_free(sdcard_path); - } else { - ERR("failed to get sdcard path!!\n"); - } - } else if (ret == '2') { - TRACE("sdcard status 2 bypass\n" ); - } else { - ERR("!!! unknown command : %c\n", ret); - } - - } else { - ERR("!!! unknown data : %c\n", ret); - } - return ERR_SUCCESS; -} - -static char* get_emulator_sdcard_path(void) -{ - char *emulator_sdcard_path = NULL; - char *tizen_sdk_data = NULL; - -#ifndef CONFIG_WIN32 - char emulator_sdcard[] = "/emulator/sdcard/"; -#else - char emulator_sdcard[] = "\\emulator\\sdcard\\"; -#endif - - TRACE("emulator_sdcard: %s, %zu\n", emulator_sdcard, sizeof(emulator_sdcard)); - - tizen_sdk_data = get_tizen_sdk_data_path(); - if (!tizen_sdk_data) { - ERR("failed to get tizen-sdk-data path.\n"); - return NULL; - } - - emulator_sdcard_path = - g_malloc(strlen(tizen_sdk_data) + sizeof(emulator_sdcard) + 1); - if (!emulator_sdcard_path) { - ERR("failed to allocate memory.\n"); - return NULL; - } - - g_snprintf(emulator_sdcard_path, strlen(tizen_sdk_data) + sizeof(emulator_sdcard), - "%s%s", tizen_sdk_data, emulator_sdcard); - - g_free(tizen_sdk_data); - - TRACE("sdcard path: %s\n", emulator_sdcard_path); - return emulator_sdcard_path; -} - -/* - * get tizen-sdk-data path from sdk.info. - */ -char *get_tizen_sdk_data_path(void) -{ - char *emul_bin_path = NULL; - char *sdk_info_file_path = NULL; - char *tizen_sdk_data_path = NULL; -#ifndef CONFIG_WIN32 - const char *sdk_info = "../../../sdk.info"; -#else - const char *sdk_info = "..\\..\\..\\sdk.info"; -#endif - const char sdk_data_var[] = "TIZEN_SDK_DATA_PATH"; - - FILE *sdk_info_fp = NULL; - int sdk_info_path_len = 0; - - TRACE("%s\n", __func__); - - emul_bin_path = get_bin_path(); - if (!emul_bin_path) { - ERR("failed to get emulator path.\n"); - return NULL; - } - - sdk_info_path_len = strlen(emul_bin_path) + strlen(sdk_info) + 1; - sdk_info_file_path = g_malloc(sdk_info_path_len); - if (!sdk_info_file_path) { - ERR("failed to allocate sdk-data buffer.\n"); - return NULL; - } - - g_snprintf(sdk_info_file_path, sdk_info_path_len, "%s%s", - emul_bin_path, sdk_info); - INFO("sdk.info path: %s\n", sdk_info_file_path); - - sdk_info_fp = fopen(sdk_info_file_path, "r"); - g_free(sdk_info_file_path); - - if (sdk_info_fp) { - TRACE("Succeeded to open [sdk.info].\n"); - - char tmp[256] = { '\0', }; - char *tmpline = NULL; - while (fgets(tmp, sizeof(tmp), sdk_info_fp) != NULL) { - if ((tmpline = g_strstr_len(tmp, sizeof(tmp), sdk_data_var))) { - tmpline += strlen(sdk_data_var) + 1; // 1 for '=' - break; - } - } - - if (tmpline) { - if (tmpline[strlen(tmpline) - 1] == '\n') { - tmpline[strlen(tmpline) - 1] = '\0'; - } - if (tmpline[strlen(tmpline) - 1] == '\r') { - tmpline[strlen(tmpline) - 1] = '\0'; - } - - tizen_sdk_data_path = g_malloc(strlen(tmpline) + 1); - g_strlcpy(tizen_sdk_data_path, tmpline, strlen(tmpline) + 1); - - INFO("tizen-sdk-data path: %s\n", tizen_sdk_data_path); - - fclose(sdk_info_fp); - return tizen_sdk_data_path; - } - - fclose(sdk_info_fp); - } - - // legacy mode - ERR("Failed to open [sdk.info].\n"); - - return get_old_tizen_sdk_data_path(); -} - -static char *get_old_tizen_sdk_data_path(void) -{ - char *tizen_sdk_data_path = NULL; - - INFO("try to search tizen-sdk-data path in another way.\n"); - -#ifndef CONFIG_WIN32 - char tizen_sdk_data[] = "/tizen-sdk-data"; - int tizen_sdk_data_len = 0; - char *home_dir; - - home_dir = (char *)g_getenv("HOME"); - if (!home_dir) { - home_dir = (char *)g_get_home_dir(); - } - - tizen_sdk_data_len = strlen(home_dir) + sizeof(tizen_sdk_data) + 1; - tizen_sdk_data_path = g_malloc(tizen_sdk_data_len); - if (!tizen_sdk_data_path) { - ERR("failed to allocate memory.\n"); - return NULL; - } - g_strlcpy(tizen_sdk_data_path, home_dir, tizen_sdk_data_len); - g_strlcat(tizen_sdk_data_path, tizen_sdk_data, tizen_sdk_data_len); - -#else - char tizen_sdk_data[] = "\\tizen-sdk-data\\"; - gint tizen_sdk_data_len = 0; - HKEY hKey; - char strLocalAppDataPath[1024] = { 0 }; - DWORD dwBufLen = 1024; - - RegOpenKeyEx(HKEY_CURRENT_USER, - "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", - 0, KEY_QUERY_VALUE, &hKey); - - RegQueryValueEx(hKey, "Local AppData", NULL, - NULL, (LPBYTE)strLocalAppDataPath, &dwBufLen); - RegCloseKey(hKey); - - tizen_sdk_data_len = strlen(strLocalAppDataPath) + sizeof(tizen_sdk_data) + 1; - tizen_sdk_data_path = g_malloc(tizen_sdk_data_len); - if (!tizen_sdk_data_path) { - ERR("failed to allocate memory.\n"); - return NULL; - } - - g_strlcpy(tizen_sdk_data_path, strLocalAppDataPath, tizen_sdk_data_len); - g_strlcat(tizen_sdk_data_path, tizen_sdk_data, tizen_sdk_data_len); -#endif - - INFO("tizen-sdk-data path: %s\n", tizen_sdk_data_path); - return tizen_sdk_data_path; -} - diff --git a/tizen/src/ecs/ecs_msg_device.c b/tizen/src/ecs/ecs_msg_device.c new file mode 100644 index 0000000000..947cda6d0f --- /dev/null +++ b/tizen/src/ecs/ecs_msg_device.c @@ -0,0 +1,537 @@ +/* Emulator Control Server + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: + * Jinhyung choi + * MunKyu Im + * Daiyoung Kim + * YeongKyoon Lee + * + * 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 "qemu-common.h" +#include "qemu/option.h" +#include "qemu/config-file.h" + +#include "qmp-commands.h" +#include "net/slirp.h" +#include "fsdev/qemu-fsdev.h" +#include "monitor/qdev.h" +#include "mloop_event.h" +#include "hw/maru_virtio_sensor.h" +#include "hw/maru_virtio_nfc.h" +#include "skin/maruskin_operation.h" +#include "skin/maruskin_server.h" +#ifndef CONFIG_USE_SHM +#include "maru_finger.h" +#endif + +#include "emulator.h" +#include "emul_state.h" +#include "ecs.h" +#include "debug_ch.h" + +MULTI_DEBUG_CHANNEL(qemu, ecs); + +static void msgproc_device_ans(ECS_Client* ccli, const char* category, bool succeed, char* data) +{ + if (ccli == NULL) { + return; + } + int catlen = 0; + ECS__Master master = ECS__MASTER__INIT; + ECS__DeviceAns ans = ECS__DEVICE_ANS__INIT; + + TRACE("device ans - category : %s, succed : %d\n", category, succeed); + + catlen = strlen(category); + ans.category = (char*) g_malloc0(catlen + 1); + memcpy(ans.category, category, catlen); + + ans.errcode = !succeed; + + if (data != NULL) { + ans.length = strlen(data); + + if (ans.length > 0) { + ans.has_data = 1; + ans.data.data = g_malloc(ans.length); + ans.data.len = ans.length; + memcpy(ans.data.data, data, ans.length); + TRACE("data = %s, length = %hu\n", data, ans.length); + } + } + + master.type = ECS__MASTER__TYPE__DEVICE_ANS; + master.device_ans = &ans; + + pb_to_all_clients(&master); + + if (ans.category) + g_free(ans.category); +} + +extern char tizen_target_img_path[]; +void send_target_image_information(ECS_Client* ccli) { + ECS__Master master = ECS__MASTER__INIT; + ECS__DeviceAns ans = ECS__DEVICE_ANS__INIT; + int length = strlen(tizen_target_img_path); // ?? + + ans.category = (char*) g_malloc(10 + 1); + strncpy(ans.category, "info", 10); + + ans.errcode = 0; + ans.length = length; + ans.group = 1; + ans.action = 1; + + if (length > 0) + { + ans.has_data = 1; + + ans.data.data = g_malloc(length); + ans.data.len = length; + memcpy(ans.data.data, tizen_target_img_path, length); + + TRACE("data = %s, length = %hu\n", tizen_target_img_path, length); + } + + master.type = ECS__MASTER__TYPE__DEVICE_ANS; + master.device_ans = &ans; + + pb_to_single_client(&master, ccli); + + if (ans.data.len > 0) + { + g_free(ans.data.data); + } + + g_free(ans.category); +} + +static void msgproc_device_req_sensor(ECS_Client* ccli, ECS__DeviceReq* msg, char* cmd) +{ + char* data = NULL; + type_group group = (type_group) (msg->group & 0xff); + type_action action = (type_action) (msg->action & 0xff); + + if (msg->has_data && msg->data.len > 0) + { + data = (char*) g_malloc0(msg->data.len + 1); + memcpy(data, msg->data.data, msg->data.len); + } + + if (group == MSG_GROUP_STATUS) { + if (action == MSG_ACT_ACCEL) { + get_sensor_accel(); + } else if (action == MSG_ACT_GYRO) { + get_sensor_gyro(); + } else if (action == MSG_ACT_MAG) { + get_sensor_mag(); + } else if (action == MSG_ACT_LIGHT) { + get_sensor_light(); + } else if (action == MSG_ACT_PROXI) { + get_sensor_proxi(); + } + } else { + if (data != NULL) { + set_injector_data(data); + } else { + ERR("sensor set data is null\n"); + } + } + msgproc_device_ans(ccli, cmd, true, NULL); + + if (data) { + g_free(data); + } +} + +static void msgproc_device_req_network(ECS_Client* ccli, ECS__DeviceReq* msg) +{ + char* data = NULL; + + if (msg->has_data && msg->data.len > 0) + { + data = (char*) g_malloc0(msg->data.len + 1); + memcpy(data, msg->data.data, msg->data.len); + } + + if (data != NULL) { + TRACE(">>> Network msg: '%s'\n", data); + if(net_slirp_redir(data) < 0) { + ERR( "redirect [%s] fail\n", data); + } else { + TRACE("redirect [%s] success\n", data); + } + } else { + ERR("Network redirection data is null.\n"); + } + + if (data) { + g_free(data); + } +} + +static void msgproc_device_req_tgesture(ECS_Client* ccli, ECS__DeviceReq* msg) +{ + char* data = NULL; + type_group group = (type_group) (msg->group & 0xff); + + if (msg->has_data && msg->data.len > 0) + { + data = (char*) g_malloc0(msg->data.len + 1); + memcpy(data, msg->data.data, msg->data.len); + } + + /* release multi-touch */ +#ifndef CONFIG_USE_SHM + if (get_multi_touch_enable() != 0) { + clear_finger_slot(false); + } +#else + // TODO: +#endif + + if (data == NULL) { + ERR("touch gesture data is NULL\n"); + return; + } + + TRACE("%s\n", data); + + char token[] = "#"; + + if (group == 1) { /* HW key event */ + char *section = strtok(data, token); + int event_type = atoi(section); + + section = strtok(NULL, token); + int keycode = atoi(section); + + do_hw_key_event(event_type, keycode); + } else { /* touch event */ + char *section = strtok(data, token); + int event_type = atoi(section); + + section = strtok(NULL, token); + int xx = atoi(section); + + section = strtok(NULL, token); + int yy = atoi(section); + + section = strtok(NULL, token); + int zz = atoi(section); + + do_mouse_event(1/* LEFT */, event_type, 0, 0, xx, yy, zz); + } + + if (data) { + g_free(data); + } +} + +static void msgproc_device_req_input(ECS_Client* ccli, ECS__DeviceReq* msg, char* cmd) +{ + char* data = NULL; + type_group group = (type_group) (msg->group & 0xff); + type_action action = (type_action) (msg->action & 0xff); + + if (msg->has_data && msg->data.len > 0) + { + data = (char*) g_malloc0(msg->data.len + 1); + memcpy(data, msg->data.data, msg->data.len); + } + + // cli input + TRACE("receive input message [%s]\n", data); + + if (group == 0) { + TRACE("input keycode data : [%s]\n", data); + + char token[] = " "; + char *section = strtok(data, token); + int keycode = atoi(section); + if (action == 1) { + //action 1 press + do_hw_key_event(KEY_PRESSED, keycode); + + } else if (action == 2) { + //action 2 released + do_hw_key_event(KEY_RELEASED, keycode); + + } else { + ERR("unknown action : [%d]\n", (int)action); + } + } else if (group == 1) { + //spec out + TRACE("input category's group 1 is spec out\n"); + } else { + ERR("unknown group [%d]\n", (int)group); + } + msgproc_device_ans(ccli, cmd, true, NULL); + + if (data) { + g_free(data); + } +} + +static void msgproc_device_req_nfc(ECS_Client* ccli, ECS__DeviceReq* msg) +{ + char* data = NULL; + type_group group = (type_group) (msg->group & 0xff); + + if (msg->has_data && msg->data.len > 0) + { + data = (char*) g_malloc0(msg->data.len + 1); + memcpy(data, msg->data.data, msg->data.len); + } + + if (group == MSG_GROUP_STATUS) { + get_nfc_data(); + } else { + if (data != NULL) { + send_to_nfc(ccli->client_id, ccli->client_type, data, msg->data.len); + } else { + ERR("nfc data is null\n"); + } + } + + if (data) { + g_free(data); + } +} + +static bool is_hds_attached = false; + +#define FS_FILE_SYSTEM "virtfs" +#define FS_DRIVER "virtio-9p-pci" +#define FS_MOUNT_TAG "fileshare" +static bool do_virtfs_attach(const char * const file) +{ + QemuOpts *fsdev; + int ret; + QDict *qdict = qdict_new(); + + fsdev = qemu_opts_create(qemu_find_opts("fsdev"), + FS_MOUNT_TAG, 0, NULL); + if (!fsdev) { + fprintf(stderr, "duplicate fsdev id: %s\n", FS_MOUNT_TAG); + return false; + } + + qemu_opt_set(fsdev, "fsdriver", "local"); + qemu_opt_set(fsdev, "path", file); + qemu_opt_set(fsdev, "security_model", "none"); + + ret = qemu_fsdev_add(fsdev); + if (ret != 0) { + ERR("qemu_fsdev_add failed. with ret: %d\n", ret); + return false; + } + + qdict = qdict_new(); + qdict_put(qdict, "driver", qstring_from_str(FS_DRIVER)); + qdict_put(qdict, "fsdev", qstring_from_str(FS_MOUNT_TAG)); + qdict_put(qdict, "mount_tag", qstring_from_str(FS_MOUNT_TAG)); + + qdict_put(qdict, "id", qstring_from_str(FS_MOUNT_TAG)); + + if (do_device_add(default_mon, qdict, NULL)) { + QDECREF(qdict); + return false; + } + + QDECREF(qdict); + + is_hds_attached = true; + + return true; +} + +bool do_virtfs_detach(void) +{ + INFO("try to detach hds.\n"); + + QDict *qdict = qdict_new(); + qemu_fsdev_remove(FS_MOUNT_TAG); + + qdict_put(qdict, "id", qstring_from_str(FS_MOUNT_TAG)); + + if (qmp_marshal_input_device_del(cur_mon, qdict, NULL)) { + QDECREF(qdict); + return false; + } + + QDECREF(qdict); + + is_hds_attached = false; + + return true; +} + +static char hds_path[PATH_MAX]; + +static void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char * cmd) +{ + char* data = NULL; + type_group group = (type_group) (msg->group & 0xff); + type_action action = (type_action) (msg->action & 0xff); + + if (msg->has_data && msg->data.len > 0) + { + data = (char*) g_malloc0(msg->data.len + 1); + memcpy(data, msg->data.data, msg->data.len); + } + + INFO("hds group: %d, action : %d\n", group, action); + if (group == MSG_GROUP_STATUS) { + char hds_data_send[PATH_MAX + 3]; + if (is_hds_attached) { + sprintf(hds_data_send, "1, %s", hds_path); + } else { + sprintf(hds_data_send, "0, "); + } + make_send_device_ntf(cmd, group, 99, hds_data_send); + } else if (group == 100 && action == 1) { + INFO("try attach with is_hds_attached : %d\n", is_hds_attached); + if (data != NULL && !is_hds_attached) { + if (!do_virtfs_attach(data)) { + ERR("failed to attach"); + make_send_device_ntf(cmd, 100, 2, NULL); + } else { + memset(hds_path, 0, sizeof(hds_path)); + memcpy(hds_path, data, sizeof(hds_path) - 1); + INFO("send emuld to mount.\n"); + send_msg_to_guest(ccli, cmd, group, action, data, strlen(data)); + } + } else { + make_send_device_ntf(cmd, 100, 2, NULL); + } + } else if (group == 100 && action == 2) { + INFO("try detach with is_hds_attached : %d\n", is_hds_attached); + if (is_hds_attached) { + INFO("send emuld to umount.\n"); + send_msg_to_guest(ccli, cmd, group, action, NULL, 0); + } else { + INFO("hds is not attached. do not try detach it.\n"); + } + } else { + ERR("hds unknown command: group %d action %d\n", group, action); + } + + if (data) { + g_free(data); + } +} + +bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg) +{ + char cmd[10]; + memset(cmd, 0, 10); + strcpy(cmd, msg->category); + + TRACE(">> device_req: header = cmd = %s, length = %d, action=%d, group=%d\n", + cmd, msg->length, msg->action, msg->group); + + if (!strcmp(cmd, MSG_TYPE_SENSOR)) { + msgproc_device_req_sensor(ccli, msg, cmd); + } else if (!strcmp(cmd, "Network")) { + msgproc_device_req_network(ccli, msg); + } else if (!strcmp(cmd, "TGesture")) { + msgproc_device_req_tgesture(ccli, msg); + } else if (!strcmp(cmd, "info")) { + // check to emulator target image path + TRACE("receive info message %s\n", tizen_target_img_path); + send_target_image_information(ccli); + } else if (!strcmp(cmd, "hds")) { + msgproc_device_req_hds(ccli, msg, cmd); + } else if (!strcmp(cmd, "input")) { + msgproc_device_req_input(ccli, msg, cmd); + } else if (!strcmp(cmd, "vmname")) { + char* vmname = get_emul_vm_name(); + msgproc_device_ans(ccli, cmd, true, vmname); + } else if (!strcmp(cmd, "nfc")) { + msgproc_device_req_nfc(ccli, msg); + } else { + ERR("unknown cmd [%s]\n", cmd); + } + + return true; +} + +bool send_device_ntf(const char* data, const int len) +{ + type_length length = 0; + type_group group = 0; + type_action action = 0; + + const int catsize = 10; + char cat[catsize + 1]; + memset(cat, 0, catsize + 1); + + read_val_str(data, cat, catsize); + read_val_short(data + catsize, &length); + read_val_char(data + catsize + 2, &group); + read_val_char(data + catsize + 2 + 1, &action); + + const char* ijdata = (data + catsize + 2 + 1 + 1); + + TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group); + + ECS__Master master = ECS__MASTER__INIT; + ECS__DeviceNtf ntf = ECS__DEVICE_NTF__INIT; + + ntf.category = (char*) g_malloc(catsize + 1); + strncpy(ntf.category, cat, 10); + + + ntf.length = length; + ntf.group = group; + ntf.action = action; + + if (length > 0) + { + ntf.has_data = 1; + + ntf.data.data = g_malloc(length); + ntf.data.len = length; + memcpy(ntf.data.data, ijdata, length); + + TRACE("data = %s, length = %hu\n", ijdata, length); + } + + master.type = ECS__MASTER__TYPE__DEVICE_NTF; + master.device_ntf = &ntf; + + pb_to_all_clients(&master); + + if (ntf.data.data && ntf.data.len > 0) + { + g_free(ntf.data.data); + } + + if (ntf.category) + g_free(ntf.category); + + return true; +} + diff --git a/tizen/src/ecs/ecs_msg_injector.c b/tizen/src/ecs/ecs_msg_injector.c new file mode 100644 index 0000000000..4373a8f520 --- /dev/null +++ b/tizen/src/ecs/ecs_msg_injector.c @@ -0,0 +1,699 @@ +/* Emulator Control Server + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: + * Jinhyung choi + * MunKyu Im + * Daiyoung Kim + * YeongKyoon Lee + * + * 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 "qemu-common.h" + +#include "mloop_event.h" + +#include "hw/maru_virtio_vmodem.h" +#include "hw/maru_virtio_evdi.h" +#include "hw/maru_virtio_jack.h" +#include "hw/maru_virtio_power.h" + +#include "emulator.h" +#include "emul_state.h" +#include "ecs.h" +#include "debug_ch.h" + +MULTI_DEBUG_CHANNEL(qemu, ecs); + +extern QemuMutex mutex_guest_connection; +static int guest_connection = 0; + +extern QemuMutex mutex_location_data; +static char location_data[MAX_INJECTOR_REQ_DATA]; + +static bool is_sdcard_attached = false; + +static void msgproc_injector_ans(ECS_Client* ccli, const char* category, bool succeed) +{ + if (ccli == NULL) { + return; + } + int catlen = 0; + ECS__Master master = ECS__MASTER__INIT; + ECS__InjectorAns ans = ECS__INJECTOR_ANS__INIT; + + TRACE("injector ans - category : %s, succed : %d\n", category, succeed); + + catlen = strlen(category); + ans.category = (char*) g_malloc0(catlen + 1); + memcpy(ans.category, category, catlen); + + ans.errcode = !succeed; + master.type = ECS__MASTER__TYPE__INJECTOR_ANS; + master.injector_ans = &ans; + + pb_to_all_clients(&master); + + if (ans.category) + g_free(ans.category); +} + +static bool injector_send(ECS_Client* ccli, ECS__InjectorReq* msg, char* cmd) +{ + int sndlen = 15; // HEADER(CMD + LENGTH + GROUP + ACTION) + 1 + const char* msg_data; + char* sndbuf; + bool ret = false; + type_group group; + + group = (type_group) (msg->group & 0xff); + + if (msg->has_data && msg->data.data && msg->data.len > 0) + sndlen += msg->data.len; + + sndbuf = (char*) g_malloc0(sndlen); + if (!sndbuf) { + msgproc_injector_ans(ccli, cmd, false); + return false; + } + + memcpy(sndbuf, cmd, 10); + memcpy(sndbuf + 10, &msg->length, 2); + memcpy(sndbuf + 12, &msg->group, 1); + memcpy(sndbuf + 13, &msg->action, 1); + + if (msg->has_data && msg->data.data && msg->data.len > 0) { + msg_data = (const char*)msg->data.data; + memcpy(sndbuf + 14, msg_data, msg->data.len); + TRACE(">> print len = %zd, data\" %s\"\n", msg->data.len, msg_data); + } + + if(strcmp(cmd, "telephony") == 0) { + TRACE("telephony msg >>"); + ret = send_to_vmodem(route_ij, sndbuf, sndlen); + } else { + TRACE("evdi msg >> %s", cmd); + ret = send_to_evdi(route_ij, sndbuf, sndlen); + } + + g_free(sndbuf); + + if (group != MSG_GROUP_STATUS) { + msgproc_injector_ans(ccli, cmd, ret); + } + + if (!ret) { + return false; + } + + return true; +} + +static char* get_emulator_sdcard_path(void) +{ + char *emulator_sdcard_path = NULL; + char *tizen_sdk_data = NULL; + +#ifndef CONFIG_WIN32 + char emulator_sdcard[] = "/emulator/sdcard/"; +#else + char emulator_sdcard[] = "\\emulator\\sdcard\\"; +#endif + + TRACE("emulator_sdcard: %s, %zu\n", emulator_sdcard, sizeof(emulator_sdcard)); + + tizen_sdk_data = get_tizen_sdk_data_path(); + if (!tizen_sdk_data) { + ERR("failed to get tizen-sdk-data path.\n"); + return NULL; + } + + emulator_sdcard_path = + g_malloc(strlen(tizen_sdk_data) + sizeof(emulator_sdcard) + 1); + if (!emulator_sdcard_path) { + ERR("failed to allocate memory.\n"); + return NULL; + } + + g_snprintf(emulator_sdcard_path, strlen(tizen_sdk_data) + sizeof(emulator_sdcard), + "%s%s", tizen_sdk_data, emulator_sdcard); + + g_free(tizen_sdk_data); + + TRACE("sdcard path: %s\n", emulator_sdcard_path); + return emulator_sdcard_path; +} + +static char *get_old_tizen_sdk_data_path(void) +{ + char *tizen_sdk_data_path = NULL; + + INFO("try to search tizen-sdk-data path in another way.\n"); + +#ifndef CONFIG_WIN32 + char tizen_sdk_data[] = "/tizen-sdk-data"; + int tizen_sdk_data_len = 0; + char *home_dir; + + home_dir = (char *)g_getenv("HOME"); + if (!home_dir) { + home_dir = (char *)g_get_home_dir(); + } + + tizen_sdk_data_len = strlen(home_dir) + sizeof(tizen_sdk_data) + 1; + tizen_sdk_data_path = g_malloc(tizen_sdk_data_len); + if (!tizen_sdk_data_path) { + ERR("failed to allocate memory.\n"); + return NULL; + } + g_strlcpy(tizen_sdk_data_path, home_dir, tizen_sdk_data_len); + g_strlcat(tizen_sdk_data_path, tizen_sdk_data, tizen_sdk_data_len); + +#else + char tizen_sdk_data[] = "\\tizen-sdk-data\\"; + gint tizen_sdk_data_len = 0; + HKEY hKey; + char strLocalAppDataPath[1024] = { 0 }; + DWORD dwBufLen = 1024; + + RegOpenKeyEx(HKEY_CURRENT_USER, + "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", + 0, KEY_QUERY_VALUE, &hKey); + + RegQueryValueEx(hKey, "Local AppData", NULL, + NULL, (LPBYTE)strLocalAppDataPath, &dwBufLen); + RegCloseKey(hKey); + + tizen_sdk_data_len = strlen(strLocalAppDataPath) + sizeof(tizen_sdk_data) + 1; + tizen_sdk_data_path = g_malloc(tizen_sdk_data_len); + if (!tizen_sdk_data_path) { + ERR("failed to allocate memory.\n"); + return NULL; + } + + g_strlcpy(tizen_sdk_data_path, strLocalAppDataPath, tizen_sdk_data_len); + g_strlcat(tizen_sdk_data_path, tizen_sdk_data, tizen_sdk_data_len); +#endif + + INFO("tizen-sdk-data path: %s\n", tizen_sdk_data_path); + return tizen_sdk_data_path; +} + +/* + * get tizen-sdk-data path from sdk.info. + */ +char *get_tizen_sdk_data_path(void) +{ + char *emul_bin_path = NULL; + char *sdk_info_file_path = NULL; + char *tizen_sdk_data_path = NULL; +#ifndef CONFIG_WIN32 + const char *sdk_info = "../../../sdk.info"; +#else + const char *sdk_info = "..\\..\\..\\sdk.info"; +#endif + const char sdk_data_var[] = "TIZEN_SDK_DATA_PATH"; + + FILE *sdk_info_fp = NULL; + int sdk_info_path_len = 0; + + TRACE("%s\n", __func__); + + emul_bin_path = get_bin_path(); + if (!emul_bin_path) { + ERR("failed to get emulator path.\n"); + return NULL; + } + + sdk_info_path_len = strlen(emul_bin_path) + strlen(sdk_info) + 1; + sdk_info_file_path = g_malloc(sdk_info_path_len); + if (!sdk_info_file_path) { + ERR("failed to allocate sdk-data buffer.\n"); + return NULL; + } + + g_snprintf(sdk_info_file_path, sdk_info_path_len, "%s%s", + emul_bin_path, sdk_info); + INFO("sdk.info path: %s\n", sdk_info_file_path); + + sdk_info_fp = fopen(sdk_info_file_path, "r"); + g_free(sdk_info_file_path); + + if (sdk_info_fp) { + TRACE("Succeeded to open [sdk.info].\n"); + + char tmp[256] = { '\0', }; + char *tmpline = NULL; + while (fgets(tmp, sizeof(tmp), sdk_info_fp) != NULL) { + if ((tmpline = g_strstr_len(tmp, sizeof(tmp), sdk_data_var))) { + tmpline += strlen(sdk_data_var) + 1; // 1 for '=' + break; + } + } + + if (tmpline) { + if (tmpline[strlen(tmpline) - 1] == '\n') { + tmpline[strlen(tmpline) - 1] = '\0'; + } + if (tmpline[strlen(tmpline) - 1] == '\r') { + tmpline[strlen(tmpline) - 1] = '\0'; + } + + tizen_sdk_data_path = g_malloc(strlen(tmpline) + 1); + g_strlcpy(tizen_sdk_data_path, tmpline, strlen(tmpline) + 1); + + INFO("tizen-sdk-data path: %s\n", tizen_sdk_data_path); + + fclose(sdk_info_fp); + return tizen_sdk_data_path; + } + + fclose(sdk_info_fp); + } + + // legacy mode + ERR("Failed to open [sdk.info].\n"); + + return get_old_tizen_sdk_data_path(); +} + +static void send_gen_injector_ntf(const char* cmd, int cmdlen, int grp, int act, char* on) +{ + int msglen = 0, datalen = 0; + type_length length = 0; + type_group group = grp; + type_action action = act; + + if (cmd == NULL || cmdlen > 10) + return; + + if (on == NULL) { + msglen = 14; + } else { + datalen = strlen(on); + length = (unsigned short)datalen; + + msglen = datalen + 15; + } + + char* status_msg = (char*) malloc(msglen); + if(!status_msg) + return; + + memset(status_msg, 0, msglen); + + memcpy(status_msg, cmd, cmdlen); + memcpy(status_msg + 10, &length, sizeof(unsigned short)); + memcpy(status_msg + 12, &group, sizeof(unsigned char)); + memcpy(status_msg + 13, &action, sizeof(unsigned char)); + + if (on != NULL) { + memcpy(status_msg + 14, on, datalen); + } + + send_injector_ntf(status_msg, msglen); + + if (status_msg) + free(status_msg); +} + +static bool handle_sdcard(char* dataBuf, size_t dataLen) +{ + int err_no = 0; + char ret = 0; + INFO("handle_sdcard() data: %s\n", dataBuf); + if (dataBuf != NULL) { + ret = dataBuf[0]; + + if (ret == '0' ) { + /* umount sdcard */ + //mloop_evcmd_usbdisk(NULL); + char sdcard_img_path[256]; + char* sdcard_path = NULL; + + sdcard_path = get_emulator_sdcard_path(); + if (sdcard_path) { + g_strlcpy(sdcard_img_path, sdcard_path, + sizeof(sdcard_img_path)); + + /* emulator_sdcard_img_path + sdcard img name */ + char* sdcard_img_name = dataBuf+2; + if (dataLen > 3 && sdcard_img_name != NULL) { + char* pLinechange = strchr(sdcard_img_name, '\n'); + if(pLinechange != NULL){ + sdcard_img_name = g_strndup(sdcard_img_name, pLinechange - sdcard_img_name); + } + + g_strlcat(sdcard_img_path, sdcard_img_name, sizeof(sdcard_img_path)); + INFO("sdcard path: [%s]\n", sdcard_img_path); + + /*if using strndup than free string*/ + if (pLinechange != NULL && sdcard_img_name!= NULL) { + free(sdcard_img_name); + } + } + g_free(sdcard_path); + + } + err_no = remove_sdcard_lock_os(sdcard_img_path); + INFO("umount err_no: %d\n", err_no); + if (errno == 0 && is_sdcard_attached) { + mloop_evcmd_sdcard(NULL); + is_sdcard_attached = false; + } else { + ERR("failed to umount: %s\n", sdcard_img_path); + send_gen_injector_ntf(MSG_TYPE_SDCARD, 6, 11, err_no, NULL); + return err_no; + } + } + else if (ret == '1') { + /* mount sdcard */ + char sdcard_img_path[256]; + char* sdcard_path = NULL; + + sdcard_path = get_emulator_sdcard_path(); + if (sdcard_path) { + g_strlcpy(sdcard_img_path, sdcard_path, + sizeof(sdcard_img_path)); + + /* emulator_sdcard_img_path + sdcard img name */ + char* sdcard_img_name = dataBuf+2; + if (dataLen > 3 && sdcard_img_name != NULL) { + char* pLinechange = strchr(sdcard_img_name, '\n'); + if(pLinechange != NULL){ + sdcard_img_name = g_strndup(sdcard_img_name, pLinechange - sdcard_img_name); + } + + g_strlcat(sdcard_img_path, sdcard_img_name, sizeof(sdcard_img_path)); + TRACE("sdcard path: [%s]\n", sdcard_img_path); + + //mloop_evcmd_usbdisk(sdcard_img_path); + if (!is_sdcard_attached && make_sdcard_lock_os(sdcard_img_path)) { + mloop_evcmd_sdcard(sdcard_img_path); + is_sdcard_attached = true; + } else { + send_gen_injector_ntf(MSG_TYPE_SDCARD, 6, 11, 5, NULL); + return ERR_LCK; + } + /*if using strndup than free string*/ + if (pLinechange != NULL && sdcard_img_name!= NULL) { + free(sdcard_img_name); + } + + } + + g_free(sdcard_path); + } else { + ERR("failed to get sdcard path!!\n"); + } + } else if (ret == '2') { + TRACE("sdcard status 2 bypass\n" ); + } else { + ERR("!!! unknown command : %c\n", ret); + } + + } else { + ERR("!!! unknown data : %c\n", ret); + } + return ERR_SUCCESS; +} + +static bool injector_req_sdcard(ECS_Client* ccli, ECS__InjectorReq* msg, char *cmd) +{ + if (msg->has_data) { + TRACE("msg(%zu) : %s\n", msg->data.len, msg->data.data); + if (handle_sdcard((char*) msg->data.data, msg->data.len) > 0) { + return false; + } + } else { + ERR("has no msg\n"); + } + + return injector_send(ccli, msg, cmd); +} + +static void send_status_injector_ntf(const char* cmd, int cmdlen, int act, char* on) +{ + int msglen = 0, datalen = 0; + type_length length = 0; + type_group group = MSG_GROUP_STATUS; + type_action action = act; + + if (cmd == NULL || cmdlen > 10) + return; + + if (on == NULL) { + msglen = 14; + } else { + datalen = strlen(on); + length = (unsigned short)datalen; + + msglen = datalen + 15; + } + + char* status_msg = (char*) malloc(msglen); + if(!status_msg) + return; + + memset(status_msg, 0, msglen); + + memcpy(status_msg, cmd, cmdlen); + memcpy(status_msg + 10, &length, sizeof(unsigned short)); + memcpy(status_msg + 12, &group, sizeof(unsigned char)); + memcpy(status_msg + 13, &action, sizeof(unsigned char)); + + if (on != NULL) { + memcpy(status_msg + 14, on, datalen); + } + + send_injector_ntf(status_msg, msglen); + + if (status_msg) + free(status_msg); +} + +static bool injector_req_sensor(ECS_Client* ccli, ECS__InjectorReq* msg, char *cmd) +{ + char data[MAX_INJECTOR_REQ_DATA]; + type_group group; + type_action action; + + memset(data, 0, MAX_INJECTOR_REQ_DATA); + group = (type_group) (msg->group & 0xff); + action = (type_action) (msg->action & 0xff); + + if (group == MSG_GROUP_STATUS) { + switch (action) { + case MSG_ACT_BATTERY_LEVEL: + sprintf(data, "%d", get_power_capacity()); + break; + case MSG_ACT_BATTERY_CHARGER: + sprintf(data, "%d", get_jack_charger()); + break; + case MSG_ACT_USB: + sprintf(data, "%d", get_jack_usb()); + break; + case MSG_ACT_EARJACK: + sprintf(data, "%d", get_jack_earjack()); + break; + case MSG_ACT_LOCATION: + qemu_mutex_lock(&mutex_location_data); + sprintf(data, "%s", location_data); + qemu_mutex_unlock(&mutex_location_data); + break; + default: + return injector_send(ccli, msg, cmd); + } + TRACE("status : %s\n", data); + send_status_injector_ntf(MSG_TYPE_SENSOR, 6, action, data); + return true; + } else if (msg->data.data && msg->data.len > 0) { + set_injector_data((char*) msg->data.data); + return injector_send(ccli, msg, cmd); + } + + return false; +} + +static bool injector_req_guest(void) +{ + int value = 0; + qemu_mutex_lock(&mutex_guest_connection); + value = guest_connection; + qemu_mutex_unlock(&mutex_guest_connection); + send_status_injector_ntf(MSG_TYPE_GUEST, 5, value, NULL); + return true; +} + +static bool injector_req_location(ECS_Client* ccli, ECS__InjectorReq* msg, char *cmd) +{ + if (msg->data.data != NULL && msg->data.len > 0) { + qemu_mutex_lock(&mutex_location_data); + snprintf(location_data, msg->data.len + 1, "%s", (char*)msg->data.data); + qemu_mutex_unlock(&mutex_location_data); + return injector_send(ccli, msg, cmd); + } + + return false; +} + +bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg) +{ + char cmd[11]; + bool ret = false; + + strncpy(cmd, msg->category, sizeof(cmd) - 1); + + if (!strcmp(cmd, MSG_TYPE_SDCARD)) { + ret = injector_req_sdcard(ccli, msg, cmd); + } else if (!strcmp(cmd, MSG_TYPE_SENSOR)) { + ret = injector_req_sensor(ccli, msg, cmd); + } else if (!strcmp(cmd, MSG_TYPE_GUEST)) { + ret = injector_req_guest(); + } else if (!strcmp(cmd, MSG_TYPE_LOCATION)) { + ret = injector_req_location(ccli, msg, cmd); + } else { + ret = injector_send(ccli, msg, cmd); + } + + return ret; +} + +void ecs_suspend_lock_state(int state) +{ + int catlen; + + ECS__InjectorReq msg = ECS__INJECTOR_REQ__INIT; + const char* category = "suspend"; + + catlen = strlen(category); + msg.category = (char*) g_malloc0(catlen + 1); + memcpy(msg.category, category, catlen); + + msg.group = 5; + msg.action = state; + + msgproc_injector_req(NULL, &msg); +} + +#define MSG_GROUP_HDS 100 +static bool injector_req_handle(char* cat, type_action action) +{ + /*SD CARD msg process*/ + if (!strcmp(cat, MSG_TYPE_SDCARD)) { + return false; + } else if (!strcmp(cat, "suspend")) { + ecs_suspend_lock_state(ecs_get_suspend_state()); + return true; + } else if (!strcmp(cat, MSG_TYPE_GUEST)) { + INFO("emuld connection is %d\n", action); + qemu_mutex_lock(&mutex_guest_connection); + guest_connection = action; + qemu_mutex_unlock(&mutex_guest_connection); + return false; + } else if (!strcmp(cat, "hds")) { + INFO("hds status is %d\n", action); + switch (action) { + case 1: + make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL); + break; + case 2: + make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL); + break; + case 3: + if (!do_virtfs_detach()) { + make_send_device_ntf(cat, MSG_GROUP_HDS, 5, NULL); + } else { + make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL); + } + break; + case 4: + make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL); + break; + default: + ERR("unknown action: %s.\n", action); + break; + } + return true; + } else { + ERR("unknown command: %s.\n", cat); + } + + return false; +} + +bool send_injector_ntf(const char* data, const int len) +{ + type_length length = 0; + type_group group = 0; + type_action action = 0; + + const int catsize = 10; + char cat[catsize + 1]; + memset(cat, 0, catsize + 1); + + read_val_str(data, cat, catsize); + read_val_short(data + catsize, &length); + read_val_char(data + catsize + 2, &group); + read_val_char(data + catsize + 2 + 1, &action); + + if (injector_req_handle(cat, action)) { + return true; + } + + const char* ijdata = (data + catsize + 2 + 1 + 1); + + TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group); + + ECS__Master master = ECS__MASTER__INIT; + ECS__InjectorNtf ntf = ECS__INJECTOR_NTF__INIT; + + ntf.category = (char*) g_malloc(catsize + 1); + strncpy(ntf.category, cat, 10); + + ntf.length = length; + ntf.group = group; + ntf.action = action; + + if (length > 0) + { + ntf.has_data = 1; + + ntf.data.data = g_malloc(length); + ntf.data.len = length; + memcpy(ntf.data.data, ijdata, length); + } + + master.type = ECS__MASTER__TYPE__INJECTOR_NTF; + master.injector_ntf = &ntf; + + pb_to_all_clients(&master); + + if (ntf.data.len > 0) + { + g_free(ntf.data.data); + } + + g_free(ntf.category); + + return true; +} + diff --git a/tizen/src/ecs/ecs_nfc.c b/tizen/src/ecs/ecs_nfc.c new file mode 100644 index 0000000000..7e5ee5ff8c --- /dev/null +++ b/tizen/src/ecs/ecs_nfc.c @@ -0,0 +1,116 @@ +/* Emulator Control Server + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: + * Jinhyung choi + * MunKyu Im + * Daiyoung Kim + * YeongKyoon Lee + * + * 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 "qemu-common.h" + +#include "hw/maru_virtio_nfc.h" + +#include "ecs.h" + +#include "debug_ch.h" + +MULTI_DEBUG_CHANNEL(qemu, ecs); + +bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg) +{ + int datalen = msg->data.len; + void* data = (void*)g_malloc(datalen); + if(!data) { + ERR("g_malloc failed!\n"); + return false; + } + + memset(data, 0, datalen); + memcpy(data, msg->data.data, msg->data.len); + + if (msg->has_data && msg->data.len > 0) + { + TRACE("recv from nfc injector: %s, %z\n", msg->has_data, msg->data.len); + print_binary(data, datalen); + } + + send_to_nfc(ccli->client_id, ccli->client_type, data, msg->data.len); + g_free(data); + return true; +} + +bool send_nfc_ntf(struct nfc_msg_info* msg) +{ + const int catsize = 10; + char cat[catsize + 1]; + ECS_Client *clii; + memset(cat, 0, catsize + 1); + + print_binary((char*)msg->buf, msg->use); + TRACE("id: %02x, type: %02x, use: %d\n", msg->client_id, msg->client_type, msg->use); + clii = find_client(msg->client_id, msg->client_type); + if (clii) { + if(clii->client_type == TYPE_SIMUL_NFC) { + strncpy(cat, MSG_TYPE_NFC, 3); + } else if (clii->client_type == TYPE_ECP) { + strncpy(cat, MSG_TYPE_SIMUL_NFC, 9); + }else { + ERR("cannot find type! : %d\n", clii->client_type); + } + TRACE("header category = %s\n", cat); + } + else { + ERR("cannot find client!\n"); + } + + 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(NFC_MAX_BUF_SIZE); + ntf.data.len = NFC_MAX_BUF_SIZE; + memcpy(ntf.data.data, msg->buf, NFC_MAX_BUF_SIZE); + + TRACE("send to nfc injector: \n"); + master.type = ECS__MASTER__TYPE__NFC_NTF; + master.nfc_ntf = &ntf; + + pb_to_all_clients(&master); + + if (ntf.data.data && ntf.data.len > 0) + { + g_free(ntf.data.data); + } + + if (ntf.category) + g_free(ntf.category); + + return true; +} + + diff --git a/tizen/src/ecs/ecs_tethering.c b/tizen/src/ecs/ecs_tethering.c index 5180e40eb8..a3b6b56fb9 100644 --- a/tizen/src/ecs/ecs_tethering.c +++ b/tizen/src/ecs/ecs_tethering.c @@ -243,7 +243,7 @@ static bool send_tethering_ntf(const char *data) master.type = ECS__MASTER__TYPE__TETHERING_NTF; master.tethering_ntf = &ntf; - send_to_ecp(&master); + pb_to_all_clients(&master); if (ntf.data.data && ntf.data.len > 0) { g_free(ntf.data.data); diff --git a/tizen/src/skin/maruskin_server.c b/tizen/src/skin/maruskin_server.c index 56fd9b84b5..76371825ec 100644 --- a/tizen/src/skin/maruskin_server.c +++ b/tizen/src/skin/maruskin_server.c @@ -1075,7 +1075,7 @@ static void* run_skin_server(void* args) do_host_kbd_enable(true); } - send_host_keyboard_ntf((on == 0) ? 0 : 1); + //send_host_keyboard_ntf((on == 0) ? 0 : 1); break; } case RECV_INTERPOLATION_STATE: {