Files
BPI-M2C/source_sync_rls_25c/source/unisoc/trusty/libtrusty/trusty.c
T
2026-09-22 09:38:26 +08:00

82 lines
2.2 KiB
C

/*
* Copyright 2022 Unisoc (Shanghai) Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-FileCopyrightText: 2022 Unisoc (Shanghai) Technologies Co., Ltd
* SPDX-License-Identifier: LicenseRef-Unisoc-General-1.0
*
* Licensed under the Unisoc General Software License, version 1.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.unisoc.com/en_us/license/UNISOC_GENERAL_LICENSE_V1.0-EN_US
*
* Software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OF ANY KIND, either express or implied.
* See the Unisoc General Software License, version 1.0 for more details.
*/
#define LOG_TAG "libtrusty"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "tipc_ioctl.h"
#define LOCAL_TRACE 1
#define ALOGE(fmt, ...) \
fprintf(stderr, "%s: %d: " fmt, LOG_TAG, __LINE__, ## __VA_ARGS__)
#if LOCAL_TRACE
#define ALOGV(fmt, ...) \
fprintf(stderr, "%s: %d: " fmt, LOG_TAG, __LINE__, ## __VA_ARGS__)
#else
#define ALOGV(fmt, ...)
#endif
int tipc_connect(const char *device, const char *port)
{
int fd, rc;
fd = open(device, O_RDWR);
if (fd < 0) {
rc = -errno;
ALOGE("cannot open tipc device \"%s\": %s\n", device, strerror(errno));
goto error;
}
rc = ioctl(fd, TIPC_IOC_CONNECT, port);
if (rc < 0) {
rc = -errno;
ALOGE("can't connect to tipc service \"%s\" (err=%d)\n", port, errno);
close(fd);
goto error;
}
ALOGV("%s: connected to \"%s\" fd %d\n", __func__, port, fd);
return fd;
error:
return rc < 0 ? rc : -1;
}
void tipc_close(int fd)
{
close(fd);
}