4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
8 * Cherepanov Vitaliy <v.cherepanov@samsung.com>
9 * Nikita Kalyazin <n.kalyazin@samsung.com>
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
24 * - Samsung RnD Institute Russia
35 #include <sys/types.h>
36 #include <sys/socket.h>
38 #include <sys/sysinfo.h>
40 #include "da_protocol.h"
42 #include "da_protocol_check.h"
45 #include "transfer_thread.h"
47 #include "ioctl_commands.h"
56 static pthread_mutex_t stop_all_mutex = PTHREAD_MUTEX_INITIALIZER;
58 static void inline free_msg(struct msg_t *msg)
63 struct prof_session_t prof_session;
65 static void print_conf(struct conf_t *conf);
68 #define check_and_return(check) if ( ID == check ) {return dstr(check);}
70 char *msg_ID_str(enum HostMessageT ID)
72 check_and_return(NMSG_KEEP_ALIVE);
73 check_and_return(NMSG_START);
74 check_and_return(NMSG_STOP);
75 check_and_return(NMSG_CONFIG);
76 check_and_return(NMSG_BINARY_INFO);
77 check_and_return(NMSG_GET_TARGET_INFO);
78 check_and_return(NMSG_SWAP_INST_ADD);
79 check_and_return(NMSG_SWAP_INST_REMOVE);
80 check_and_return(NMSG_GET_SCREENSHOT);
82 check_and_return(NMSG_KEEP_ALIVE_ACK);
83 check_and_return(NMSG_START_ACK);
84 check_and_return(NMSG_STOP_ACK);
85 check_and_return(NMSG_CONFIG_ACK);
86 check_and_return(NMSG_BINARY_INFO_ACK);
87 check_and_return(NMSG_SWAP_INST_ACK);
88 check_and_return(NMSG_GET_TARGET_INFO_ACK);
89 check_and_return(NMSG_SWAP_INST_ADD_ACK);
90 check_and_return(NMSG_SWAP_INST_REMOVE_ACK);
92 check_and_return(NMSG_PROCESS_INFO);
93 check_and_return(NMSG_TERMINATE);
94 check_and_return(NMSG_ERROR);
95 check_and_return(NMSG_SAMPLE);
96 check_and_return(NMSG_SYSTEM);
97 check_and_return(NMSG_IMAGE);
98 check_and_return(NMSG_RECORD);
99 check_and_return(NMSG_FUNCTION_ENTRY);
100 check_and_return(NMSG_FUNCTION_EXIT);
101 check_and_return(NMSG_CONTEXT_SWITCH_ENTRY);
102 check_and_return(NMSG_CONTEXT_SWITCH_EXIT);
107 static char *msgErrStr(enum ErrorCode err)
112 case ERR_LOCKFILE_CREATE_FAILED:
113 return "lock file create failed";
114 case ERR_ALREADY_RUNNING:
115 return "already running";
116 case ERR_INITIALIZE_SYSTEM_INFO_FAILED:
117 return "initialize system info failed";
118 case ERR_HOST_SERVER_SOCKET_CREATE_FAILED:
119 return "host server socket create failed";
120 case ERR_TARGET_SERVER_SOCKET_CREATE_FAILED:
121 return "target server socket create failed";
122 case ERR_SIGNAL_MASK_SETTING_FAILED: //TODO del (old parametr)
123 return "ERR SIGNAL MASK SETTING FAILED";
124 case ERR_WRONG_MESSAGE_FORMAT:
125 return "wrong message format";
126 case ERR_WRONG_MESSAGE_TYPE:
127 return "wrong message type";
128 case ERR_WRONG_MESSAGE_DATA:
129 return "wrong message data";
130 case ERR_CANNOT_START_PROFILING:
131 return "cannot start profiling";
132 case ERR_SERV_SOCK_CREATE:
133 return "server socket creation failed (written in /tmp/da.port file)";
134 case ERR_SERV_SOCK_BIND:
135 return "server socket bind failed (written in /tmp/da.port file)";
136 case ERR_SERV_SOCK_LISTEN:
137 return "server socket listen failed (written in /tmp/da.port file)";
140 return "unknown error";
142 return "unknown error";
146 #define print_feature(f,in,to,delim) \
148 sprintf(to, dstr(f) delim ); \
149 to+=strlen( dstr(f) delim ); \
151 #define print_feature_0(f) print_feature(f, feature0, to, ", \n\t")
152 static void feature_code_str(uint64_t feature0, uint64_t feature1, char *to)
154 print_feature_0(FL_CPU);
155 print_feature_0(FL_MEMORY);
156 print_feature_0(FL_FUNCTION_PROFILING);
157 print_feature_0(FL_MEMORY_ALLOC_PROBING);
158 print_feature_0(FL_FILE_API_PROBING);
159 print_feature_0(FL_THREAD_API_PROBING);
160 print_feature_0(FL_OSP_UI_API_PROBING);
161 print_feature_0(FL_SCREENSHOT);
162 print_feature_0(FL_USER_EVENT);
163 print_feature_0(FL_RECORDING);
164 print_feature_0(FL_SYSTCALL_FILE);
165 print_feature_0(FL_SYSTCALL_IPC);
166 print_feature_0(FL_SYSTCALL_PROCESS);
167 print_feature_0(FL_SYSTCALL_SIGNAL);
168 print_feature_0(FL_SYSTCALL_NETWORK);
169 print_feature_0(FL_SYSTCALL_DESC);
170 print_feature_0(FL_CONTEXT_SWITCH);
171 print_feature_0(FL_NETWORK_API_PROBING);
172 print_feature_0(FL_OPENGL_API_PROBING);
173 print_feature_0(FL_MEMORY_ALLOC_ALWAYS_PROBING);
174 print_feature_0(FL_FILE_API_ALWAYS_PROBING);
175 print_feature_0(FL_THREAD_API_ALWAYS_PROBING);
176 print_feature_0(FL_OSP_UI_API_ALWAYS_PROBING);
177 print_feature_0(FL_NETWORK_API_ALWAYS_PROBING);
178 print_feature_0(FL_OPENGL_API_ALWAYS_PROBING);
183 static inline uint32_t get_avail_msg_size(struct msg_buf_t *msg)
185 return (uint32_t)(msg->end - msg->cur_pos);
188 static inline uint32_t get_msg_cur_size(struct msg_buf_t *msg)
190 return (uint32_t) (msg->cur_pos - msg->payload);
193 int parse_string(struct msg_buf_t *msg, char **str)
195 parse_deb("size = %d\n", get_avail_msg_size(msg));
196 int len = strlen(msg->cur_pos) + 1;
198 if (get_avail_msg_size(msg) < len)
201 *str = strdup(msg->cur_pos);
202 parse_deb("<%s>\n", *str);
207 static const char* parse_string_inplace(struct msg_buf_t *msg)
209 const char *str = msg->cur_pos;
210 int avail_size = get_avail_msg_size(msg);
211 int len = strnlen(str, avail_size);
213 /* Malformed string or exhaused buffer. Strlen is at least one byte
214 * less, that availiable space. If it is not, string is lacking
215 * terminating null char.
218 if (len == avail_size)
221 msg->cur_pos += len + 1;
225 int parse_string_no_alloc(struct msg_buf_t *msg, char *str)
227 parse_deb("size = %d\n", get_avail_msg_size(msg));
228 int len = strlen(msg->cur_pos) + 1;
230 if (get_avail_msg_size(msg) < len)
233 memcpy(str, msg->cur_pos, len);
234 parse_deb("<%s>\n", str);
239 int parse_int8(struct msg_buf_t *msg, uint8_t *val)
241 parse_deb("size = %d\n", get_avail_msg_size(msg));
242 if (get_avail_msg_size(msg) < sizeof(*val))
244 *val = *(uint8_t *)msg->cur_pos;
245 msg->cur_pos += sizeof(uint8_t);
247 parse_deb("<%d><0x%08X>\n", *val, *val);
253 int parse_int32(struct msg_buf_t *msg, uint32_t *val)
255 parse_deb("size = %d\n", get_avail_msg_size(msg));
256 if (get_avail_msg_size(msg) < sizeof(*val))
258 *val = *(uint32_t *)msg->cur_pos;
259 msg->cur_pos += sizeof(uint32_t);
262 parse_deb("<%d><0x%08X>\n", *val, *val);
267 int parse_int64(struct msg_buf_t *msg, uint64_t *val)
269 parse_deb("size = %d\n", get_avail_msg_size(msg));
270 if (get_avail_msg_size(msg) < sizeof(*val))
273 *val = *(uint64_t *)msg->cur_pos;
275 parse_deb("<%llu><0x%016llX>\n", *val, *val);
276 msg->cur_pos += sizeof(uint64_t);
280 static int parse_conf(struct msg_buf_t *msg, struct conf_t *conf)
283 parse_deb("parse_conf\n");
284 if (!parse_int64(msg, &conf->use_features0)) {
285 LOGE("use features0 error\n");
289 if (!parse_int64(msg, &conf->use_features1)) {
290 LOGE("use features1 parsing error\n");
293 //Check features value
294 if (!check_conf_features(conf->use_features0, conf->use_features1)) {
295 LOGE("check features fail\n");
299 if (!parse_int32( msg, &conf->system_trace_period) ||
300 !check_conf_systrace_period(conf->system_trace_period))
302 LOGE("system trace period error\n");
306 if (!parse_int32( msg, &conf->data_message_period) ||
307 !check_conf_datamsg_period(conf->data_message_period))
309 LOGE("data message period error\n");
316 //REPLAY EVENTS PARSE
317 static int parse_timeval(struct msg_buf_t *msg, struct timeval *tv)
323 if (!parse_int32(msg, (uint32_t *)&tv->tv_sec)) {
324 LOGE("sec parsing error\n");
328 if (!parse_int32(msg, &nsec)) {
329 LOGE("usec parsing error\n");
332 tv->tv_usec = nsec / 1000;
337 static int parse_replay_event(struct msg_buf_t *msg,
338 struct replay_event_t *re)
341 if (!parse_timeval(msg, &re->ev.time)) {
342 LOGE("time parsing error\n");
346 if (!parse_int32(msg, &re->id)) {
347 LOGE("id parsing error\n");
351 if (!parse_int32(msg, (uint32_t *)&re->ev.type)) {
352 LOGE("type parsing error\n");
356 if (!parse_int32(msg, (uint32_t *)&re->ev.code)) {
357 LOGE("code parsing error\n");
361 if (!parse_int32(msg, (uint32_t *)&re->ev.value)) {
362 LOGE("value parsing error\n");
369 void reset_replay_event_seq(struct replay_event_seq_t *res)
372 res->tv = (struct timeval){0, 0};
373 if (res->event_num != 0)
378 int parse_replay_event_seq(struct msg_buf_t *msg,
379 struct replay_event_seq_t *res)
382 parse_deb("REPLAY\n");
383 if (!parse_int32(msg, &res->enabled)) {
384 LOGE("enabled parsing error\n");
388 if(res->enabled == 0) {
389 parse_deb("disable\n");
393 parse_deb("time main\n");
394 if (!parse_timeval(msg, &res->tv)) {
395 LOGE("time parsing error\n");
399 parse_deb("count\n");
400 if (!parse_int32(msg, &res->event_num)) {
401 LOGE("event num parsing error\n");
404 parse_deb("events num=%d\n", res->event_num);
406 res->events = (struct replay_event_t *)malloc(res->event_num *
407 sizeof(*res->events));
409 LOGE("events alloc error\n");
413 for (i = 0; i < res->event_num; i++) {
414 parse_deb("sub_rep\n");
415 if (!parse_replay_event(msg, &res->events[i])) {
416 LOGE("event #%d parsing error\n", i + 1);
426 //*REPLAY EVENT PARSE
428 static int parse_msg_config(struct msg_buf_t *msg_payload,
431 if (!parse_conf(msg_payload, conf)) {
432 LOGE("conf parsing error\n");
440 static void init_parse_control(struct msg_buf_t *buf, struct msg_t *msg)
442 buf->payload = msg->payload;
444 buf->end = msg->payload + msg->len;
445 buf->cur_pos = msg->payload;
448 static void reset_target_info(struct target_info_t *target_info)
453 static void running_status_on(struct prof_session_t *prof_session)
455 prof_session->running_status = 1;
458 static void running_status_off(struct prof_session_t *prof_session)
460 prof_session->running_status = 0;
463 int check_running_status(const struct prof_session_t *prof_session)
465 return prof_session->running_status;
468 static void reset_app_inst(struct user_space_inst_t *us_inst)
470 free_data_list((struct data_list_t **)&us_inst->app_inst_list);
471 us_inst->app_num = 0;
472 us_inst->app_inst_list = NULL;
475 void reset_system_info(struct system_info_t *sys_info)
477 if (sys_info->thread_load)
478 free(sys_info->thread_load);
479 if (sys_info->process_load)
480 free(sys_info->process_load);
481 if (sys_info->cpu_frequency)
482 free(sys_info->cpu_frequency);
483 if (sys_info->cpu_load)
484 free(sys_info->cpu_load);
485 memset(sys_info, 0, sizeof(*sys_info));
488 void init_prof_session(struct prof_session_t *prof_session)
490 memset(prof_session, 0, sizeof(*prof_session));
493 static size_t str_array_getsize(const char **strings, size_t len)
496 * Calculate about of memory to place array
497 * of \0 delimited strings
501 for (index = 0; index != len; ++index)
502 size += strlen(strings[index]) + 1;
507 static struct msg_t *gen_target_info_reply(struct target_info_t *target_info)
511 uint32_t ret_id = ERR_NO;
513 msg = malloc(sizeof(*msg) +
515 sizeof(*target_info) -
516 sizeof(target_info->network_type) +
517 strlen(target_info->network_type) + 1 +
518 sizeof(uint32_t) + /* devices count */
519 str_array_getsize(supported_devices_strings,
520 supported_devices_count));
522 LOGE("Cannot alloc target info msg\n");
527 msg->id = NMSG_GET_TARGET_INFO_ACK;
530 pack_int32(p, ret_id);
531 pack_int64(p, target_info->sys_mem_size);
532 pack_int64(p, target_info->storage_size);
533 pack_int32(p, target_info->bluetooth_supp);
534 pack_int32(p, target_info->gps_supp);
535 pack_int32(p, target_info->wifi_supp);
536 pack_int32(p, target_info->camera_count);
537 pack_str(p, target_info->network_type);
538 pack_int32(p, target_info->max_brightness);
539 pack_int32(p, target_info->cpu_core_count);
540 pack_int32(p, supported_devices_count);
541 p = pack_str_array(p, supported_devices_strings,
542 supported_devices_count);
544 msg->len = p - msg->payload;
549 static int send_reply(struct msg_t *msg)
551 printBuf((char *)msg, msg->len + sizeof (*msg));
552 if (send(manager.host.control_socket,
553 msg, MSG_CMD_HDR_LEN + msg->len, MSG_NOSIGNAL) == -1) {
554 LOGE("Cannot send reply : %s\n", strerror(errno));
561 static void write_msg_error(const char *err_str)
563 struct msg_data_t *err_msg = gen_message_error(err_str);
564 write_to_buf(err_msg);
565 free_msg_data(err_msg);
568 static enum HostMessageT get_ack_msg_id(const enum HostMessageT id)
571 case NMSG_KEEP_ALIVE:
572 return NMSG_KEEP_ALIVE_ACK;
574 return NMSG_START_ACK;
576 return NMSG_STOP_ACK;
578 return NMSG_CONFIG_ACK;
579 case NMSG_BINARY_INFO:
580 return NMSG_BINARY_INFO_ACK;
581 case NMSG_GET_TARGET_INFO:
582 return NMSG_GET_TARGET_INFO_ACK;
583 case NMSG_SWAP_INST_ADD:
584 return NMSG_SWAP_INST_ADD_ACK;
585 case NMSG_SWAP_INST_REMOVE:
586 return NMSG_SWAP_INST_REMOVE_ACK;
588 LOGE("Fatal: unknown message ID [0x%X]\n", id);
593 int sendACKToHost(enum HostMessageT resp, enum ErrorCode err_code,
594 char *payload, int payload_size)
596 if (manager.host.control_socket != -1) {
598 uint32_t err = err_code;
599 int loglen = sizeof(*msg) - sizeof(msg->payload) +
600 sizeof(err) + //return ID
602 msg = malloc(loglen);
603 char *p = msg->payload;
605 resp = get_ack_msg_id(resp);
610 msg->len = payload_size + sizeof(err);
614 memcpy(p, payload, payload_size);
616 LOGI("ACK (%s) errcode<%s> payload=0x%08X; size=%d\n", msg_ID_str(resp),
617 msgErrStr(err_code), (int)payload, payload_size);
618 printBuf((char *)msg, loglen);
620 if (send(manager.host.control_socket, msg,
621 loglen, MSG_NOSIGNAL) == -1) {
622 LOGE("Cannot send reply: %s\n", strerror(errno));
632 static struct msg_t *gen_stop_msg(void)
634 struct msg_t *res = malloc(sizeof(*res));
635 memset(res, 0, sizeof(*res));
642 enum ErrorCode stop_all_no_lock(void)
644 enum ErrorCode error_code = ERR_NO;
647 // stop all only if it has not been called yet
648 if (check_running_status(&prof_session)) {
649 msg = gen_stop_msg();
654 LOGE("cannot generate stop message\n");
655 error_code = ERR_UNKNOWN;
658 if (ioctl_send_msg(msg) != 0) {
659 LOGE("ioctl send failed\n");
660 error_code = ERR_UNKNOWN;
667 // we reset only app inst no lib no confing reset
668 reset_app_inst(&prof_session.user_space_inst);
670 running_status_off(&prof_session);
672 LOGI("already stopped\n");
675 LOGI("finished: ret = %d\n", error_code);
679 int stop_all_in_process(void)
681 return (pthread_mutex_trylock(&stop_all_mutex) != 0);
684 void stop_all_done(void)
686 pthread_mutex_unlock(&stop_all_mutex);
689 enum ErrorCode stop_all(void)
691 enum ErrorCode error_code = ERR_NO;
693 pthread_mutex_lock(&stop_all_mutex);
694 error_code = stop_all_no_lock();
695 pthread_mutex_unlock(&stop_all_mutex);
703 md5_byte_t digest[16];
706 static void binary_ack_free(struct binary_ack *ba)
713 static size_t binary_ack_size(const struct binary_ack *ba)
715 /* MD5 is 16 bytes, so 16*2 hex digits */
716 return sizeof(uint32_t) + strlen(ba->binpath) + 1
720 static size_t binary_ack_pack(char *s, const struct binary_ack *ba)
722 unsigned int len = strlen(ba->binpath);
724 *(uint32_t *) s = ba->type;
725 s += sizeof(uint32_t);
728 memmove(s, ba->binpath, len);
733 for (i = 0; i!= 16; ++i) {
734 sprintf(s, "%02x", ba->digest[i]);
738 return sizeof(uint32_t) + len + 1 + 2*16 + 1;
741 static void get_file_md5sum(md5_byte_t digest[16], const char *filename)
743 md5_byte_t buffer[1024];
745 md5_state_t md5_state;
746 int fd = open(filename, O_RDONLY);
748 md5_init(&md5_state);
750 while ((size = read(fd, buffer, sizeof(buffer))) > 0)
751 md5_append(&md5_state, buffer, size);
753 md5_finish(&md5_state, digest);
757 static const char* basename(const char *filename)
759 const char *p = strrchr(filename, '/');
760 return p ? p + 1 : NULL;
762 static struct binary_ack* binary_ack_alloc(const char *filename)
764 struct binary_ack *ba = malloc(sizeof(*ba));
765 char builddir[PATH_MAX];
766 char binpath[PATH_MAX];
768 ba->type = get_binary_type(filename);
770 get_build_dir(builddir, filename);
772 snprintf(binpath, sizeof(binpath), "%s/%s",
773 builddir, basename(filename) ?: "");
775 ba->binpath = strdup(binpath);
777 get_file_md5sum(ba->digest, filename);
782 static int process_msg_binary_info(struct msg_buf_t *msg)
784 uint32_t i, bincount;
786 if (!parse_int32(msg, &bincount)) {
787 LOGE("MSG_BINARY_INFO error: No binaries count\n");
791 struct binary_ack *acks[bincount];
792 size_t total_size = 0;
793 for (i = 0; i != bincount; ++i) {
794 const char *str = parse_string_inplace(msg);
796 LOGE("MSG_BINARY_INFO error: No enough binaries\n");
799 acks[i] = binary_ack_alloc(str);
800 total_size += binary_ack_size(acks[i]);
802 typedef uint32_t return_id;
803 typedef uint32_t binary_ack_count;
804 struct msg_t *msg_reply = malloc(sizeof(struct msg_t)
806 + sizeof(binary_ack_count)
808 char *p = msg_reply->payload;
810 msg_reply->id = NMSG_BINARY_INFO_ACK;
811 msg_reply->len = total_size + sizeof(return_id)
812 + sizeof(binary_ack_count);
814 pack_int32(p, ERR_NO);
815 pack_int32(p, bincount);
817 for (i = 0; i != bincount; ++i) {
818 p += binary_ack_pack(p, acks[i]);
819 binary_ack_free(acks[i]);
822 int err = send_reply(msg_reply);
827 static void get_serialized_time(uint32_t dst[2])
830 gettimeofday(&tv, NULL);
832 dst[1] = tv.tv_usec * 1000;
835 static int process_msg_start(struct msg_buf_t *msg_control)
837 enum ErrorCode err_code = ERR_CANNOT_START_PROFILING;
838 struct msg_t *msg_reply;
839 uint32_t serialized_time[2];
841 if (check_running_status(&prof_session) == 1) {
842 LOGW("Profiling has already been started\n");
846 if (!check_conf(&prof_session.conf)) {
847 LOGE("wrong profile config\n");
851 if (msg_start(msg_control, &prof_session.user_space_inst,
852 &msg_reply, &err_code) != 0) {
853 LOGE("parse error\n");
857 if (prepare_profiling() != 0) {
858 LOGE("failed to prepare profiling\n");
862 if (start_transfer() != 0) {
863 LOGE("Cannot start transfer\n");
867 if (ioctl_send_msg(msg_reply) != 0) {
868 LOGE("cannot send message to device\n");
872 running_status_on(&prof_session);
874 if (start_profiling() < 0) {
875 LOGE("cannot start profiling\n");
876 if (stop_all() != ERR_NO) {
877 LOGE("Stop failed\n");
878 write_msg_error("Stop failed");
885 get_serialized_time(serialized_time);
886 sendACKToHost(NMSG_START, err_code, (void *)&serialized_time,
887 sizeof(serialized_time));
889 return -(err_code != ERR_NO);
892 static int process_msg_get_screenshot(struct msg_buf_t *msg_control)
897 msg_target_t sendlog;
898 enum ErrorCode err_code = ERR_UNKNOWN;
900 // send config message to target process
901 sendlog.type = MSG_CAPTURE_SCREEN;
903 log_len = sizeof(sendlog.type) + sizeof(sendlog.length) + sendlog.length;
905 for (target_index = 0; target_index < MAX_TARGET_COUNT; target_index++) {
906 sock = manager.target[target_index].socket;
908 if (send(sock, &sendlog, log_len, MSG_NOSIGNAL) == -1) {
909 LOGE("fail to send data to target index(%d)\n",
918 return -(err_code != ERR_NO);
921 int host_message_handler(struct msg_t *msg)
923 struct target_info_t target_info;
924 struct msg_t *msg_reply = NULL;
925 struct msg_buf_t msg_control;
927 enum ErrorCode error_code = ERR_NO;
930 msg_target_t sendlog;
932 LOGI("MY HANDLE %s (%X)\n", msg_ID_str(msg->id), msg->id);
933 init_parse_control(&msg_control, msg);
936 case NMSG_KEEP_ALIVE:
937 sendACKToHost(msg->id, ERR_NO, 0, 0);
940 return process_msg_start(&msg_control);
942 sendACKToHost(msg->id, ERR_NO, 0, 0);
943 if (stop_all() != ERR_NO) {
944 LOGE("Stop failed\n");
945 write_msg_error("Stop failed");
950 if (!parse_msg_config(&msg_control, &conf)) {
951 LOGE("config parsing error\n");
952 sendACKToHost(msg->id, ERR_WRONG_MESSAGE_FORMAT, 0, 0);
955 if (reconfigure(conf) != 0) {
956 LOGE("Cannot change configuration\n");
960 if (ioctl_send_msg(msg) != 0) {
961 LOGE("ioctl send error\n");
962 sendACKToHost(msg->id, ERR_UNKNOWN, 0, 0);
966 sendACKToHost(msg->id, ERR_NO, 0, 0);
967 // send config message to target process
968 sendlog.type = MSG_OPTION;
969 sendlog.length = sprintf(sendlog.data, "%llu",
970 (unsigned long long) prof_session.conf.use_features0);
971 for (target_index = 0; target_index < MAX_TARGET_COUNT; target_index++)
973 if(manager.target[target_index].socket != -1)
975 if (0 > send(manager.target[target_index].socket, &sendlog,
976 sizeof(sendlog.type) + sizeof(sendlog.length) + sendlog.length,
978 LOGE("fail to send data to target index(%d)\n", target_index);
982 case NMSG_BINARY_INFO:
983 return process_msg_binary_info(&msg_control);
984 case NMSG_SWAP_INST_ADD:
985 if (msg_swap_inst_add(&msg_control, &prof_session.user_space_inst,
986 &msg_reply, &error_code) != 0) {
987 LOGE("swap inst add\n");
990 if (msg_reply != NULL)
991 if (ioctl_send_msg(msg_reply) != 0) {
992 error_code = ERR_UNKNOWN;
993 LOGE("ioclt send error\n");
997 case NMSG_SWAP_INST_REMOVE:
998 if (msg_swap_inst_remove(&msg_control, &prof_session.user_space_inst,
999 &msg_reply, &error_code) != 0) {
1000 LOGE("swap inst remove\n");
1001 error_code = ERR_UNKNOWN;
1004 if (msg_reply != NULL) {
1005 if (ioctl_send_msg(msg_reply) != 0)
1006 error_code = ERR_UNKNOWN;
1008 error_code = ERR_UNKNOWN;
1011 case NMSG_GET_TARGET_INFO:
1012 fill_target_info(&target_info);
1013 msg_reply = gen_target_info_reply(&target_info);
1015 LOGE("cannot generate reply message\n");
1016 sendACKToHost(msg->id, ERR_UNKNOWN, 0, 0);
1019 if (send_reply(msg_reply) != 0) {
1020 LOGE("Cannot send reply\n");
1023 reset_target_info(&target_info);
1025 case NMSG_GET_SCREENSHOT:
1026 return process_msg_get_screenshot(&msg_control);
1028 LOGE("unknown message %d <0x%08X>\n", msg->id, msg->id);
1034 sendACKToHost(msg->id, error_code, 0, 0);
1035 if (msg_reply != NULL)
1037 return (error_code == ERR_NO);
1042 static void print_conf(struct conf_t *conf)
1045 memset(&buf[0], 0, 1024);
1046 feature_code_str(conf->use_features0, conf->use_features1, buf);
1048 LOGI("\tuse_features = 0x%016LX : 0x%016LX \n(\t%s)\n",
1049 conf->use_features0, conf->use_features1, buf);
1051 "\tsystem_trace_period = %d ms\n"
1052 "\tdata message period = %d ms\n",
1053 conf->system_trace_period,
1054 conf->data_message_period
1058 void print_replay_event(struct replay_event_t *ev, uint32_t num, char *tab)
1060 LOGW("%s\t#%04d:time=0x%08X %08X, "
1066 (unsigned int)ev->ev.time.tv_sec,//timeval
1067 (unsigned int)ev->ev.time.tv_usec,//timeval