/* * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved * * 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. */ #include #include #include #include "hal-device-board-interface.h" #include "common.h" static hal_backend_device_board_funcs *hal_device_board_funcs = NULL; int hal_device_board_get_backend(void) { int ret; if (hal_device_board_funcs) return 0; hal_device_board_funcs = calloc(1, sizeof(hal_backend_device_board_funcs)); if (!hal_device_board_funcs) return -ENOMEM; ret = hal_common_get_backend(HAL_MODULE_DEVICE_BOARD, (void **)&hal_device_board_funcs); if (ret < 0) { _E("Failed to get device-board backend"); free(hal_device_board_funcs); hal_device_board_funcs = NULL; return -EINVAL; } return 0; } int hal_device_board_put_backend(void) { if (!hal_device_board_funcs) return 0; hal_common_put_backend(HAL_MODULE_DEVICE_BOARD, (void *)hal_device_board_funcs); free(hal_device_board_funcs); hal_device_board_funcs = NULL; return 0; } int hal_device_board_get_device_serial_number(char *buffer, const int max_len) { int ret ; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->get_device_serial_number) return -ENODEV; return hal_device_board_funcs->get_device_serial_number(buffer, max_len); } int hal_device_board_get_device_revision(int *revision) { int ret ; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->get_device_revision) return -ENODEV; return hal_device_board_funcs->get_device_revision(revision); } int hal_device_board_set_boot_success(void) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->set_boot_success) return -ENODEV; return hal_device_board_funcs->set_boot_success(); } int hal_device_board_clear_boot_mode(void) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->clear_boot_mode) return -ENODEV; return hal_device_board_funcs->clear_boot_mode(); } int hal_device_board_get_boot_mode(char *buffer, const int max_len) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->get_boot_mode) return -ENODEV; return hal_device_board_funcs->get_boot_mode(buffer, max_len); } int hal_device_board_get_boot_reason(char *buffer, const int max_len) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->get_boot_reason) return -ENODEV; return hal_device_board_funcs->get_boot_reason(buffer, max_len); } int hal_device_board_get_current_partition(char *partition_ab) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->get_current_partition) return -ENODEV; return hal_device_board_funcs->get_current_partition(partition_ab); } int hal_device_board_switch_partition(char partition_ab) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->switch_partition) return -ENODEV; return hal_device_board_funcs->switch_partition(partition_ab); } int hal_device_board_set_partition_ab_cloned(void) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->set_partition_ab_cloned) return -ENODEV; return hal_device_board_funcs->set_partition_ab_cloned(); } int hal_device_board_clear_partition_ab_cloned(void) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->clear_partition_ab_cloned) return -ENODEV; return hal_device_board_funcs->clear_partition_ab_cloned(); } int hal_device_board_get_partition_ab_cloned(int *cloned) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->get_partition_ab_cloned) return -ENODEV; return hal_device_board_funcs->get_partition_ab_cloned(cloned); } int hal_device_board_set_partition_status(char partition_ab, const char *status) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->set_partition_status) return -ENODEV; return hal_device_board_funcs->set_partition_status(partition_ab, status); } int hal_device_board_get_partition_status(char partition_ab, char *buffer, const int max_len) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->get_partition_status) return -ENODEV; return hal_device_board_funcs->get_partition_status(partition_ab, buffer, max_len); } int hal_device_board_set_upgrade_status(int status) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->set_upgrade_status) return -ENODEV; return hal_device_board_funcs->set_upgrade_status(status); } int hal_device_board_get_upgrade_status(int *status) { int ret; if (!hal_device_board_funcs) { if ((ret = hal_device_board_get_backend()) < 0) return ret; } if (!hal_device_board_funcs || !hal_device_board_funcs->get_upgrade_status) return -ENODEV; return hal_device_board_funcs->get_upgrade_status(status); }