trusty.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #define LOG_TAG "libtrusty"
  17. #include <errno.h>
  18. #include <fcntl.h>
  19. #include <stdbool.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <sys/ioctl.h>
  24. #include <unistd.h>
  25. #include <log/log.h>
  26. #include "tipc_ioctl.h"
  27. int tipc_connect(const char *dev_name, const char *srv_name)
  28. {
  29. int fd;
  30. int rc;
  31. fd = open(dev_name, O_RDWR);
  32. if (fd < 0) {
  33. rc = -errno;
  34. ALOGE("%s: cannot open tipc device \"%s\": %s\n",
  35. __func__, dev_name, strerror(errno));
  36. return rc < 0 ? rc : -1;
  37. }
  38. rc = ioctl(fd, TIPC_IOC_CONNECT, srv_name);
  39. if (rc < 0) {
  40. rc = -errno;
  41. ALOGE("%s: can't connect to tipc service \"%s\" (err=%d)\n",
  42. __func__, srv_name, errno);
  43. close(fd);
  44. return rc < 0 ? rc : -1;
  45. }
  46. ALOGV("%s: connected to \"%s\" fd %d\n", __func__, srv_name, fd);
  47. return fd;
  48. }
  49. void tipc_close(int fd)
  50. {
  51. close(fd);
  52. }