From: TaeminYeom Date: Thu, 16 Mar 2023 07:33:59 +0000 (+0900) Subject: Revert "Add privilege check in all public APIs" X-Git-Tag: accepted/tizen/unified/20230321.123152~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3381e305791e2f90679a6c451779f34b31049ce6;p=platform%2Fcore%2Fapi%2Fperipheral-io.git Revert "Add privilege check in all public APIs" Checking privilege has been done by device nodes DAC. So, checking code is not needed. This reverts commit e1eb7906a9c4496e7b4fa89544ae500cbf7d615a. Change-Id: Ia872c5d4b7b6c8b376e2254a79544a5f0bc3ff5b --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 3183c3c..b321988 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ SET(fw_name "${project_prefix}-${service}-${submodule}") PROJECT(${fw_name}) -SET(dependents "dlog glib-2.0 capi-base-common capi-system-info libudev cynara-client cynara-session") +SET(dependents "dlog glib-2.0 capi-base-common capi-system-info libudev") SET(pc_dependents "capi-base-common") SET(CMAKE_INSTALL_PREFIX ${prefix}) diff --git a/packaging/capi-system-peripheral-io.spec b/packaging/capi-system-peripheral-io.spec index 5f10efa..fd4cd35 100644 --- a/packaging/capi-system-peripheral-io.spec +++ b/packaging/capi-system-peripheral-io.spec @@ -16,8 +16,6 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-system-info) -BuildRequires: pkgconfig(cynara-client) -BuildRequires: pkgconfig(cynara-session) BuildRequires: pkgconfig(libudev) %if 0%{?gcov:1} BuildRequires: lcov diff --git a/src/common.c b/src/common.c index c38befa..ed56e67 100644 --- a/src/common.c +++ b/src/common.c @@ -1,21 +1,13 @@ +#include "common.h" #include #include #include #include -#include #include - #include -#include -#include - -#include "common.h" #define UDEV_MONITOR_POLL_TIMEOUT_MILISECONDS 100 #define UDEV_MONITOR_POLL_ITERATIONS 10 //! How many times to poll? Affects the total timeout. -#define BUFF_MAX 255 -#define UID_MAX_LENGTH 16 -#define PRIVILEGE_PERIPHERALIO "http://tizen.org/privilege/peripheralio" int peripheral_lock(const char *file_name) { @@ -53,49 +45,6 @@ bool peripheral_is_feature_supported(const char *feature_name, int *feature_stat return *feature_state == PERIPHERAL_FEATURE_TRUE; } -bool peripheral_is_privilege_supported(void) -{ - cynara *cynara = NULL; - FILE *fp = NULL; - char uid[UID_MAX_LENGTH]; - char *session = NULL; - char smack_label[BUFF_MAX] = {0, }; - int ret; - - if (cynara_initialize(&cynara, NULL) != CYNARA_API_SUCCESS) { - _E("failed to initialize cynara"); - return false; - } - - fp = fopen("/proc/self/attr/current", "r"); - if (fp != NULL) { - int ch = 0; - int idx = 0; - while (EOF != (ch = fgetc(fp))) { - smack_label[idx] = ch; - idx++; - } - fclose(fp); - } - - pid_t pid = getpid(); - session = cynara_session_from_pid(pid); - snprintf(uid, UID_MAX_LENGTH, "%d", getuid()); - uid[UID_MAX_LENGTH - 1] = '\0'; - - ret = cynara_check(cynara, smack_label, session, uid, PRIVILEGE_PERIPHERALIO); - if (session) - free(session); - if (cynara) - cynara_finish(cynara); - if (ret != CYNARA_API_ACCESS_ALLOWED) { - _E("'%s' privilege is not supported", PRIVILEGE_PERIPHERALIO); - return false; - } - - return true; -} - int peripheral_create_udev_monitor(struct udev **udev, struct udev_monitor **monitor, const char *filter_name) { struct udev_monitor *_monitor = NULL; diff --git a/src/common.h b/src/common.h index 42cb9a5..45a1a54 100644 --- a/src/common.h +++ b/src/common.h @@ -100,7 +100,6 @@ bool peripheral_is_feature_supported(const char *feature_name, int *feature_stat return feature == PERIPHERAL_FEATURE_TRUE; \ } -bool peripheral_is_privilege_supported(void); int peripheral_create_udev_monitor(struct udev **udev, struct udev_monitor **monitor, const char *filter_name); typedef bool (*UdevCompareFunc)(struct udev_device *, void *); diff --git a/src/peripheral_adc.c b/src/peripheral_adc.c index e4b7623..788d813 100644 --- a/src/peripheral_adc.c +++ b/src/peripheral_adc.c @@ -56,7 +56,6 @@ static inline void cleanup_handlep(peripheral_adc_h *handle) */ int peripheral_adc_open(int device, int channel, peripheral_adc_h *adc) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "ADC feature is not supported"); RETVM_IF(adc == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc handle"); RETVM_IF(device < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc device number"); @@ -90,7 +89,6 @@ int peripheral_adc_open(int device, int channel, peripheral_adc_h *adc) */ int peripheral_adc_close(peripheral_adc_h adc) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "ADC feature is not supported"); RETVM_IF(adc == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "adc handle is NULL"); @@ -104,7 +102,6 @@ int peripheral_adc_close(peripheral_adc_h adc) */ int peripheral_adc_read(peripheral_adc_h adc, uint32_t *value) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "ADC feature is not supported"); RETVM_IF(adc == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "adc handle is NULL"); RETVM_IF(value == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "adc read value is invalid"); diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 3460df7..0e8fd54 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -84,7 +84,6 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio) { int ret = PERIPHERAL_ERROR_NONE; - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported"); RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio handle"); RETVM_IF(gpio_pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin number"); @@ -127,7 +126,6 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio) */ int peripheral_gpio_close(peripheral_gpio_h gpio) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported"); RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); @@ -145,7 +143,6 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) */ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported"); RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); RETVM_IF((direction < PERIPHERAL_GPIO_DIRECTION_IN) || (direction > PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid direction input"); @@ -178,7 +175,6 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct */ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported"); RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); RETVM_IF((edge < PERIPHERAL_GPIO_EDGE_NONE) || (edge > PERIPHERAL_GPIO_EDGE_BOTH), PERIPHERAL_ERROR_INVALID_PARAMETER, "edge input is invalid"); @@ -276,7 +272,6 @@ static gpointer __peripheral_gpio_poll(void *data) */ int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported"); RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); RETVM_IF(callback == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio interrupted callback is NULL"); @@ -297,7 +292,6 @@ int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_i */ int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported"); RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); @@ -316,7 +310,6 @@ int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) */ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported"); RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); RETVM_IF(value == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio read value is invalid"); @@ -335,7 +328,6 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value) */ int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported"); RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); RETVM_IF((value != 0) && (value != 1), PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio value is invalid"); diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 3711613..cd64453 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -83,7 +83,6 @@ int peripheral_i2c_open_flags(int bus, int address, peripheral_open_flags_e flag int ret; char path[DEV_PATH_FMT_MAX_SIZE] = {0, }; /* space for /dev/i2c-%d */ - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported"); RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c handle"); RETVM_IF(bus < 0 || address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -121,7 +120,6 @@ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c) int peripheral_i2c_close(peripheral_i2c_h i2c) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported"); RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); @@ -147,7 +145,6 @@ static int i2c_readwrite(peripheral_i2c_h i2c, uint8_t read_write, uint32_t size int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data_out, uint32_t length) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported"); RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); RETVM_IF(data_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -168,7 +165,6 @@ int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data_out, uint32_t length int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data_in, uint32_t length) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported"); RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); RETVM_IF(data_in == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -184,7 +180,6 @@ int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data_in, uint32_t length int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data_out) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported"); RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); RETVM_IF(data_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -201,7 +196,6 @@ int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data_in) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported"); RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); @@ -213,7 +207,6 @@ int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_ int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data_out) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported"); RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); RETVM_IF(data_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -230,7 +223,6 @@ int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_ int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data_in) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported"); RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index 63f5945..fe0bafd 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -175,7 +175,6 @@ int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm) { int ret = PERIPHERAL_ERROR_NONE; - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported"); RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm handle"); RETVM_IF(chip < 0 || pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -242,7 +241,6 @@ int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm) int peripheral_pwm_close(peripheral_pwm_h pwm) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported"); RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); @@ -251,7 +249,6 @@ int peripheral_pwm_close(peripheral_pwm_h pwm) int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported"); RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); @@ -268,7 +265,6 @@ int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns) int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported"); RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); @@ -285,7 +281,6 @@ int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns) int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported"); RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); RETVM_IF((polarity < PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH) || (polarity > PERIPHERAL_PWM_POLARITY_ACTIVE_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid polarity parameter"); @@ -303,7 +298,6 @@ int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enable) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported"); RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 5049ef4..8e84a29 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -52,7 +52,7 @@ static inline void cleanup_handlep(peripheral_spi_h *handle) int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); + RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported"); RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi handle"); RETVM_IF(bus < 0 || cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -82,7 +82,6 @@ int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi) int peripheral_spi_close(peripheral_spi_h spi) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported"); RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); @@ -93,7 +92,6 @@ int peripheral_spi_close(peripheral_spi_h spi) int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported"); RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); RETVM_IF((mode < PERIPHERAL_SPI_MODE_0) || (mode > PERIPHERAL_SPI_MODE_3), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi mode parameter"); @@ -106,7 +104,6 @@ int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported"); RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); RETVM_IF((bit_order < PERIPHERAL_SPI_BIT_ORDER_MSB) || (bit_order > PERIPHERAL_SPI_BIT_ORDER_LSB), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid bit order parameter"); @@ -119,7 +116,6 @@ int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_ int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported"); RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); @@ -131,7 +127,6 @@ int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported"); RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); @@ -143,7 +138,6 @@ int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz) int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported"); RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -162,7 +156,6 @@ int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length) int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported"); RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -181,7 +174,6 @@ int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length) int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported"); RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); RETVM_IF(txdata == NULL || rxdata == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index fff6deb..936f3c3 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -101,7 +101,6 @@ static int peripheral_uart_find_devpath(int port, char *buffer, int len) */ int peripheral_uart_open_flags(int port, peripheral_open_flags_e flags, peripheral_uart_h *uart) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart handle"); RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid port number"); @@ -181,7 +180,6 @@ int peripheral_uart_open(int port, peripheral_uart_h *uart) int peripheral_uart_flush(peripheral_uart_h uart) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); @@ -193,7 +191,6 @@ int peripheral_uart_flush(peripheral_uart_h uart) int peripheral_uart_drain(peripheral_uart_h uart) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); @@ -208,7 +205,6 @@ int peripheral_uart_drain(peripheral_uart_h uart) */ int peripheral_uart_close(peripheral_uart_h uart) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); @@ -224,7 +220,6 @@ int peripheral_uart_close(peripheral_uart_h uart) */ int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); RETVM_IF((baud < PERIPHERAL_UART_BAUD_RATE_0) || (baud > PERIPHERAL_UART_BAUD_RATE_230400), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid baud input"); @@ -252,7 +247,6 @@ int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_r int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); RETVM_IF((byte_size < PERIPHERAL_UART_BYTE_SIZE_5BIT) || (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -278,7 +272,6 @@ int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_s int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); RETVM_IF((parity < PERIPHERAL_UART_PARITY_NONE) || (parity > PERIPHERAL_UART_PARITY_ODD), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -316,7 +309,6 @@ int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); RETVM_IF((stop_bits < PERIPHERAL_UART_STOP_BITS_1BIT) || (stop_bits > PERIPHERAL_UART_STOP_BITS_2BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -345,7 +337,6 @@ int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_b */ int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_software_flow_control_e sw_flow_control, peripheral_uart_hardware_flow_control_e hw_flow_control) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); RETVM_IF((sw_flow_control < PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE) || (sw_flow_control > PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid sw_flow_control parameter"); @@ -380,7 +371,6 @@ int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_sof */ int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -397,7 +387,6 @@ int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length) */ int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length) { - RETVM_IF(!peripheral_is_privilege_supported(), PERIPHERAL_ERROR_PERMISSION_DENIED, "Peripheral-io privilege is not supported"); RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");