1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #define LOG_TAG "libtrusty" 18 19 #include <errno.h> 20 #include <fcntl.h> 21 #include <stdbool.h> 22 #include <stdio.h> 23 #include <stdlib.h> 24 #include <string.h> 25 26 #include <cutils/log.h> 27 28 #include "tipc_ioctl.h" 29 30 int tipc_connect(const char *dev_name, const char *srv_name) 31 { 32 int fd; 33 int rc; 34 35 fd = open(dev_name, O_RDWR); 36 if (fd < 0) { 37 rc = -errno; 38 ALOGE("%s: cannot open tipc device \"%s\": %s\n", 39 __func__, dev_name, strerror(errno)); 40 return rc < 0 ? rc : -1; 41 } 42 43 rc = ioctl(fd, TIPC_IOC_CONNECT, srv_name); 44 if (rc < 0) { 45 rc = -errno; 46 ALOGE("%s: can't connect to tipc service \"%s\" (err=%d)\n", 47 __func__, srv_name, errno); 48 close(fd); 49 return rc < 0 ? rc : -1; 50 } 51 52 ALOGV("%s: connected to \"%s\" fd %d\n", __func__, srv_name, fd); 53 return fd; 54 } 55 56 void tipc_close(int fd) 57 { 58 close(fd); 59 } 60