1/*
2 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3 * Licensed under the Mulan PSL v2.
4 * You can use this software according to the terms and conditions of the Mulan PSL v2.
5 * You may obtain a copy of Mulan PSL v2 at:
6 *     http://license.coscl.org.cn/MulanPSL2
7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9 * PURPOSE.
10 * See the Mulan PSL v2 for more details.
11 */
12
13#include "late_init_agent.h"
14#include <errno.h>
15#include <fcntl.h>
16#include <sys/ioctl.h>
17#include <sys/types.h>
18#include <time.h>
19#include <unistd.h>
20#include "fs_work_agent.h"
21#include "tc_ns_client.h"
22#include "tee_log.h"
23
24#ifdef LOG_TAG
25#undef LOG_TAG
26#endif
27#define LOG_TAG "teecd_agent"
28
29void *InitLateWorkThread(void *dummy)
30{
31    (void)dummy;
32    unsigned int index = FS_LATE_INIT;
33
34    tlogd("now start to late init\n");
35
36    int fd = open(TC_PRIVATE_DEV_NAME, O_RDWR);
37    if (fd < 0) {
38        tloge("open tee client dev failed, fd is %d\n", fd);
39        return NULL;
40    }
41
42    int ret = ioctl(fd, (int)TC_NS_CLIENT_IOCTL_LATEINIT, index);
43    if (ret) {
44        tloge("failed to set late init, errno = %d\n", errno);
45    }
46
47    close(fd);
48    return NULL;
49}
50