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"
57 static pthread_mutex_t stop_all_mutex = PTHREAD_MUTEX_INITIALIZER;
59 static void inline free_msg(struct msg_t *msg)
64 struct prof_session_t prof_session;
66 static void print_conf(struct conf_t *conf);
69 #define check_and_return(check) if ( ID == check ) {return dstr(check);}
71 char *msg_ID_str(enum HostMessageT ID)
73 check_and_return(NMSG_KEEP_ALIVE);
74 check_and_return(NMSG_START);
75 check_and_return(NMSG_STOP);
76 check_and_return(NMSG_CONFIG);
77 check_and_return(NMSG_BINARY_INFO);
78 check_and_return(NMSG_GET_TARGET_INFO);
79 check_and_return(NMSG_SWAP_INST_ADD);
80 check_and_return(NMSG_SWAP_INST_REMOVE);
81 check_and_return(NMSG_GET_SCREENSHOT);
83 check_and_return(NMSG_KEEP_ALIVE_ACK);
84 check_and_return(NMSG_START_ACK);
85 check_and_return(NMSG_STOP_ACK);
86 check_and_return(NMSG_CONFIG_ACK);
87 check_and_return(NMSG_BINARY_INFO_ACK);
88 check_and_return(NMSG_SWAP_INST_ACK);
89 check_and_return(NMSG_GET_TARGET_INFO_ACK);
90 check_and_return(NMSG_SWAP_INST_ADD_ACK);
91 check_and_return(NMSG_SWAP_INST_REMOVE_ACK);
93 check_and_return(NMSG_PROCESS_INFO);
94 check_and_return(NMSG_TERMINATE);
95 check_and_return(NMSG_ERROR);
96 check_and_return(NMSG_SAMPLE);
97 check_and_return(NMSG_SYSTEM);
98 check_and_return(NMSG_IMAGE);
99 check_and_return(NMSG_RECORD);
100 check_and_return(NMSG_FUNCTION_ENTRY);
101 check_and_return(NMSG_FUNCTION_EXIT);
102 check_and_return(NMSG_CONTEXT_SWITCH_ENTRY);
103 check_and_return(NMSG_CONTEXT_SWITCH_EXIT);
108 static char *msgErrStr(enum ErrorCode err)
113 case ERR_LOCKFILE_CREATE_FAILED:
114 return "lock file create failed";
115 case ERR_ALREADY_RUNNING:
116 return "already running";
117 case ERR_INITIALIZE_SYSTEM_INFO_FAILED:
118 return "initialize system info failed";
119 case ERR_HOST_SERVER_SOCKET_CREATE_FAILED:
120 return "host server socket create failed";
121 case ERR_TARGET_SERVER_SOCKET_CREATE_FAILED:
122 return "target server socket create failed";
123 case ERR_SIGNAL_MASK_SETTING_FAILED: //TODO del (old parametr)
124 return "ERR SIGNAL MASK SETTING FAILED";
125 case ERR_WRONG_MESSAGE_FORMAT:
126 return "wrong message format";
127 case ERR_WRONG_MESSAGE_TYPE:
128 return "wrong message type";
129 case ERR_WRONG_MESSAGE_DATA:
130 return "wrong message data";
131 case ERR_CANNOT_START_PROFILING:
132 return "cannot start profiling";
133 case ERR_SERV_SOCK_CREATE:
134 return "server socket creation failed (written in /tmp/da.port file)";
135 case ERR_SERV_SOCK_BIND:
136 return "server socket bind failed (written in /tmp/da.port file)";
137 case ERR_SERV_SOCK_LISTEN:
138 return "server socket listen failed (written in /tmp/da.port file)";
141 return "unknown error";
143 return "unknown error";
147 #define print_feature(f,in,to,delim) \
149 sprintf(to, dstr(f) delim ); \
150 to+=strlen( dstr(f) delim ); \
152 #define print_feature_0(f) print_feature(f, feature0, to, ", \n\t")
153 static void feature_code_str(uint64_t feature0, uint64_t feature1, char *to)
155 print_feature_0(FL_CPU);
156 print_feature_0(FL_MEMORY);
157 print_feature_0(FL_FUNCTION_PROFILING);
158 print_feature_0(FL_MEMORY_ALLOC_PROBING);
159 print_feature_0(FL_FILE_API_PROBING);
160 print_feature_0(FL_THREAD_API_PROBING);
161 print_feature_0(FL_OSP_UI_API_PROBING);
162 print_feature_0(FL_SCREENSHOT);
163 print_feature_0(FL_USER_EVENT);
164 print_feature_0(FL_RECORDING);
165 print_feature_0(FL_SYSTCALL_FILE);
166 print_feature_0(FL_SYSTCALL_IPC);
167 print_feature_0(FL_SYSTCALL_PROCESS);
168 print_feature_0(FL_SYSTCALL_SIGNAL);
169 print_feature_0(FL_SYSTCALL_NETWORK);
170 print_feature_0(FL_SYSTCALL_DESC);
171 print_feature_0(FL_CONTEXT_SWITCH);
172 print_feature_0(FL_NETWORK_API_PROBING);
173 print_feature_0(FL_OPENGL_API_PROBING);
174 print_feature_0(FL_MEMORY_ALLOC_ALWAYS_PROBING);
175 print_feature_0(FL_FILE_API_ALWAYS_PROBING);
176 print_feature_0(FL_THREAD_API_ALWAYS_PROBING);
177 print_feature_0(FL_OSP_UI_API_ALWAYS_PROBING);
178 print_feature_0(FL_NETWORK_API_ALWAYS_PROBING);
179 print_feature_0(FL_OPENGL_API_ALWAYS_PROBING);
184 static inline uint32_t get_avail_msg_size(struct msg_buf_t *msg)
186 return (uint32_t)(msg->end - msg->cur_pos);
189 static inline uint32_t get_msg_cur_size(struct msg_buf_t *msg)
191 return (uint32_t) (msg->cur_pos - msg->payload);
194 int parse_string(struct msg_buf_t *msg, char **str)
196 parse_deb("size = %d\n", get_avail_msg_size(msg));
197 int len = strlen(msg->cur_pos) + 1;
199 if (get_avail_msg_size(msg) < len)
202 *str = strdup(msg->cur_pos);
203 parse_deb("<%s>\n", *str);
208 static const char* parse_string_inplace(struct msg_buf_t *msg)
210 const char *str = msg->cur_pos;
211 int avail_size = get_avail_msg_size(msg);
212 int len = strnlen(str, avail_size);
214 /* Malformed string or exhaused buffer. Strlen is at least one byte
215 * less, that availiable space. If it is not, string is lacking
216 * terminating null char.
219 if (len == avail_size)
222 msg->cur_pos += len + 1;
226 int parse_string_no_alloc(struct msg_buf_t *msg, char *str)
228 parse_deb("size = %d\n", get_avail_msg_size(msg));
229 int len = strlen(msg->cur_pos) + 1;
231 if (get_avail_msg_size(msg) < len)
234 memcpy(str, msg->cur_pos, len);
235 parse_deb("<%s>\n", str);
240 int parse_int8(struct msg_buf_t *msg, uint8_t *val)
242 parse_deb("size = %d\n", get_avail_msg_size(msg));
243 if (get_avail_msg_size(msg) < sizeof(*val))
245 *val = *(uint8_t *)msg->cur_pos;
246 msg->cur_pos += sizeof(uint8_t);
248 parse_deb("<%d><0x%08X>\n", *val, *val);
254 int parse_int32(struct msg_buf_t *msg, uint32_t *val)
256 parse_deb("size = %d\n", get_avail_msg_size(msg));
257 if (get_avail_msg_size(msg) < sizeof(*val))
259 *val = *(uint32_t *)msg->cur_pos;
260 msg->cur_pos += sizeof(uint32_t);
263 parse_deb("<%d><0x%08X>\n", *val, *val);
268 int parse_int64(struct msg_buf_t *msg, uint64_t *val)
270 parse_deb("size = %d\n", get_avail_msg_size(msg));
271 if (get_avail_msg_size(msg) < sizeof(*val))
274 *val = *(uint64_t *)msg->cur_pos;
276 parse_deb("<%llu><0x%016llX>\n", *val, *val);
277 msg->cur_pos += sizeof(uint64_t);
281 static int parse_conf(struct msg_buf_t *msg, struct conf_t *conf)
284 parse_deb("parse_conf\n");
285 if (!parse_int64(msg, &conf->use_features0)) {
286 LOGE("use features0 error\n");
290 if (!parse_int64(msg, &conf->use_features1)) {
291 LOGE("use features1 parsing error\n");
294 //Check features value
295 if (!check_conf_features(conf->use_features0, conf->use_features1)) {
296 LOGE("check features fail\n");
300 if (!parse_int32( msg, &conf->system_trace_period) ||
301 !check_conf_systrace_period(conf->system_trace_period))
303 LOGE("system trace period error\n");
307 if (!parse_int32( msg, &conf->data_message_period) ||
308 !check_conf_datamsg_period(conf->data_message_period))
310 LOGE("data message period error\n");
317 //REPLAY EVENTS PARSE
318 static int parse_timeval(struct msg_buf_t *msg, struct timeval *tv)
324 if (!parse_int32(msg, (uint32_t *)&tv->tv_sec)) {
325 LOGE("sec parsing error\n");
329 if (!parse_int32(msg, &nsec)) {
330 LOGE("usec parsing error\n");
333 tv->tv_usec = nsec / 1000;
338 static int parse_replay_event(struct msg_buf_t *msg,
339 struct replay_event_t *re)
342 if (!parse_timeval(msg, &re->ev.time)) {
343 LOGE("time parsing error\n");
347 if (!parse_int32(msg, &re->id)) {
348 LOGE("id parsing error\n");
352 if (!parse_int32(msg, (uint32_t *)&re->ev.type)) {
353 LOGE("type parsing error\n");
357 if (!parse_int32(msg, (uint32_t *)&re->ev.code)) {
358 LOGE("code parsing error\n");
362 if (!parse_int32(msg, (uint32_t *)&re->ev.value)) {
363 LOGE("value parsing error\n");
370 void reset_replay_event_seq(struct replay_event_seq_t *res)
373 res->tv = (struct timeval){0, 0};
374 if (res->event_num != 0)
379 int parse_replay_event_seq(struct msg_buf_t *msg,
380 struct replay_event_seq_t *res)
383 parse_deb("REPLAY\n");
384 if (!parse_int32(msg, &res->enabled)) {
385 LOGE("enabled parsing error\n");
389 if(res->enabled == 0) {
390 parse_deb("disable\n");
394 parse_deb("time main\n");
395 if (!parse_timeval(msg, &res->tv)) {
396 LOGE("time parsing error\n");
400 parse_deb("count\n");
401 if (!parse_int32(msg, &res->event_num)) {
402 LOGE("event num parsing error\n");
405 parse_deb("events num=%d\n", res->event_num);
407 res->events = (struct replay_event_t *)malloc(res->event_num *
408 sizeof(*res->events));
410 LOGE("events alloc error\n");
414 for (i = 0; i < res->event_num; i++) {
415 parse_deb("sub_rep\n");
416 if (!parse_replay_event(msg, &res->events[i])) {
417 LOGE("event #%d parsing error\n", i + 1);
427 //*REPLAY EVENT PARSE
429 static int parse_msg_config(struct msg_buf_t *msg_payload,
432 if (!parse_conf(msg_payload, conf)) {
433 LOGE("conf parsing error\n");
441 static void init_parse_control(struct msg_buf_t *buf, struct msg_t *msg)
443 buf->payload = msg->payload;
445 buf->end = msg->payload + msg->len;
446 buf->cur_pos = msg->payload;
449 static void reset_target_info(struct target_info_t *target_info)
454 static void running_status_on(struct prof_session_t *prof_session)
456 prof_session->running_status = 1;
459 static void running_status_off(struct prof_session_t *prof_session)
461 prof_session->running_status = 0;
464 int check_running_status(const struct prof_session_t *prof_session)
466 return prof_session->running_status;
469 static void reset_app_inst(struct user_space_inst_t *us_inst)
471 free_data_list((struct data_list_t **)&us_inst->app_inst_list);
472 us_inst->app_num = 0;
473 us_inst->app_inst_list = NULL;
476 void reset_system_info(struct system_info_t *sys_info)
478 if (sys_info->thread_load)
479 free(sys_info->thread_load);
480 if (sys_info->process_load)
481 free(sys_info->process_load);
482 if (sys_info->cpu_frequency)
483 free(sys_info->cpu_frequency);
484 if (sys_info->cpu_load)
485 free(sys_info->cpu_load);
486 memset(sys_info, 0, sizeof(*sys_info));
489 void init_prof_session(struct prof_session_t *prof_session)
491 memset(prof_session, 0, sizeof(*prof_session));
494 static size_t str_array_getsize(const char **strings, size_t len)
497 * Calculate about of memory to place array
498 * of \0 delimited strings
502 for (index = 0; index != len; ++index)
503 size += strlen(strings[index]) + 1;
508 static struct msg_t *gen_target_info_reply(struct target_info_t *target_info)
512 uint32_t ret_id = ERR_NO;
514 msg = malloc(sizeof(*msg) +
516 sizeof(*target_info) -
517 sizeof(target_info->network_type) +
518 strlen(target_info->network_type) + 1 +
519 sizeof(uint32_t) + /* devices count */
520 str_array_getsize(supported_devices_strings,
521 supported_devices_count));
523 LOGE("Cannot alloc target info msg\n");
528 msg->id = NMSG_GET_TARGET_INFO_ACK;
531 pack_int32(p, ret_id);
532 pack_int64(p, target_info->sys_mem_size);
533 pack_int64(p, target_info->storage_size);
534 pack_int32(p, target_info->bluetooth_supp);
535 pack_int32(p, target_info->gps_supp);
536 pack_int32(p, target_info->wifi_supp);
537 pack_int32(p, target_info->camera_count);
538 pack_str(p, target_info->network_type);
539 pack_int32(p, target_info->max_brightness);
540 pack_int32(p, target_info->cpu_core_count);
541 pack_int32(p, supported_devices_count);
542 p = pack_str_array(p, supported_devices_strings,
543 supported_devices_count);
545 msg->len = p - msg->payload;
550 static int send_reply(struct msg_t *msg)
552 printBuf((char *)msg, msg->len + sizeof (*msg));
553 if (send(manager.host.control_socket,
554 msg, MSG_CMD_HDR_LEN + msg->len, MSG_NOSIGNAL) == -1) {
555 LOGE("Cannot send reply : %s\n", strerror(errno));
562 static void write_msg_error(const char *err_str)
564 struct msg_data_t *err_msg = gen_message_error(err_str);
565 write_to_buf(err_msg);
566 free_msg_data(err_msg);
569 static enum HostMessageT get_ack_msg_id(const enum HostMessageT id)
572 case NMSG_KEEP_ALIVE:
573 return NMSG_KEEP_ALIVE_ACK;
575 return NMSG_START_ACK;
577 return NMSG_STOP_ACK;
579 return NMSG_CONFIG_ACK;
580 case NMSG_BINARY_INFO:
581 return NMSG_BINARY_INFO_ACK;
582 case NMSG_GET_TARGET_INFO:
583 return NMSG_GET_TARGET_INFO_ACK;
584 case NMSG_SWAP_INST_ADD:
585 return NMSG_SWAP_INST_ADD_ACK;
586 case NMSG_SWAP_INST_REMOVE:
587 return NMSG_SWAP_INST_REMOVE_ACK;
589 LOGE("Fatal: unknown message ID [0x%X]\n", id);
594 int sendACKToHost(enum HostMessageT resp, enum ErrorCode err_code,
595 char *payload, int payload_size)
597 if (manager.host.control_socket != -1) {
599 uint32_t err = err_code;
600 int loglen = sizeof(*msg) - sizeof(msg->payload) +
601 sizeof(err) + //return ID
603 msg = malloc(loglen);
604 char *p = msg->payload;
606 resp = get_ack_msg_id(resp);
611 msg->len = payload_size + sizeof(err);
615 memcpy(p, payload, payload_size);
617 LOGI("ACK (%s) errcode<%s> payload=0x%08X; size=%d\n", msg_ID_str(resp),
618 msgErrStr(err_code), (int)payload, payload_size);
619 printBuf((char *)msg, loglen);
621 if (send(manager.host.control_socket, msg,
622 loglen, MSG_NOSIGNAL) == -1) {
623 LOGE("Cannot send reply: %s\n", strerror(errno));
633 static struct msg_t *gen_stop_msg(void)
635 struct msg_t *res = malloc(sizeof(*res));
636 memset(res, 0, sizeof(*res));
643 enum ErrorCode stop_all_no_lock(void)
645 enum ErrorCode error_code = ERR_NO;
648 // stop all only if it has not been called yet
649 if (check_running_status(&prof_session)) {
650 msg = gen_stop_msg();
651 if(thaw_subgroup()) {
652 LOGE("Cannot thaw subgroup\n");
653 error_code = ERR_UNKNOWN;
660 LOGE("cannot generate stop message\n");
661 error_code = ERR_UNKNOWN;
664 if (ioctl_send_msg(msg) != 0) {
665 LOGE("ioctl send failed\n");
666 error_code = ERR_UNKNOWN;
673 // we reset only app inst no lib no confing reset
674 reset_app_inst(&prof_session.user_space_inst);
676 running_status_off(&prof_session);
678 LOGI("already stopped\n");
681 LOGI("finished: ret = %d\n", error_code);
685 int stop_all_in_process(void)
687 return (pthread_mutex_trylock(&stop_all_mutex) != 0);
690 void stop_all_done(void)
692 pthread_mutex_unlock(&stop_all_mutex);
695 enum ErrorCode stop_all(void)
697 enum ErrorCode error_code = ERR_NO;
699 pthread_mutex_lock(&stop_all_mutex);
700 error_code = stop_all_no_lock();
701 pthread_mutex_unlock(&stop_all_mutex);
709 md5_byte_t digest[16];
712 static void binary_ack_free(struct binary_ack *ba)
719 static size_t binary_ack_size(const struct binary_ack *ba)
721 /* MD5 is 16 bytes, so 16*2 hex digits */
722 return sizeof(uint32_t) + strlen(ba->binpath) + 1
726 static size_t binary_ack_pack(char *s, const struct binary_ack *ba)
728 unsigned int len = strlen(ba->binpath);
730 *(uint32_t *) s = ba->type;
731 s += sizeof(uint32_t);
734 memmove(s, ba->binpath, len);
739 for (i = 0; i!= 16; ++i) {
740 sprintf(s, "%02x", ba->digest[i]);
744 return sizeof(uint32_t) + len + 1 + 2*16 + 1;
747 static void get_file_md5sum(md5_byte_t digest[16], const char *filename)
749 md5_byte_t buffer[1024];
751 md5_state_t md5_state;
752 int fd = open(filename, O_RDONLY);
754 md5_init(&md5_state);
756 while ((size = read(fd, buffer, sizeof(buffer))) > 0)
757 md5_append(&md5_state, buffer, size);
759 md5_finish(&md5_state, digest);
763 static const char* basename(const char *filename)
765 const char *p = strrchr(filename, '/');
766 return p ? p + 1 : NULL;
768 static struct binary_ack* binary_ack_alloc(const char *filename)
770 struct binary_ack *ba = malloc(sizeof(*ba));
771 char builddir[PATH_MAX];
772 char binpath[PATH_MAX];
774 ba->type = get_binary_type(filename);
776 get_build_dir(builddir, filename);
778 snprintf(binpath, sizeof(binpath), "%s/%s",
779 builddir, basename(filename) ?: "");
781 ba->binpath = strdup(binpath);
783 get_file_md5sum(ba->digest, filename);
788 static int process_msg_binary_info(struct msg_buf_t *msg)
790 uint32_t i, bincount;
792 if (!parse_int32(msg, &bincount)) {
793 LOGE("MSG_BINARY_INFO error: No binaries count\n");
797 struct binary_ack *acks[bincount];
798 size_t total_size = 0;
799 for (i = 0; i != bincount; ++i) {
800 const char *str = parse_string_inplace(msg);
802 LOGE("MSG_BINARY_INFO error: No enough binaries\n");
805 acks[i] = binary_ack_alloc(str);
806 total_size += binary_ack_size(acks[i]);
808 typedef uint32_t return_id;
809 typedef uint32_t binary_ack_count;
810 struct msg_t *msg_reply = malloc(sizeof(struct msg_t)
812 + sizeof(binary_ack_count)
814 char *p = msg_reply->payload;
816 msg_reply->id = NMSG_BINARY_INFO_ACK;
817 msg_reply->len = total_size + sizeof(return_id)
818 + sizeof(binary_ack_count);
820 pack_int32(p, ERR_NO);
821 pack_int32(p, bincount);
823 for (i = 0; i != bincount; ++i) {
824 p += binary_ack_pack(p, acks[i]);
825 binary_ack_free(acks[i]);
828 int err = send_reply(msg_reply);
833 static void get_serialized_time(uint32_t dst[2])
836 gettimeofday(&tv, NULL);
838 dst[1] = tv.tv_usec * 1000;
841 static int process_msg_start(struct msg_buf_t *msg_control)
843 enum ErrorCode err_code = ERR_CANNOT_START_PROFILING;
844 struct msg_t *msg_reply;
845 uint32_t serialized_time[2];
847 if (check_running_status(&prof_session) == 1) {
848 LOGW("Profiling has already been started\n");
852 if (!check_conf(&prof_session.conf)) {
853 LOGE("wrong profile config\n");
857 if (msg_start(msg_control, &prof_session.user_space_inst,
858 &msg_reply, &err_code) != 0) {
859 LOGE("parse error\n");
863 if (prepare_profiling() != 0) {
864 LOGE("failed to prepare profiling\n");
868 if (start_transfer() != 0) {
869 LOGE("Cannot start transfer\n");
873 if (ioctl_send_msg(msg_reply) != 0) {
874 LOGE("cannot send message to device\n");
878 running_status_on(&prof_session);
880 if (start_profiling() < 0) {
881 LOGE("cannot start profiling\n");
882 if (stop_all() != ERR_NO) {
883 LOGE("Stop failed\n");
884 write_msg_error("Stop failed");
891 get_serialized_time(serialized_time);
892 sendACKToHost(NMSG_START, err_code, (void *)&serialized_time,
893 sizeof(serialized_time));
895 return -(err_code != ERR_NO);
898 static int process_msg_get_screenshot(struct msg_buf_t *msg_control)
903 msg_target_t sendlog;
904 enum ErrorCode err_code = ERR_UNKNOWN;
906 // send config message to target process
907 sendlog.type = MSG_CAPTURE_SCREEN;
909 log_len = sizeof(sendlog.type) + sizeof(sendlog.length) + sendlog.length;
911 for (target_index = 0; target_index < MAX_TARGET_COUNT; target_index++) {
912 sock = manager.target[target_index].socket;
914 if (send(sock, &sendlog, log_len, MSG_NOSIGNAL) == -1) {
915 LOGE("fail to send data to target index(%d)\n",
924 return -(err_code != ERR_NO);
927 int host_message_handler(struct msg_t *msg)
929 struct target_info_t target_info;
930 struct msg_t *msg_reply = NULL;
931 struct msg_buf_t msg_control;
933 enum ErrorCode error_code = ERR_NO;
936 msg_target_t sendlog;
938 LOGI("MY HANDLE %s (%X)\n", msg_ID_str(msg->id), msg->id);
939 init_parse_control(&msg_control, msg);
942 case NMSG_KEEP_ALIVE:
943 sendACKToHost(msg->id, ERR_NO, 0, 0);
946 return process_msg_start(&msg_control);
948 sendACKToHost(msg->id, ERR_NO, 0, 0);
949 if (stop_all() != ERR_NO) {
950 LOGE("Stop failed\n");
951 write_msg_error("Stop failed");
956 if (!parse_msg_config(&msg_control, &conf)) {
957 LOGE("config parsing error\n");
958 sendACKToHost(msg->id, ERR_WRONG_MESSAGE_FORMAT, 0, 0);
961 if (reconfigure(conf) != 0) {
962 LOGE("Cannot change configuration\n");
966 if (ioctl_send_msg(msg) != 0) {
967 LOGE("ioctl send error\n");
968 sendACKToHost(msg->id, ERR_UNKNOWN, 0, 0);
972 sendACKToHost(msg->id, ERR_NO, 0, 0);
973 // send config message to target process
974 sendlog.type = MSG_OPTION;
975 sendlog.length = sprintf(sendlog.data, "%llu",
976 (unsigned long long) prof_session.conf.use_features0);
977 for (target_index = 0; target_index < MAX_TARGET_COUNT; target_index++)
979 if(manager.target[target_index].socket != -1)
981 if (0 > send(manager.target[target_index].socket, &sendlog,
982 sizeof(sendlog.type) + sizeof(sendlog.length) + sendlog.length,
984 LOGE("fail to send data to target index(%d)\n", target_index);
988 case NMSG_BINARY_INFO:
989 return process_msg_binary_info(&msg_control);
990 case NMSG_SWAP_INST_ADD:
991 if (msg_swap_inst_add(&msg_control, &prof_session.user_space_inst,
992 &msg_reply, &error_code) != 0) {
993 LOGE("swap inst add\n");
996 if (msg_reply != NULL)
997 if (ioctl_send_msg(msg_reply) != 0) {
998 error_code = ERR_UNKNOWN;
999 LOGE("ioclt send error\n");
1003 case NMSG_SWAP_INST_REMOVE:
1004 if (msg_swap_inst_remove(&msg_control, &prof_session.user_space_inst,
1005 &msg_reply, &error_code) != 0) {
1006 LOGE("swap inst remove\n");
1007 error_code = ERR_UNKNOWN;
1010 if (msg_reply != NULL) {
1011 if (ioctl_send_msg(msg_reply) != 0)
1012 error_code = ERR_UNKNOWN;
1014 error_code = ERR_UNKNOWN;
1017 case NMSG_GET_TARGET_INFO:
1018 fill_target_info(&target_info);
1019 msg_reply = gen_target_info_reply(&target_info);
1021 LOGE("cannot generate reply message\n");
1022 sendACKToHost(msg->id, ERR_UNKNOWN, 0, 0);
1025 if (send_reply(msg_reply) != 0) {
1026 LOGE("Cannot send reply\n");
1029 reset_target_info(&target_info);
1031 case NMSG_GET_SCREENSHOT:
1032 return process_msg_get_screenshot(&msg_control);
1034 LOGE("unknown message %d <0x%08X>\n", msg->id, msg->id);
1040 sendACKToHost(msg->id, error_code, 0, 0);
1041 if (msg_reply != NULL)
1043 return (error_code == ERR_NO);
1048 static void print_conf(struct conf_t *conf)
1051 memset(&buf[0], 0, 1024);
1052 feature_code_str(conf->use_features0, conf->use_features1, buf);
1054 LOGI("\tuse_features = 0x%016LX : 0x%016LX \n(\t%s)\n",
1055 conf->use_features0, conf->use_features1, buf);
1057 "\tsystem_trace_period = %d ms\n"
1058 "\tdata message period = %d ms\n",
1059 conf->system_trace_period,
1060 conf->data_message_period
1064 void print_replay_event(struct replay_event_t *ev, uint32_t num, char *tab)
1066 LOGW("%s\t#%04d:time=0x%08X %08X, "
1072 (unsigned int)ev->ev.time.tv_sec,//timeval
1073 (unsigned int)ev->ev.time.tv_usec,//timeval