+#define WIFI_CP2_FIRMWARE_STATE_PATH "/tmp/.wifi-firmware-loaded"
+#define BT_CP2_FIRMWARE_STATE_PATH "/tmp/.bt-firmware-loaded"
+#define BT_CP2_FIRMWARE_PATH "/hal/bin/cp2-downloader"
+#define MAX_SIZE_ERROR_BUFFER 256
+
+int __bt_execute_file(const char *file_path,
+ char *const args[], char *const envs[])
+{
+ pid_t pid = 0;
+ int status = 0;
+ int rv = 0;
+ errno = 0;
+ register unsigned int index = 0;
+ char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
+
+ while (args[index] != NULL) {
+ LOGD("%s", args[index]);
+ index++;
+ }
+
+ if (!(pid = fork())) {
+ LOGD("pid(%d), ppid (%d)", getpid(), getppid());
+ LOGD("Inside child, exec (%s) command", file_path);
+
+ errno = 0;
+ if (execve(file_path, args, envs) == -1) {
+ strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
+ LOGE("Fail to execute command (%s)", error_buf);
+ exit(1);
+ }
+ } else if (pid > 0) {
+ if (waitpid(pid, &status, 0) == -1)
+ LOGD("wait pid (%u) status (%d)", pid, status);
+
+ if (WIFEXITED(status)) {
+ rv = WEXITSTATUS(status);
+ LOGD("exited, status=%d", rv);
+ } else if (WIFSIGNALED(status)) {
+ LOGD("killed by signal %d", WTERMSIG(status));
+ } else if (WIFSTOPPED(status)) {
+ LOGD("stopped by signal %d", WSTOPSIG(status));
+ } else if (WIFCONTINUED(status)) {
+ LOGD("continued");
+ }
+
+ return rv;
+ }
+
+ strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
+ LOGD("failed to fork(%s)", error_buf);
+ return -EIO;
+}
+
+static void __bt_firmware_update_state(void)
+{
+ int fd;
+ mode_t mode = S_IRGRP | S_IWUSR | S_IXGRP;
+
+ fd = creat(BT_CP2_FIRMWARE_STATE_PATH, mode);
+ if (fd >= 0)
+ close(fd);
+ else
+ LOGE("Failed to create bt firmware state file");
+}
+