SET(LIBDIR ${CMAKE_LIBDIR_PREFIX})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/protocol)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
SET(PKG_MODULES
hal-api-common
dlog
- wayland-client
- wayland-server
- wayland-scanner
- libdrm
)
INCLUDE(FindPkgConfig)
ADD_DEFINITIONS("-DLOG_TAG=\"HALAPI_TBM\"")
SET(SRCS
- protocol/wayland-tbm-drm-auth-protocol.c
src/hal-api-tbm.c
- src/hal-tbm-drm-helper-server.c
- src/hal-tbm-drm-helper-client.c
src/hal-tbm-log.c)
ADD_LIBRARY( ${PROJECT_NAME} SHARED ${SRCS})
hal_tbm_key (*bo_export_key)(hal_tbm_bo *bo, hal_tbm_error *error);
};
-/**
- * @brief Initialize authentication server in display server.
- * @details
- * In DRM system, client sholud get authenticated fd from display server for using drm.
- Tbm provides wayland protocol and helper function for passing and authenticating
- fd from display server.
- * @param[in] wl_display wayland display
- * @param[in] fd fd of drm_master
- * @param[in] device_name name of drm device
- * @param[in] flags flags
- * @see #hal_tbm_drm_helper_wl_auth_server_deinit()
- */
-int hal_tbm_drm_helper_wl_auth_server_init(void *wl_display, int fd, const char *device_name, uint32_t flags);
-
-/**
- * @brief Deinitialize authentication server in display server
- * @details
- * In DRM system, client sholud get authenticated fd from display server for using drm.
- Tbm provides wayland protocol and helper function for passing and authenticating
- fd from display server.
- * @see #tdm_helper_set_tbm_master_fd()
- * @see #hal_tbm_drm_helper_unset_tbm_master_fd()
- */
-void hal_tbm_drm_helper_wl_auth_server_deinit(void);
-
-/**
- * @brief Get a drm master fd.
- * @details
- * This function will dup the drm master fd.
- The Caller SHOULD close the fd.
- In DRM system, a drm master fd SHOULD be shared between TDM backend and
- TBM backend in display server side.
- * @return fd if success. Otherwise, -1.
- * @see #hal_tbm_drm_helper_set_tbm_master_fd()
- * @see #hal_tbm_drm_helper_unset_tbm_master_fd()
- */
-int hal_tbm_drm_helper_get_master_fd(void);
-
-/**
- * @brief Set a drm master fd with the given fd.
- * @details
- * In DRM system, a drm master fd @b SHOULD be shared between TDM backend and
- TBM backend in display server side.
- * @param[in] fd The given fd
- * @see #hal_tbm_drm_helper_get_master_fd()
- * @see #hal_tbm_drm_helper_unset_tbm_master_fd()
- */
-void hal_tbm_drm_helper_set_tbm_master_fd(int fd);
-
-/**
- * @brief Unset a drm master fd.
- * @see #hal_tbm_drm_helper_get_master_fd()
- * @see #hal_tbm_drm_helper_set_tbm_master_fd()
- */
-void hal_tbm_drm_helper_unset_tbm_master_fd(void);
-
-/**
- * @brief Get infomation of drm authentication.
- * @details
- * In DRM system, client sholud get authenticated fd from display server for using drm.
- Tbm provides wayland protocol and helper function for passing and authenticating
- fd from display server.
- * @param[out] fd The authenticated fd
- * @param[out] device The device name
- * @param[out] capabilities The capabilities of device
- * @see #tdm_helper_set_tbm_master_fd()
- * @see #hal_tbm_drm_helper_unset_tbm_master_fd()
- */
-int hal_tbm_drm_helper_get_auth_info(int *auth_fd, char **device, uint32_t *capabilities);
-
-/**
- * @brief Set drm fd with the given fd.
- * @details
- * Some client want to get drm fd used tbm_backend.
- if tbm_backend allow that client use drm_fd, it SHOULD be set.
- * @param[in] fd The given fd
- * @see #hal_tbm_drm_helper_get_fd()
- */
-void hal_tbm_drm_helper_set_fd(int fd);
-
-/**
- * @brief Unset drm fd.
- * @details
- * Some client want to get drm fd used tbm_backend.
- if tbm_backend allow that client use drm_fd, it SHOULD be set.
- * @param[in] fd The given fd
- * @see #hal_tbm_drm_helper_get_fd()
- */
-void hal_tbm_drm_helper_unset_fd(void);
-
-/**
- * @brief Get drm fd.
- * @details
- * Some client want to get drm fd used tbm_backend.
- client can get drm fd from this fucntion.
- The Caller SHOULD close the fd.
- * @return fd if success. Otherwise, -1.
- * @see #tdm_helper_set_tbm_master_fd()
- * @see #hal_tbm_drm_helper_unset_tbm_master_fd()
- */
-int hal_tbm_drm_helper_get_fd(void);
-
#ifdef __cplusplus
}
#endif
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(gmock)
BuildRequires: pkgconfig(hal-api-common)
-BuildRequires: pkgconfig(wayland-server)
-BuildRequires: pkgconfig(wayland-client)
BuildRequires: pkgconfig(libdrm)
%description
+++ /dev/null
-/* Generated by wayland-scanner 1.18.92 */
-
-#ifndef TBM_DRM_AUTH_CLIENT_PROTOCOL_H
-#define TBM_DRM_AUTH_CLIENT_PROTOCOL_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include "wayland-client.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @page page_tbm_drm_auth The tbm_drm_auth protocol
- * @section page_ifaces_tbm_drm_auth Interfaces
- * - @subpage page_iface_wl_tbm_drm_auth -
- * @section page_copyright_tbm_drm_auth Copyright
- * <pre>
- *
- * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
- *
- * Permission to use, copy, modify, distribute, and sell this
- * software and its documentation for any purpose is hereby granted
- * without fee, provided that\n the above copyright notice appear in
- * all copies and that both that copyright notice and this permission
- * notice appear in supporting documentation, and that the name of
- * the copyright holders not be used in advertising or publicity
- * pertaining to distribution of the software without specific,
- * written prior permission. The copyright holders make no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied
- * warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
- * THIS SOFTWARE.
- * </pre>
- */
-struct wl_tbm_drm_auth;
-
-#ifndef WL_TBM_DRM_AUTH_INTERFACE
-#define WL_TBM_DRM_AUTH_INTERFACE
-/**
- * @page page_iface_wl_tbm_drm_auth wl_tbm_drm_auth
- * @section page_iface_wl_tbm_drm_auth_api API
- * See @ref iface_wl_tbm_drm_auth.
- */
-/**
- * @defgroup iface_wl_tbm_drm_auth The wl_tbm_drm_auth interface
- */
-extern const struct wl_interface wl_tbm_drm_auth_interface;
-#endif
-
-#ifndef WL_TBM_DRM_AUTH_ERROR_ENUM
-#define WL_TBM_DRM_AUTH_ERROR_ENUM
-enum wl_tbm_drm_auth_error {
- WL_TBM_DRM_AUTH_ERROR_AUTHENTICATE_FAIL = 0,
-};
-#endif /* WL_TBM_DRM_AUTH_ERROR_ENUM */
-
-/**
- * @ingroup iface_wl_tbm_drm_auth
- * @struct wl_tbm_drm_auth_listener
- */
-struct wl_tbm_drm_auth_listener {
- /**
- */
- void (*authentication_info)(void *data,
- struct wl_tbm_drm_auth *wl_tbm_drm_auth,
- const char *device_name,
- uint32_t capabilities,
- int32_t auth_fd);
-};
-
-/**
- * @ingroup iface_wl_tbm_drm_auth
- */
-static inline int
-wl_tbm_drm_auth_add_listener(struct wl_tbm_drm_auth *wl_tbm_drm_auth,
- const struct wl_tbm_drm_auth_listener *listener, void *data)
-{
- return wl_proxy_add_listener((struct wl_proxy *) wl_tbm_drm_auth,
- (void (**)(void)) listener, data);
-}
-
-#define WL_TBM_DRM_AUTH_GET_AUTHENTICATION_INFO 0
-
-/**
- * @ingroup iface_wl_tbm_drm_auth
- */
-#define WL_TBM_DRM_AUTH_AUTHENTICATION_INFO_SINCE_VERSION 1
-
-/**
- * @ingroup iface_wl_tbm_drm_auth
- */
-#define WL_TBM_DRM_AUTH_GET_AUTHENTICATION_INFO_SINCE_VERSION 1
-
-/** @ingroup iface_wl_tbm_drm_auth */
-static inline void
-wl_tbm_drm_auth_set_user_data(struct wl_tbm_drm_auth *wl_tbm_drm_auth, void *user_data)
-{
- wl_proxy_set_user_data((struct wl_proxy *) wl_tbm_drm_auth, user_data);
-}
-
-/** @ingroup iface_wl_tbm_drm_auth */
-static inline void *
-wl_tbm_drm_auth_get_user_data(struct wl_tbm_drm_auth *wl_tbm_drm_auth)
-{
- return wl_proxy_get_user_data((struct wl_proxy *) wl_tbm_drm_auth);
-}
-
-static inline uint32_t
-wl_tbm_drm_auth_get_version(struct wl_tbm_drm_auth *wl_tbm_drm_auth)
-{
- return wl_proxy_get_version((struct wl_proxy *) wl_tbm_drm_auth);
-}
-
-/** @ingroup iface_wl_tbm_drm_auth */
-static inline void
-wl_tbm_drm_auth_destroy(struct wl_tbm_drm_auth *wl_tbm_drm_auth)
-{
- wl_proxy_destroy((struct wl_proxy *) wl_tbm_drm_auth);
-}
-
-/**
- * @ingroup iface_wl_tbm_drm_auth
- */
-static inline void
-wl_tbm_drm_auth_get_authentication_info(struct wl_tbm_drm_auth *wl_tbm_drm_auth)
-{
- wl_proxy_marshal((struct wl_proxy *) wl_tbm_drm_auth,
- WL_TBM_DRM_AUTH_GET_AUTHENTICATION_INFO);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-/* Generated by wayland-scanner 1.18.92 */
-
-/*
- * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
- *
- * Permission to use, copy, modify, distribute, and sell this
- * software and its documentation for any purpose is hereby granted
- * without fee, provided that\n the above copyright notice appear in
- * all copies and that both that copyright notice and this permission
- * notice appear in supporting documentation, and that the name of
- * the copyright holders not be used in advertising or publicity
- * pertaining to distribution of the software without specific,
- * written prior permission. The copyright holders make no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied
- * warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
- * THIS SOFTWARE.
- */
-
-#include <stdlib.h>
-#include <stdint.h>
-#include "wayland-util.h"
-
-
-static const struct wl_interface *tbm_drm_auth_types[] = {
- NULL,
- NULL,
- NULL,
-};
-
-static const struct wl_message wl_tbm_drm_auth_requests[] = {
- { "get_authentication_info", "", tbm_drm_auth_types + 0 },
-};
-
-static const struct wl_message wl_tbm_drm_auth_events[] = {
- { "authentication_info", "suh", tbm_drm_auth_types + 0 },
-};
-
-WL_EXPORT const struct wl_interface wl_tbm_drm_auth_interface = {
- "wl_tbm_drm_auth", 1,
- 1, wl_tbm_drm_auth_requests,
- 1, wl_tbm_drm_auth_events,
-};
-
+++ /dev/null
-/* Generated by wayland-scanner 1.18.92 */
-
-#ifndef TBM_DRM_AUTH_SERVER_PROTOCOL_H
-#define TBM_DRM_AUTH_SERVER_PROTOCOL_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include "wayland-server.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct wl_client;
-struct wl_resource;
-
-/**
- * @page page_tbm_drm_auth The tbm_drm_auth protocol
- * @section page_ifaces_tbm_drm_auth Interfaces
- * - @subpage page_iface_wl_tbm_drm_auth -
- * @section page_copyright_tbm_drm_auth Copyright
- * <pre>
- *
- * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
- *
- * Permission to use, copy, modify, distribute, and sell this
- * software and its documentation for any purpose is hereby granted
- * without fee, provided that\n the above copyright notice appear in
- * all copies and that both that copyright notice and this permission
- * notice appear in supporting documentation, and that the name of
- * the copyright holders not be used in advertising or publicity
- * pertaining to distribution of the software without specific,
- * written prior permission. The copyright holders make no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied
- * warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
- * THIS SOFTWARE.
- * </pre>
- */
-struct wl_tbm_drm_auth;
-
-#ifndef WL_TBM_DRM_AUTH_INTERFACE
-#define WL_TBM_DRM_AUTH_INTERFACE
-/**
- * @page page_iface_wl_tbm_drm_auth wl_tbm_drm_auth
- * @section page_iface_wl_tbm_drm_auth_api API
- * See @ref iface_wl_tbm_drm_auth.
- */
-/**
- * @defgroup iface_wl_tbm_drm_auth The wl_tbm_drm_auth interface
- */
-extern const struct wl_interface wl_tbm_drm_auth_interface;
-#endif
-
-#ifndef WL_TBM_DRM_AUTH_ERROR_ENUM
-#define WL_TBM_DRM_AUTH_ERROR_ENUM
-enum wl_tbm_drm_auth_error {
- WL_TBM_DRM_AUTH_ERROR_AUTHENTICATE_FAIL = 0,
-};
-#endif /* WL_TBM_DRM_AUTH_ERROR_ENUM */
-
-/**
- * @ingroup iface_wl_tbm_drm_auth
- * @struct wl_tbm_drm_auth_interface
- */
-struct wl_tbm_drm_auth_interface {
- /**
- */
- void (*get_authentication_info)(struct wl_client *client,
- struct wl_resource *resource);
-};
-
-#define WL_TBM_DRM_AUTH_AUTHENTICATION_INFO 0
-
-/**
- * @ingroup iface_wl_tbm_drm_auth
- */
-#define WL_TBM_DRM_AUTH_AUTHENTICATION_INFO_SINCE_VERSION 1
-
-/**
- * @ingroup iface_wl_tbm_drm_auth
- */
-#define WL_TBM_DRM_AUTH_GET_AUTHENTICATION_INFO_SINCE_VERSION 1
-
-/**
- * @ingroup iface_wl_tbm_drm_auth
- * Sends an authentication_info event to the client owning the resource.
- * @param resource_ The client's resource
- */
-static inline void
-wl_tbm_drm_auth_send_authentication_info(struct wl_resource *resource_, const char *device_name, uint32_t capabilities, int32_t auth_fd)
-{
- wl_resource_post_event(resource_, WL_TBM_DRM_AUTH_AUTHENTICATION_INFO, device_name, capabilities, auth_fd);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<protocol name="tbm_drm_auth">
-
- <copyright>
- Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that\n the above copyright notice appear in
- all copies and that both that copyright notice and this permission
- notice appear in supporting documentation, and that the name of
- the copyright holders not be used in advertising or publicity
- pertaining to distribution of the software without specific,
- written prior permission. The copyright holders make no
- representations about the suitability of this software for any
- purpose. It is provided "as is" without express or implied
- warranty.
-
- THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
- SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
- THIS SOFTWARE.
- </copyright>
-
- <!-- tbm support. This object is created by the server and published
- using the display's global event. -->
- <interface name="wl_tbm_drm_auth" version="1">
- <enum name="error">
- <entry name="authenticate_fail" value="0"/>
- </enum>
-
- <request name="get_authentication_info">
- </request>
-
- <event name="authentication_info">
- <arg name="device_name" type="string"/>
- <arg name="capabilities" type="uint"/>
- <arg name="auth_fd" type="fd"/>
- </event>
-
- </interface>
-
-</protocol>
+++ /dev/null
-/**************************************************************************
- *
- * hal-api-tbm
- *
- * Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved.
- *
- * Contact: SooChan Lim <sc1.lim@samsung.com>,
- * Junkyeong Kim <jk0430.kim@samsung.com>,
- * Changyeon Lee <cyeon.lee@samsung.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
-**************************************************************************/
-
-#define WL_HIDE_DEPRECATED
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/resource.h>
-#include "common.h"
-#include "hal-tbm-types.h"
-#include "wayland-tbm-drm-auth-client-protocol.h"
-
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define EXTERN __attribute__ ((visibility("default")))
-#else
-#define EXTERN
-#endif
-
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define INTERN __attribute__ ((visibility("hidden")))
-#else
-#define INTERN
-#endif
-
-struct wayland_tbm_drm_auth_client {
- struct wl_display *display;
- struct wl_tbm_drm_auth *wl_tbm_drm_auth;
- int auth_fd;
- char *device;
- uint32_t capabilities;
-};
-
-static int tbm_drm_fd = -1;
-
-/* LCOV_EXCL_START */
-static void
-handle_tbm_drm_authentication_info(void *data, struct wl_tbm_drm_auth *wl_tbm_drm_auth, const char *device_name, uint32_t capabilities, int32_t auth_fd)
-{
- struct wayland_tbm_drm_auth_client *tbm_drm_client = (struct wayland_tbm_drm_auth_client *)data;
-
- /* client authentication infomation */
- tbm_drm_client->auth_fd = auth_fd;
- tbm_drm_client->capabilities = capabilities;
- if (device_name)
- tbm_drm_client->device = strdup(device_name);
-}
-
-static const struct wl_tbm_drm_auth_listener wl_tbm_drm_auth_client_listener = {
- handle_tbm_drm_authentication_info
-};
-
-static void
-_wayland_tbm_drm_auth_client_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
-{
- struct wayland_tbm_drm_auth_client *tbm_drm_client = (struct wayland_tbm_drm_auth_client *)data;
-
- if (!strcmp(interface, "wl_tbm_drm_auth")) {
- tbm_drm_client->wl_tbm_drm_auth = wl_registry_bind(registry, name, &wl_tbm_drm_auth_interface, version);
- HAL_TBM_RETURN_IF_FAIL(tbm_drm_client->wl_tbm_drm_auth != NULL);
-
- wl_tbm_drm_auth_add_listener(tbm_drm_client->wl_tbm_drm_auth, &wl_tbm_drm_auth_client_listener, tbm_drm_client);
- }
-}
-
-static void
-_wayland_tbm_drm_auth_client_registry_remove_global(void *data, struct wl_registry *registry, uint32_t name)
-{
-}
-
-static const struct wl_registry_listener registry_listener = {
- _wayland_tbm_drm_auth_client_registry_handle_global,
- _wayland_tbm_drm_auth_client_registry_remove_global
-};
-
-EXTERN int
-hal_tbm_drm_helper_get_auth_info(int *auth_fd, char **device, uint32_t *capabilities)
-{
- struct wl_display *display;
- struct wl_registry *wl_registry;
- struct wayland_tbm_drm_auth_client *tbm_drm_client;
-
- tbm_drm_client = calloc(1, sizeof(struct wayland_tbm_drm_auth_client));
- HAL_TBM_RETURN_VAL_IF_FAIL(tbm_drm_client != NULL, 0);
-
- tbm_drm_client->auth_fd = -1;
-
- display = wl_display_connect("tbm-drm-auth");
- if (!display) {
- HAL_TBM_ERR("Failed to connect display\n");
- free(tbm_drm_client);
-
- return 0;
- }
-
- tbm_drm_client->display = display;
-
- wl_registry = wl_display_get_registry(display);
- if (!wl_registry) {
- HAL_TBM_ERR("Failed to get registry\n");
- wl_display_disconnect(display);
- free(tbm_drm_client);
-
- return 0;
- }
-
- wl_registry_add_listener(wl_registry, ®istry_listener, tbm_drm_client);
- if (wl_display_roundtrip(display) < 0) { //For Gloabl registry
- HAL_TBM_ERR("Failed to wl_display_roundtrip for global registry\n");
- wl_registry_destroy(wl_registry);
- wl_display_disconnect(display);
- free(tbm_drm_client);
- return 0;
- }
-
- if (!tbm_drm_client->wl_tbm_drm_auth) {
- HAL_TBM_ERR("Failed to get wl_tbm_drm_auth interface\n");
- wl_registry_destroy(wl_registry);
- wl_display_disconnect(display);
- free(tbm_drm_client);
-
- return 0;
- }
-
- wl_tbm_drm_auth_get_authentication_info(tbm_drm_client->wl_tbm_drm_auth);
- if (wl_display_roundtrip(display) < 0) {
- HAL_TBM_ERR("Failed to wl_display_roundtrip get auth info\n");
- wl_tbm_drm_auth_set_user_data(tbm_drm_client->wl_tbm_drm_auth, NULL);
- wl_tbm_drm_auth_destroy(tbm_drm_client->wl_tbm_drm_auth);
- wl_registry_destroy(wl_registry);
- wl_display_disconnect(display);
- free(tbm_drm_client);
- return 0;
- }
-
- if (tbm_drm_client->auth_fd < 0) {
- HAL_TBM_ERR("Failed to get auth info\n");
- wl_tbm_drm_auth_set_user_data(tbm_drm_client->wl_tbm_drm_auth, NULL);
- wl_tbm_drm_auth_destroy(tbm_drm_client->wl_tbm_drm_auth);
- wl_registry_destroy(wl_registry);
- wl_display_disconnect(display);
- free(tbm_drm_client);
-
- return 0;
- }
-
- if (auth_fd)
- *auth_fd = tbm_drm_client->auth_fd;
- else
- close(tbm_drm_client->auth_fd);
-
- if (capabilities)
- *capabilities = tbm_drm_client->capabilities;
-
- if (device) {
- if (tbm_drm_client->device)
- *device = strdup(tbm_drm_client->device);
- else
- *device = NULL;
- }
-
- wl_tbm_drm_auth_set_user_data(tbm_drm_client->wl_tbm_drm_auth, NULL);
- wl_tbm_drm_auth_destroy(tbm_drm_client->wl_tbm_drm_auth);
-
- if (tbm_drm_client->device)
- free(tbm_drm_client->device);
-
- free(tbm_drm_client);
-
- wl_registry_destroy(wl_registry);
- wl_display_disconnect(display);
-
- return 1;
-}
-
-static int
-_hal_tbm_drm_helper_client_get_fd_limit(void)
-{
- struct rlimit lim;
-
- if (getrlimit(RLIMIT_NOFILE, &lim))
- return 1024;
-
- return (int)lim.rlim_cur;
-}
-
-EXTERN void
-hal_tbm_drm_helper_set_fd(int fd)
-{
- int fd_max = _hal_tbm_drm_helper_client_get_fd_limit();
-
- if (tbm_drm_fd == fd)
- return;
-
- if (fd < 0 || fd > fd_max) {
- HAL_TBM_ERR("%d out of fd range\n", fd);
- return;
- }
-
- if (tbm_drm_fd != -1)
- HAL_TBM_WRN("already has TBM_DRM_FD: %d\n", tbm_drm_fd);
-
- tbm_drm_fd = fd;
-
- HAL_TBM_INFO("TBM_DRM_FD: %d\n", tbm_drm_fd);
-}
-
-EXTERN void
-hal_tbm_drm_helper_unset_fd(void)
-{
- tbm_drm_fd = -1;
- HAL_TBM_INFO("TBM_DRM_FD: %d\n", tbm_drm_fd);
-}
-
-EXTERN int
-hal_tbm_drm_helper_get_fd(void)
-{
- int new_fd, flags;
-
- if (tbm_drm_fd == -1) {
- HAL_TBM_ERR("no drm fd");
- return -1;
- }
-
- HAL_TBM_INFO("TBM_DRM_FD: %d\n", tbm_drm_fd);
-
- flags = fcntl(tbm_drm_fd, F_GETFD);
- if (flags == -1) {
- HAL_TBM_ERR("fcntl failed: %m");
- return -1;
- }
-
- new_fd = dup(tbm_drm_fd);
- if (new_fd < 0) {
- HAL_TBM_ERR("dup failed: %m");
- return -1;
- }
-
- if (fcntl(new_fd, F_SETFD, flags|FD_CLOEXEC) == -1) {
- HAL_TBM_ERR("failed to set fd\n");
- close(new_fd);
- return -1;
- }
-
- HAL_TBM_INFO("Return TBM_FD: %d\n", new_fd);
-
- return new_fd;
-}
-
-/* LCOV_EXCL_STOP */
+++ /dev/null
-/**************************************************************************
- *
- * hal-api-tbm
- *
- * Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved.
- *
- * Contact: SooChan Lim <sc1.lim@samsung.com>,
- * Junkyeong Kim <jk0430.kim@samsung.com>,
- * Changyeon Lee <cyeon.lee@samsung.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
-**************************************************************************/
-
-#define WL_HIDE_DEPRECATED
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stddef.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/resource.h>
-#include <xf86drm.h>
-#include <grp.h>
-#include "common.h"
-#include "hal-tbm-types.h"
-#include "wayland-tbm-drm-auth-server-protocol.h"
-
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define EXTERN __attribute__ ((visibility("default")))
-#else
-#define EXTERN
-#endif
-
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define INTERN __attribute__ ((visibility("hidden")))
-#else
-#define INTERN
-#endif
-
-struct wayland_tbm_drm_auth_server {
- struct wl_display *display;
- struct wl_global *wl_tbm_drm_auth_global;
-
- char *device_name;
- uint32_t fd;
- uint32_t flags;
-};
-
-#define MIN(x, y) (((x) < (y)) ? (x) : (y))
-
-struct wayland_tbm_drm_auth_server *tbm_drm_auth_srv;
-
-static int tbm_drm_master_fd = -1;
-
-/* LCOV_EXCL_START */
-static void
-_send_server_auth_info(struct wayland_tbm_drm_auth_server *tbm_drm_auth_srv,
- struct wl_resource *resource)
-{
- int fd = -1;
- uint32_t capabilities;
- char *device_name = NULL;
- drm_magic_t magic = 0;
-
- fd = open(tbm_drm_auth_srv->device_name, O_RDWR | O_CLOEXEC);
- if (fd == -1 && errno == EINVAL) {
- fd = open(tbm_drm_auth_srv->device_name, O_RDWR);
- if (fd != -1) {
- if (fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC) == -1) {
- HAL_TBM_ERR("failed to set fd\n");
- goto fini;
- }
- }
- }
-
- if (fd < 0) {
- HAL_TBM_ERR("failed to open drm : device_name, %s\n", tbm_drm_auth_srv->device_name);
-
- wl_resource_post_error(resource, WL_TBM_DRM_AUTH_ERROR_AUTHENTICATE_FAIL,
- "authenicate failed::open_drm");
- goto fini;
- }
-
- if (drmGetMagic(fd, &magic) < 0) {
- if (errno != EACCES) {
- HAL_TBM_ERR("failed to get magic\n");
-
- wl_resource_post_error(resource, WL_TBM_DRM_AUTH_ERROR_AUTHENTICATE_FAIL,
- "authenicate failed::get_magic");
- goto fini;
- }
- }
-
- if (drmAuthMagic(tbm_drm_auth_srv->fd, magic) < 0) {
- HAL_TBM_ERR("failed to authenticate magic\n");
-
- wl_resource_post_error(resource, WL_TBM_DRM_AUTH_ERROR_AUTHENTICATE_FAIL,
- "authenicate failed::auth_magic");
- goto fini;
- }
-
- capabilities = tbm_drm_auth_srv->flags;
- device_name = tbm_drm_auth_srv->device_name;
-
- /* send */
- wl_tbm_drm_auth_send_authentication_info(resource, device_name, capabilities, fd);
-
-fini:
- if (fd >= 0)
- close(fd);
-
- if (device_name && device_name != tbm_drm_auth_srv->device_name)
- free(device_name);
-
-}
-
-static void
-_wayland_tbm_drm_auth_server_impl_get_authentication_info(struct wl_client *client,
- struct wl_resource *resource)
-{
- struct wayland_tbm_drm_auth_server *tbm_drm_auth_srv = wl_resource_get_user_data(resource);
-
- /* if display server is the client of the host display server, for embedded server */
- _send_server_auth_info(tbm_drm_auth_srv, resource);
-}
-
-
-static const struct wl_tbm_drm_auth_interface _wayland_tbm_drm_auth_server_implementation = {
- _wayland_tbm_drm_auth_server_impl_get_authentication_info,
-};
-
-static void
-_wayland_tbm_drm_auth_server_bind_cb(struct wl_client *client, void *data,
- uint32_t version,
- uint32_t id)
-{
- struct wl_resource *resource;
-
- resource = wl_resource_create(client, &wl_tbm_drm_auth_interface, MIN(version, 1), id);
- if (!resource) {
- wl_client_post_no_memory(client);
- return;
- }
-
- wl_resource_set_implementation(resource,
- &_wayland_tbm_drm_auth_server_implementation,
- data,
- NULL);
-}
-
-static int
-_tbm_getgrnam_r(const char *name)
-{
- struct group *grp = NULL;
- struct group *grp_res = NULL;
- char* buf = NULL;
- size_t buf_len;
- int ret;
- int id;
-
- buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
- if (buf_len == -1)
- buf_len = 2048;
-
- buf = calloc(1, buf_len * sizeof(char));
- if (!buf) {
- HAL_TBM_ERR("creating buffer failed\n");
- goto failed;
- }
-
- grp = calloc(1, sizeof(struct group));
- if (!grp) {
- HAL_TBM_ERR("creating group failed\n");
- goto failed;
- }
-
- ret = getgrnam_r(name, grp, buf, buf_len, &grp_res);
- if (ret < 0) {
- HAL_TBM_ERR("getgrnam_r failed errno:%d(%m)\n", ret);
- goto failed;
- }
-
- if (grp_res == NULL) {
- HAL_TBM_ERR("finding name:%s group failed\n", name);
- goto failed;
- }
-
- id = grp->gr_gid;
- free(buf);
- free(grp);
-
- return id;
-
-failed:
- if (buf)
- free(buf);
- if (grp)
- free(grp);
-
- return -1;
-}
-
-static void
-_tbm_drm_auth_socket_init(struct wayland_tbm_drm_auth_server *tbm_drm_auth_srv)
-{
- const char *dir = NULL;
- char socket_path[128];
- int ret = -1;
- uid_t uid;
- gid_t gid;
-
- dir = getenv("XDG_RUNTIME_DIR");
- if (!dir) {
- HAL_TBM_WRN("getting XDG_RUNTIME_DIR failed\n");
- return;
- }
-
- snprintf(socket_path, sizeof(socket_path), "%s/%s", dir, "tbm-drm-auth");
-
- ret = chmod(socket_path, 509);
- if (ret < 0) {
- HAL_TBM_WRN("changing modes of socket file failed:%s (%m)\n", socket_path);
- return;
- }
-
- ret = _tbm_getgrnam_r("root");
- if (ret < 0) {
- HAL_TBM_WRN("getting uid failed\n");
- return;
- }
- uid = ret;
-
- ret = _tbm_getgrnam_r("display");
- if (ret < 0) {
- HAL_TBM_WRN("getting gid failed\n");
- return;
- }
- gid = ret;
-
- ret = chown(socket_path, uid, gid);
- if (ret < 0) {
- HAL_TBM_WRN("changing owner of socket file failed:%s (%m)\n", socket_path);
- return;
- }
-}
-
-EXTERN int
-hal_tbm_drm_helper_wl_auth_server_init(void *wl_display, int fd, const char *device_name, uint32_t flags)
-{
- if (!tbm_drm_auth_srv) {
- HAL_TBM_RETURN_VAL_IF_FAIL(wl_display != NULL, 0);
-
- tbm_drm_auth_srv = calloc(1, sizeof(struct wayland_tbm_drm_auth_server));
- HAL_TBM_RETURN_VAL_IF_FAIL(tbm_drm_auth_srv != NULL, 0);
-
- tbm_drm_auth_srv->display = (struct wl_display *)wl_display;
- tbm_drm_auth_srv->device_name = strdup(device_name);
- tbm_drm_auth_srv->fd = fd;
- tbm_drm_auth_srv->flags = flags;
-
- if (wl_display_add_socket(tbm_drm_auth_srv->display, "tbm-drm-auth")) {
- HAL_TBM_ERR("[TBM_DRM] fail to add socket\n");
-
- if (tbm_drm_auth_srv->device_name)
- free(tbm_drm_auth_srv->device_name);
-
- free(tbm_drm_auth_srv);
- tbm_drm_auth_srv = NULL;
-
- return 0;
- }
-
- _tbm_drm_auth_socket_init(tbm_drm_auth_srv);
-
- /* init the client resource list */
- tbm_drm_auth_srv->wl_tbm_drm_auth_global = wl_global_create(tbm_drm_auth_srv->display, &wl_tbm_drm_auth_interface, 1,
- tbm_drm_auth_srv, _wayland_tbm_drm_auth_server_bind_cb);
- }
-
- return 1;
-}
-
-EXTERN void
-hal_tbm_drm_helper_wl_auth_server_deinit(void)
-{
- if (tbm_drm_auth_srv) {
- wl_global_destroy(tbm_drm_auth_srv->wl_tbm_drm_auth_global);
-
- if (tbm_drm_auth_srv->device_name)
- free(tbm_drm_auth_srv->device_name);
-
- free(tbm_drm_auth_srv);
- tbm_drm_auth_srv = NULL;
- }
-}
-
-EXTERN int
-hal_tbm_drm_helper_get_master_fd(void)
-{
- int new_fd, flags, fd = -1;
-
- fd = tbm_drm_master_fd;
- if (fd == -1) {
- HAL_TBM_INFO("no presetted TBM DRM MASTER FD");
- return -1;
- }
-
- HAL_TBM_INFO("TBM DRM MASTER FD: %d\n", fd);
-
- flags = fcntl(fd, F_GETFD);
- if (flags == -1) {
- HAL_TBM_ERR("fcntl failed: %m");
- return -1;
- }
-
- new_fd = dup(fd);
- if (new_fd < 0) {
- HAL_TBM_ERR("dup failed: %m");
- return -1;
- }
-
- if (fcntl(new_fd, F_SETFD, flags|FD_CLOEXEC) == -1) {
- HAL_TBM_ERR("failed to set fd\n");
- close(new_fd);
- return -1;
- }
-
- HAL_TBM_INFO("Return MASTER_FD: %d\n", new_fd);
-
- return new_fd;
-}
-
-static int
-_hal_tbm_drm_helper_server_get_fd_limit(void)
-{
- struct rlimit lim;
-
- if (getrlimit(RLIMIT_NOFILE, &lim))
- return 1024;
-
- return (int)lim.rlim_cur;
-}
-
-EXTERN void
-hal_tbm_drm_helper_set_tbm_master_fd(int fd)
-{
- int fd_max = _hal_tbm_drm_helper_server_get_fd_limit();
-
- if (tbm_drm_master_fd == fd)
- return;
-
- if (fd < 0 || fd > fd_max) {
- HAL_TBM_ERR("%d out of fd range\n", fd);
- return;
- }
-
- if (tbm_drm_master_fd != -1)
- HAL_TBM_WRN("already has TBM DRM MASTER FD: %d\n", tbm_drm_master_fd);
-
- tbm_drm_master_fd = fd;
-
- HAL_TBM_INFO("TBM DRM MASTER FD: %d\n", tbm_drm_master_fd);
-}
-
-EXTERN void
-hal_tbm_drm_helper_unset_tbm_master_fd(void)
-{
- tbm_drm_master_fd = -1;
- HAL_TBM_INFO("TBM DRM MASTER FD: %d\n", tbm_drm_master_fd);
-}
-/* LCOV_EXCL_STOP */
-