util: move board, log, privilege file into util directory 17/161017/2
authorSegwon <segwon.han@samsung.com>
Tue, 21 Nov 2017 05:45:33 +0000 (14:45 +0900)
committerSegwon <segwon.han@samsung.com>
Tue, 21 Nov 2017 07:02:58 +0000 (16:02 +0900)
 - prefix match with "peripheral"

Change-Id: Iddb98ac81212712deeb3896c5c39fecf1df220e3
Signed-off-by: Segwon <segwon.han@samsung.com>
18 files changed:
CMakeLists.txt
include/handle/peripheral_handle.h
include/peripheral_bus_board.h [deleted file]
include/peripheral_log.h [deleted file]
include/privilege_checker.h [deleted file]
include/util/peripheral_board.h [new file with mode: 0644]
include/util/peripheral_log.h [new file with mode: 0644]
include/util/peripheral_privilege.h [new file with mode: 0644]
src/gdbus/peripheral_gdbus_gpio.c
src/gdbus/peripheral_gdbus_i2c.c
src/gdbus/peripheral_gdbus_pwm.c
src/gdbus/peripheral_gdbus_spi.c
src/gdbus/peripheral_gdbus_uart.c
src/peripheral_bus.c
src/peripheral_bus_board.c [deleted file]
src/privilege_checker.c [deleted file]
src/util/peripheral_board.c [new file with mode: 0644]
src/util/peripheral_privilege.c [new file with mode: 0644]

index de5c17bb7579912558c24d34e207e1366a6cf874..366f33137e5f75241668751c7c3cee5b5bdf1cce 100644 (file)
@@ -19,13 +19,12 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/handle)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/gdbus)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/interface)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/util)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/gdbus)
 
 SET(PERIPHERAL-BUS "peripheral-bus")
 SET(SRCS
        src/peripheral_bus.c
-       src/peripheral_bus_board.c
-       src/privilege_checker.c
        src/gdbus/peripheral_io_gdbus.c
        src/gdbus/peripheral_gdbus_gpio.c
        src/gdbus/peripheral_gdbus_i2c.c
@@ -42,7 +41,9 @@ SET(SRCS
        src/interface/peripheral_interface_i2c.c
        src/interface/peripheral_interface_pwm.c
        src/interface/peripheral_interface_uart.c
-       src/interface/peripheral_interface_spi.c)
+       src/interface/peripheral_interface_spi.c
+       src/util/peripheral_board.c
+       src/util/peripheral_privilege.c)
 
 INCLUDE(FindPkgConfig)
 pkg_check_modules(pbus_pkgs REQUIRED ${dependents})
index 595ca2c5dca78f4d4874768363ce7061d17cc1dc..cae3177a4a0c1de0db89d3c44629e5693f6ac042 100644 (file)
@@ -19,8 +19,8 @@
 
 #include <gio/gio.h>
 
+#include "peripheral_board.h"
 #include "peripheral_io_gdbus.h"
-#include "peripheral_bus_board.h"
 
 typedef enum {
        PERIPHERAL_BUS_TYPE_GPIO = 0,
diff --git a/include/peripheral_bus_board.h b/include/peripheral_bus_board.h
deleted file mode 100644 (file)
index c84b8b7..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#ifndef __PERIPHERAL_BUS_BOARD_H__
-#define __PERIPHERAL_BUS_BOARD_H__
-
-#define BOARD_DEVICE_TREE      "/proc/device-tree/model"
-#define BOARD_PINS_MAX 4
-#define BOARD_ARGS_MAX 2
-
-typedef enum {
-       PB_BOARD_ARTIK710 = 0,
-       PB_BOARD_ARTIK530,
-       PB_BOARD_ARTIK520,
-       PB_BOARD_RP3_B,
-       PB_BOARD_UNKNOWN,
-} pb_board_type_e;
-
-typedef enum {
-       PB_BOARD_DEV_GPIO = 0,
-       PB_BOARD_DEV_I2C,
-       PB_BOARD_DEV_PWM,
-       PB_BOARD_DEV_UART,
-       PB_BOARD_DEV_SPI,
-       PB_BOARD_DEV_MAX,
-} pb_board_dev_e;
-
-typedef struct {
-       pb_board_type_e type;
-       char *name;
-       char *path;
-} pb_board_type_s;
-
-typedef struct {
-       pb_board_dev_e dev_type;
-       unsigned int pins[BOARD_PINS_MAX];
-       unsigned int num_pins;
-       unsigned int args[BOARD_ARGS_MAX];
-} pb_board_dev_s;
-
-typedef struct {
-       pb_board_type_e type;
-       pb_board_dev_s *dev;
-       unsigned int num_dev;
-} pb_board_s;
-
-pb_board_dev_s *peripheral_bus_board_find_device(pb_board_dev_e dev_type, pb_board_s *board, int arg, ...);
-pb_board_s *peripheral_bus_board_init(void);
-void peripheral_bus_board_deinit(pb_board_s *board);
-
-#endif /* __PERIPHERAL_BUS_BOARD_H__ */
diff --git a/include/peripheral_log.h b/include/peripheral_log.h
deleted file mode 100644 (file)
index a1c91bd..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-#ifndef __PERIPHERAL_LOG_H__
-#define __PERIPHERAL_LOG_H__
-
-// #include <unistd.h>
-#include <dlog.h>
-
-#undef LOG_TAG
-#define LOG_TAG "PERIPHERAL-BUS"
-
-#define _E(fmt, arg...) LOGE(fmt, ##arg)
-#define _D(fmt, arg...) LOGD(fmt, ##arg)
-#define _W(fmt, arg...) LOGW(fmt, ##arg)
-
-#define RET_IF(expr) \
-       do { \
-               if (expr) { \
-                       _E("(%s)", #expr); \
-                       return; \
-               } \
-       } while (0)
-#define RETV_IF(expr, val) \
-       do {\
-               if (expr) { \
-                       _E("(%s)", #expr); \
-                       return (val); \
-               } \
-       } while (0)
-#define RETM_IF(expr, fmt, arg...) \
-       do {\
-               if (expr) { \
-                       _E(fmt, ##arg); \
-                       return; \
-               } \
-       } while (0)
-#define RETVM_IF(expr, val, fmt, arg...) \
-       do {\
-               if (expr) { \
-                       _E(fmt, ##arg); \
-                       return (val); \
-               } \
-       } while (0)
-
-#endif /* __PERIPHERAL_COMMON_H__ */
diff --git a/include/privilege_checker.h b/include/privilege_checker.h
deleted file mode 100644 (file)
index e225bf7..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#ifndef __PRIVILEGE_CHECKER_H__
-#define __PRIVILEGE_CHECKER_H__
-
-#include <gio/gio.h>
-
-void peripheral_privilege_init(void);
-void peripheral_privilege_deinit(void);
-int peripheral_privilege_check(GDBusMethodInvocation *invocation, GDBusConnection *connection);
-
-#endif /* __PRIVILEGE_CHECKER_H__ */
diff --git a/include/util/peripheral_board.h b/include/util/peripheral_board.h
new file mode 100644 (file)
index 0000000..c84b8b7
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __PERIPHERAL_BUS_BOARD_H__
+#define __PERIPHERAL_BUS_BOARD_H__
+
+#define BOARD_DEVICE_TREE      "/proc/device-tree/model"
+#define BOARD_PINS_MAX 4
+#define BOARD_ARGS_MAX 2
+
+typedef enum {
+       PB_BOARD_ARTIK710 = 0,
+       PB_BOARD_ARTIK530,
+       PB_BOARD_ARTIK520,
+       PB_BOARD_RP3_B,
+       PB_BOARD_UNKNOWN,
+} pb_board_type_e;
+
+typedef enum {
+       PB_BOARD_DEV_GPIO = 0,
+       PB_BOARD_DEV_I2C,
+       PB_BOARD_DEV_PWM,
+       PB_BOARD_DEV_UART,
+       PB_BOARD_DEV_SPI,
+       PB_BOARD_DEV_MAX,
+} pb_board_dev_e;
+
+typedef struct {
+       pb_board_type_e type;
+       char *name;
+       char *path;
+} pb_board_type_s;
+
+typedef struct {
+       pb_board_dev_e dev_type;
+       unsigned int pins[BOARD_PINS_MAX];
+       unsigned int num_pins;
+       unsigned int args[BOARD_ARGS_MAX];
+} pb_board_dev_s;
+
+typedef struct {
+       pb_board_type_e type;
+       pb_board_dev_s *dev;
+       unsigned int num_dev;
+} pb_board_s;
+
+pb_board_dev_s *peripheral_bus_board_find_device(pb_board_dev_e dev_type, pb_board_s *board, int arg, ...);
+pb_board_s *peripheral_bus_board_init(void);
+void peripheral_bus_board_deinit(pb_board_s *board);
+
+#endif /* __PERIPHERAL_BUS_BOARD_H__ */
diff --git a/include/util/peripheral_log.h b/include/util/peripheral_log.h
new file mode 100644 (file)
index 0000000..535ab04
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+#ifndef __PERIPHERAL_LOG_H__
+#define __PERIPHERAL_LOG_H__
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "PERIPHERAL-BUS"
+
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+
+#define RET_IF(expr) \
+       do { \
+               if (expr) { \
+                       _E("(%s)", #expr); \
+                       return; \
+               } \
+       } while (0)
+#define RETV_IF(expr, val) \
+       do {\
+               if (expr) { \
+                       _E("(%s)", #expr); \
+                       return (val); \
+               } \
+       } while (0)
+#define RETM_IF(expr, fmt, arg...) \
+       do {\
+               if (expr) { \
+                       _E(fmt, ##arg); \
+                       return; \
+               } \
+       } while (0)
+#define RETVM_IF(expr, val, fmt, arg...) \
+       do {\
+               if (expr) { \
+                       _E(fmt, ##arg); \
+                       return (val); \
+               } \
+       } while (0)
+
+#endif /* __PERIPHERAL_COMMON_H__ */
diff --git a/include/util/peripheral_privilege.h b/include/util/peripheral_privilege.h
new file mode 100644 (file)
index 0000000..e225bf7
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __PRIVILEGE_CHECKER_H__
+#define __PRIVILEGE_CHECKER_H__
+
+#include <gio/gio.h>
+
+void peripheral_privilege_init(void);
+void peripheral_privilege_deinit(void);
+int peripheral_privilege_check(GDBusMethodInvocation *invocation, GDBusConnection *connection);
+
+#endif /* __PRIVILEGE_CHECKER_H__ */
index 4bb0fe3316ed849a32fc0f4f668c1075da929ead..28174244aef6367df20830dcecd4058825fa6058 100644 (file)
 #include <peripheral_io.h>
 #include <gio/gunixfdlist.h>
 
+#include "peripheral_log.h"
+#include "peripheral_privilege.h"
 #include "peripheral_io_gdbus.h"
 #include "peripheral_handle.h"
 #include "peripheral_handle_gpio.h"
-#include "peripheral_log.h"
 #include "peripheral_gdbus_gpio.h"
-#include "privilege_checker.h"
 
 static void __gpio_on_name_vanished(GDBusConnection *connection,
                const gchar     *name,
index 5f233539b8488a8b282dee76f83f32b3646b3680..05b29ce67231499ca7dcc353f29f82fda1b00560 100644 (file)
 
 #include <peripheral_io.h>
 
+#include "peripheral_log.h"
+#include "peripheral_privilege.h"
 #include "peripheral_io_gdbus.h"
 #include "peripheral_handle.h"
 #include "peripheral_handle_i2c.h"
-#include "peripheral_log.h"
 #include "peripheral_gdbus_i2c.h"
-#include "privilege_checker.h"
+
 
 static void __i2c_on_name_vanished(GDBusConnection *connection,
                const gchar     *name,
index 2f1adf889ccdcdba0a38eb533eb8ba1b4e382344..ef3d54d31c361313c5ddac6d861f3ad1f67dab5b 100644 (file)
 
 #include <peripheral_io.h>
 
+#include "peripheral_log.h"
+#include "peripheral_privilege.h"
 #include "peripheral_io_gdbus.h"
 #include "peripheral_handle.h"
 #include "peripheral_handle_pwm.h"
-#include "peripheral_log.h"
 #include "peripheral_gdbus_pwm.h"
-#include "privilege_checker.h"
 
 static void __pwm_on_name_vanished(GDBusConnection *connection,
                const gchar     *name,
index 9910670ab1cae171a1ac9fa235c829f338f514db..0930323b3227335e2f915a7713b0b5ef56042b4b 100644 (file)
 
 #include <peripheral_io.h>
 
+#include "peripheral_log.h"
+#include "peripheral_privilege.h"
 #include "peripheral_io_gdbus.h"
 #include "peripheral_handle.h"
 #include "peripheral_handle_spi.h"
-#include "peripheral_log.h"
 #include "peripheral_gdbus_spi.h"
-#include "privilege_checker.h"
 
 static void __spi_on_name_vanished(GDBusConnection *connection,
                const gchar     *name,
index 740001c7c3aa4604cbb589074d0498bfa838d1ed..6732fe98081a105ffb389df5bf31458c27c95e57 100644 (file)
 
 #include <peripheral_io.h>
 
+#include "peripheral_log.h"
+#include "peripheral_privilege.h"
 #include "peripheral_io_gdbus.h"
 #include "peripheral_handle.h"
 #include "peripheral_handle_uart.h"
-#include "peripheral_log.h"
 #include "peripheral_gdbus_uart.h"
-#include "privilege_checker.h"
 
 static void __uart_on_name_vanished(GDBusConnection *connection,
                const gchar     *name,
index 1d1411274c383793f50b2cd17f1ba82dd9b2aa45..ffda8746af93ebbca27918a76c80deaaffc7726c 100644 (file)
 
 #include <peripheral_io.h>
 
-#include "peripheral_io_gdbus.h"
-#include "peripheral_handle.h"
 #include "peripheral_log.h"
+#include "peripheral_privilege.h"
+#include "peripheral_handle.h"
+#include "peripheral_io_gdbus.h"
 #include "peripheral_gdbus_gpio.h"
 #include "peripheral_gdbus_i2c.h"
 #include "peripheral_gdbus_pwm.h"
 #include "peripheral_gdbus_spi.h"
 #include "peripheral_gdbus_uart.h"
 
-#include "privilege_checker.h"
-
 #define PERIPHERAL_GDBUS_GPIO_PATH     "/Org/Tizen/Peripheral_io/Gpio"
 #define PERIPHERAL_GDBUS_I2C_PATH      "/Org/Tizen/Peripheral_io/I2c"
 #define PERIPHERAL_GDBUS_PWM_PATH      "/Org/Tizen/Peripheral_io/Pwm"
diff --git a/src/peripheral_bus_board.c b/src/peripheral_bus_board.c
deleted file mode 100644 (file)
index 23210c2..0000000
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <iniparser.h>
-
-#include <peripheral_io.h>
-
-#include "peripheral_bus_board.h"
-#include "peripheral_log.h"
-
-#define STR_BUF_MAX 255
-
-#define BOARD_INI_BASE SYSCONFDIR "/peripheral-bus/"
-
-#define BOARD_INI_ARTIK710_PATH BOARD_INI_BASE "pio_board_artik710.ini"
-#define BOARD_INI_ARTIK520_PATH BOARD_INI_BASE "pio_board_artik520.ini"
-#define BOARD_INI_RP3_B_PATH    BOARD_INI_BASE "pio_board_rp3_b.ini"
-#define BOARD_INI_UNKNOWN_PATH  BOARD_INI_BASE "pio_board_unknown.ini"
-
-static const pb_board_type_s pb_board_type[] = {
-       {PB_BOARD_ARTIK710, "artik710 raptor", BOARD_INI_ARTIK710_PATH},
-       {PB_BOARD_ARTIK530, "artik530 raptor", BOARD_INI_ARTIK710_PATH},
-       {PB_BOARD_ARTIK520, "ARTIK5 board",    BOARD_INI_ARTIK520_PATH},
-       {PB_BOARD_RP3_B,    "Raspberry Pi 3 Model B", BOARD_INI_RP3_B_PATH},
-       {PB_BOARD_UNKNOWN,  "unknown board",   BOARD_INI_UNKNOWN_PATH},
-};
-
-static int peripheral_bus_board_get_device_type(char *string)
-{
-       if (0 == strncmp(string, "gpio", strlen("gpio")))
-               return PB_BOARD_DEV_GPIO;
-       else if (0 == strncmp(string, "i2c", strlen("i2c")))
-               return PB_BOARD_DEV_I2C;
-       else if (0 == strncmp(string, "pwm", strlen("pwm")))
-               return PB_BOARD_DEV_PWM;
-       else if (0 == strncmp(string, "uart", strlen("uart")))
-               return PB_BOARD_DEV_UART;
-       else if (0 == strncmp(string, "spi", strlen("spi")))
-               return PB_BOARD_DEV_SPI;
-
-       return -1;
-}
-
-static void peripheral_bus_board_ini_parse_key(pb_board_dev_e type, char *string, unsigned int *args)
-{
-       switch (type) {
-       case PB_BOARD_DEV_GPIO:
-               sscanf(string, "%*50[^0-9]%d", &args[0]);
-               break;
-       case PB_BOARD_DEV_I2C:
-               sscanf(string, "%*50[^-]-%d", &args[0]);
-               break;
-       case PB_BOARD_DEV_PWM:
-               sscanf(string, "%*50[^0-9]%d%*50[^0-9]%d", &args[0], &args[1]);
-               break;
-       case PB_BOARD_DEV_UART:
-               sscanf(string, "%*50[^0-9]%d", &args[0]);
-               break;
-       case PB_BOARD_DEV_SPI:
-               sscanf(string, "%*50[^0-9]%d.%d", &args[0], &args[1]);
-               break;
-       default:
-               break;
-       }
-}
-
-static int peripheral_bus_board_ini_parse_pins(char *string, unsigned int *pins)
-{
-       const char delimiter[] = ", ";
-       int cnt_pins = 0;
-       char *token, *ptr = NULL;
-
-       if (string == NULL) return 0;
-
-       token = strtok_r(string, delimiter, &ptr);
-       while (token) {
-               if (cnt_pins >= BOARD_PINS_MAX) break;
-
-               pins[cnt_pins++] = atoi(token);
-               token = strtok_r(NULL, delimiter, &ptr);
-       }
-
-       return cnt_pins;
-}
-
-static int peripheral_bus_board_ini_get_nkeys(dictionary *dict)
-{
-       int i, sec_num, key_num, ret = 0;
-       char *section;
-
-       sec_num = iniparser_getnsec(dict);
-       for (i = 0; i < sec_num; i++) {
-               section = iniparser_getsecname(dict, i);
-               key_num = iniparser_getsecnkeys(dict, section);
-               if (key_num <= 0) continue;
-               ret += key_num;
-       }
-
-       return ret;
-}
-
-static int peripheral_bus_board_get_type(void)
-{
-       int fd, i, ret = 0;
-       char str_buf[STR_BUF_MAX] = {0};
-       int type = PB_BOARD_UNKNOWN;
-
-       fd = open(BOARD_DEVICE_TREE, O_RDONLY);
-       if (fd < 0) {
-               strerror_r(errno, str_buf, STR_BUF_MAX);
-               _E("Cannot open %s, errmsg : %s", BOARD_DEVICE_TREE, str_buf);
-               return -ENXIO;
-       }
-
-       ret = read(fd, str_buf, STR_BUF_MAX);
-       if (ret < 0) {
-               _E("Failed to read model information, path: %s, ret: %d", BOARD_DEVICE_TREE, ret);
-               close(fd);
-               return -EIO;
-       }
-
-       str_buf[STR_BUF_MAX - 1] = '\0';
-
-       for (i = 0; i < PB_BOARD_UNKNOWN; i++) {
-               if (strstr(str_buf, pb_board_type[i].name)) {
-                       type = pb_board_type[i].type;
-                       break;
-               }
-       }
-
-       close(fd);
-
-       return type;
-}
-
-static pb_board_s *peripheral_bus_board_get_info()
-{
-       dictionary *dict = NULL;
-       int i, j, ret;
-       int sec_num, key_num, cnt_key = 0;
-       pb_board_dev_s *dev;
-       pb_board_dev_e enum_dev;
-       pb_board_s *board;
-
-       board = (pb_board_s*)calloc(1, sizeof(pb_board_s));
-       if (board == NULL) {
-               _E("Failed to allocate pb_board_s");
-               return NULL;
-       }
-
-       ret = peripheral_bus_board_get_type();
-       if (ret < 0) {
-               _E("Failed to get board type");
-               goto err_get_type;
-       }
-
-       board->type = (pb_board_type_e)ret;
-       dict = iniparser_load(pb_board_type[board->type].path);
-       if (dict == NULL) {
-               _E("Failed to load %s", pb_board_type[board->type].path);
-               goto err_get_type;
-       }
-
-       board->num_dev = peripheral_bus_board_ini_get_nkeys(dict);
-       if (board->num_dev == 0) {
-               _E("There is no device to open");
-               goto err_get_nkeys;
-       }
-
-       board->dev = calloc(board->num_dev, sizeof(pb_board_dev_s));
-       if (board->dev == NULL) {
-               _E("Failed to allocate pb_board_dev_s");
-               goto err_get_nkeys;
-       }
-
-       sec_num = iniparser_getnsec(dict);
-       for (i = 0; i < sec_num; i++) {
-               char *section, *key_str;
-               char **key_list = NULL;
-
-               section = iniparser_getsecname(dict, i);
-               ret = peripheral_bus_board_get_device_type(section);
-               if (ret < 0)
-                       continue;
-
-               enum_dev = (pb_board_dev_e)ret;
-               key_list = iniparser_getseckeys(dict, section);
-               key_num = iniparser_getsecnkeys(dict, section);
-               if (key_num <= 0)
-                       continue;
-
-               for (j = 0; j < key_num; j++) {
-                       dev = &board->dev[cnt_key];
-                       dev->dev_type = enum_dev;
-                       key_str = iniparser_getstring(dict, key_list[j], NULL);
-                       peripheral_bus_board_ini_parse_key(dev->dev_type, key_list[j], dev->args);
-                       dev->num_pins = peripheral_bus_board_ini_parse_pins(key_str, dev->pins);
-                       cnt_key++;
-               }
-       }
-
-       iniparser_freedict(dict);
-
-       return board;
-
-err_get_nkeys:
-       iniparser_freedict(dict);
-
-err_get_type:
-       free(board);
-       return NULL;
-}
-
-pb_board_dev_s *peripheral_bus_board_find_device(pb_board_dev_e dev_type, pb_board_s *board, int arg, ...)
-{
-       int i, args[2] = {0, };
-       va_list ap;
-
-       RETV_IF(board == NULL, false);
-
-       args[0] = arg;
-       if (dev_type == PB_BOARD_DEV_PWM || dev_type == PB_BOARD_DEV_SPI) {
-               va_start(ap, arg);
-               args[1] = va_arg(ap, int);
-               va_end(ap);
-       }
-
-       for (i = 0; i < board->num_dev; i++) {
-               if (board->dev[i].dev_type != dev_type) continue;
-
-               if (board->dev[i].args[0] == args[0] && board->dev[i].args[1] == args[1])
-                       return &board->dev[i];
-       }
-
-       return NULL;
-}
-
-pb_board_s *peripheral_bus_board_init(void)
-{
-       pb_board_s *board;
-
-       board = peripheral_bus_board_get_info();
-
-       return board;
-}
-
-void peripheral_bus_board_deinit(pb_board_s *board)
-{
-       if (board) {
-               if (board->dev)
-                       free(board->dev);
-
-               free(board);
-       }
-}
diff --git a/src/privilege_checker.c b/src/privilege_checker.c
deleted file mode 100644 (file)
index 37f9dd5..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * 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 <cynara-creds-gdbus.h>
-#include <cynara-client.h>
-#include <cynara-session.h>
-
-#include "privilege_checker.h"
-#include "peripheral_log.h"
-
-#define PERIPHERAL_PRIVILEGE "http://tizen.org/privilege/peripheralio"
-
-#define CACHE_SIZE  100
-
-static cynara *__cynara;
-
-void peripheral_privilege_init(void)
-{
-       int err;
-       cynara_configuration* conf = NULL;
-
-       err = cynara_configuration_create(&conf);
-       RETM_IF(err != CYNARA_API_SUCCESS, "Failed to create cynara configuration");
-
-       err = cynara_configuration_set_cache_size(conf, CACHE_SIZE);
-       if (err != CYNARA_API_SUCCESS) {
-               _E("Failed to set cynara cache size");
-               cynara_configuration_destroy(conf);
-               return;
-       }
-
-       err = cynara_initialize(&__cynara, conf);
-       cynara_configuration_destroy(conf);
-       if (err != CYNARA_API_SUCCESS) {
-               _E("Failed to initialize cynara");
-               __cynara = NULL;
-               return;
-       }
-
-       _D("Cynara initialized");
-}
-
-void peripheral_privilege_deinit(void)
-{
-       if (__cynara)
-               cynara_finish(__cynara);
-
-       _D("Cynara deinitialized");
-}
-
-int peripheral_privilege_check(GDBusMethodInvocation *invocation, GDBusConnection *connection)
-{
-       int ret;
-       int pid;
-       const char *sender;
-       char *session;
-       char *client;
-       char *user;
-
-       sender = g_dbus_method_invocation_get_sender(invocation);
-
-       cynara_creds_gdbus_get_pid(connection, sender, &pid);
-       session = cynara_session_from_pid(pid);
-
-       cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT, &client);
-       cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT, &user);
-
-       if (!session || !client || !user) {
-               _E("Failed to get client info");
-               return -1;
-       }
-
-       ret = cynara_check(__cynara, client, session, user, PERIPHERAL_PRIVILEGE);
-       if (ret != 0) {
-               g_free(session);
-               g_free(client);
-               g_free(user);
-               return -EACCES;
-       }
-
-       g_free(session);
-       g_free(client);
-       g_free(user);
-
-       return 0;
-}
diff --git a/src/util/peripheral_board.c b/src/util/peripheral_board.c
new file mode 100644 (file)
index 0000000..02d7f3d
--- /dev/null
@@ -0,0 +1,273 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <iniparser.h>
+
+#include <peripheral_io.h>
+
+#include "peripheral_board.h"
+#include "peripheral_log.h"
+
+#define STR_BUF_MAX 255
+
+#define BOARD_INI_BASE SYSCONFDIR "/peripheral-bus/"
+
+#define BOARD_INI_ARTIK710_PATH BOARD_INI_BASE "pio_board_artik710.ini"
+#define BOARD_INI_ARTIK520_PATH BOARD_INI_BASE "pio_board_artik520.ini"
+#define BOARD_INI_RP3_B_PATH    BOARD_INI_BASE "pio_board_rp3_b.ini"
+#define BOARD_INI_UNKNOWN_PATH  BOARD_INI_BASE "pio_board_unknown.ini"
+
+static const pb_board_type_s pb_board_type[] = {
+       {PB_BOARD_ARTIK710, "artik710 raptor", BOARD_INI_ARTIK710_PATH},
+       {PB_BOARD_ARTIK530, "artik530 raptor", BOARD_INI_ARTIK710_PATH},
+       {PB_BOARD_ARTIK520, "ARTIK5 board",    BOARD_INI_ARTIK520_PATH},
+       {PB_BOARD_RP3_B,    "Raspberry Pi 3 Model B", BOARD_INI_RP3_B_PATH},
+       {PB_BOARD_UNKNOWN,  "unknown board",   BOARD_INI_UNKNOWN_PATH},
+};
+
+static int peripheral_bus_board_get_device_type(char *string)
+{
+       if (0 == strncmp(string, "gpio", strlen("gpio")))
+               return PB_BOARD_DEV_GPIO;
+       else if (0 == strncmp(string, "i2c", strlen("i2c")))
+               return PB_BOARD_DEV_I2C;
+       else if (0 == strncmp(string, "pwm", strlen("pwm")))
+               return PB_BOARD_DEV_PWM;
+       else if (0 == strncmp(string, "uart", strlen("uart")))
+               return PB_BOARD_DEV_UART;
+       else if (0 == strncmp(string, "spi", strlen("spi")))
+               return PB_BOARD_DEV_SPI;
+
+       return -1;
+}
+
+static void peripheral_bus_board_ini_parse_key(pb_board_dev_e type, char *string, unsigned int *args)
+{
+       switch (type) {
+       case PB_BOARD_DEV_GPIO:
+               sscanf(string, "%*50[^0-9]%d", &args[0]);
+               break;
+       case PB_BOARD_DEV_I2C:
+               sscanf(string, "%*50[^-]-%d", &args[0]);
+               break;
+       case PB_BOARD_DEV_PWM:
+               sscanf(string, "%*50[^0-9]%d%*50[^0-9]%d", &args[0], &args[1]);
+               break;
+       case PB_BOARD_DEV_UART:
+               sscanf(string, "%*50[^0-9]%d", &args[0]);
+               break;
+       case PB_BOARD_DEV_SPI:
+               sscanf(string, "%*50[^0-9]%d.%d", &args[0], &args[1]);
+               break;
+       default:
+               break;
+       }
+}
+
+static int peripheral_bus_board_ini_parse_pins(char *string, unsigned int *pins)
+{
+       const char delimiter[] = ", ";
+       int cnt_pins = 0;
+       char *token, *ptr = NULL;
+
+       if (string == NULL) return 0;
+
+       token = strtok_r(string, delimiter, &ptr);
+       while (token) {
+               if (cnt_pins >= BOARD_PINS_MAX) break;
+
+               pins[cnt_pins++] = atoi(token);
+               token = strtok_r(NULL, delimiter, &ptr);
+       }
+
+       return cnt_pins;
+}
+
+static int peripheral_bus_board_ini_get_nkeys(dictionary *dict)
+{
+       int i, sec_num, key_num, ret = 0;
+       char *section;
+
+       sec_num = iniparser_getnsec(dict);
+       for (i = 0; i < sec_num; i++) {
+               section = iniparser_getsecname(dict, i);
+               key_num = iniparser_getsecnkeys(dict, section);
+               if (key_num <= 0) continue;
+               ret += key_num;
+       }
+
+       return ret;
+}
+
+static int peripheral_bus_board_get_type(void)
+{
+       int fd, i, ret = 0;
+       char str_buf[STR_BUF_MAX] = {0};
+       int type = PB_BOARD_UNKNOWN;
+
+       fd = open(BOARD_DEVICE_TREE, O_RDONLY);
+       if (fd < 0) {
+               strerror_r(errno, str_buf, STR_BUF_MAX);
+               _E("Cannot open %s, errmsg : %s", BOARD_DEVICE_TREE, str_buf);
+               return -ENXIO;
+       }
+
+       ret = read(fd, str_buf, STR_BUF_MAX);
+       if (ret < 0) {
+               _E("Failed to read model information, path: %s, ret: %d", BOARD_DEVICE_TREE, ret);
+               close(fd);
+               return -EIO;
+       }
+
+       str_buf[STR_BUF_MAX - 1] = '\0';
+
+       for (i = 0; i < PB_BOARD_UNKNOWN; i++) {
+               if (strstr(str_buf, pb_board_type[i].name)) {
+                       type = pb_board_type[i].type;
+                       break;
+               }
+       }
+
+       close(fd);
+
+       return type;
+}
+
+static pb_board_s *peripheral_bus_board_get_info()
+{
+       dictionary *dict = NULL;
+       int i, j, ret;
+       int sec_num, key_num, cnt_key = 0;
+       pb_board_dev_s *dev;
+       pb_board_dev_e enum_dev;
+       pb_board_s *board;
+
+       board = (pb_board_s*)calloc(1, sizeof(pb_board_s));
+       if (board == NULL) {
+               _E("Failed to allocate pb_board_s");
+               return NULL;
+       }
+
+       ret = peripheral_bus_board_get_type();
+       if (ret < 0) {
+               _E("Failed to get board type");
+               goto err_get_type;
+       }
+
+       board->type = (pb_board_type_e)ret;
+       dict = iniparser_load(pb_board_type[board->type].path);
+       if (dict == NULL) {
+               _E("Failed to load %s", pb_board_type[board->type].path);
+               goto err_get_type;
+       }
+
+       board->num_dev = peripheral_bus_board_ini_get_nkeys(dict);
+       if (board->num_dev == 0) {
+               _E("There is no device to open");
+               goto err_get_nkeys;
+       }
+
+       board->dev = calloc(board->num_dev, sizeof(pb_board_dev_s));
+       if (board->dev == NULL) {
+               _E("Failed to allocate pb_board_dev_s");
+               goto err_get_nkeys;
+       }
+
+       sec_num = iniparser_getnsec(dict);
+       for (i = 0; i < sec_num; i++) {
+               char *section, *key_str;
+               char **key_list = NULL;
+
+               section = iniparser_getsecname(dict, i);
+               ret = peripheral_bus_board_get_device_type(section);
+               if (ret < 0)
+                       continue;
+
+               enum_dev = (pb_board_dev_e)ret;
+               key_list = iniparser_getseckeys(dict, section);
+               key_num = iniparser_getsecnkeys(dict, section);
+               if (key_num <= 0)
+                       continue;
+
+               for (j = 0; j < key_num; j++) {
+                       dev = &board->dev[cnt_key];
+                       dev->dev_type = enum_dev;
+                       key_str = iniparser_getstring(dict, key_list[j], NULL);
+                       peripheral_bus_board_ini_parse_key(dev->dev_type, key_list[j], dev->args);
+                       dev->num_pins = peripheral_bus_board_ini_parse_pins(key_str, dev->pins);
+                       cnt_key++;
+               }
+       }
+
+       iniparser_freedict(dict);
+
+       return board;
+
+err_get_nkeys:
+       iniparser_freedict(dict);
+
+err_get_type:
+       free(board);
+       return NULL;
+}
+
+pb_board_dev_s *peripheral_bus_board_find_device(pb_board_dev_e dev_type, pb_board_s *board, int arg, ...)
+{
+       int i, args[2] = {0, };
+       va_list ap;
+
+       RETV_IF(board == NULL, false);
+
+       args[0] = arg;
+       if (dev_type == PB_BOARD_DEV_PWM || dev_type == PB_BOARD_DEV_SPI) {
+               va_start(ap, arg);
+               args[1] = va_arg(ap, int);
+               va_end(ap);
+       }
+
+       for (i = 0; i < board->num_dev; i++) {
+               if (board->dev[i].dev_type != dev_type) continue;
+
+               if (board->dev[i].args[0] == args[0] && board->dev[i].args[1] == args[1])
+                       return &board->dev[i];
+       }
+
+       return NULL;
+}
+
+pb_board_s *peripheral_bus_board_init(void)
+{
+       pb_board_s *board;
+
+       board = peripheral_bus_board_get_info();
+
+       return board;
+}
+
+void peripheral_bus_board_deinit(pb_board_s *board)
+{
+       if (board) {
+               if (board->dev)
+                       free(board->dev);
+
+               free(board);
+       }
+}
diff --git a/src/util/peripheral_privilege.c b/src/util/peripheral_privilege.c
new file mode 100644 (file)
index 0000000..4abddd1
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 <cynara-creds-gdbus.h>
+#include <cynara-client.h>
+#include <cynara-session.h>
+
+#include "peripheral_privilege.h"
+#include "peripheral_log.h"
+
+#define PERIPHERAL_PRIVILEGE "http://tizen.org/privilege/peripheralio"
+
+#define CACHE_SIZE  100
+
+static cynara *__cynara;
+
+void peripheral_privilege_init(void)
+{
+       int err;
+       cynara_configuration* conf = NULL;
+
+       err = cynara_configuration_create(&conf);
+       RETM_IF(err != CYNARA_API_SUCCESS, "Failed to create cynara configuration");
+
+       err = cynara_configuration_set_cache_size(conf, CACHE_SIZE);
+       if (err != CYNARA_API_SUCCESS) {
+               _E("Failed to set cynara cache size");
+               cynara_configuration_destroy(conf);
+               return;
+       }
+
+       err = cynara_initialize(&__cynara, conf);
+       cynara_configuration_destroy(conf);
+       if (err != CYNARA_API_SUCCESS) {
+               _E("Failed to initialize cynara");
+               __cynara = NULL;
+               return;
+       }
+
+       _D("Cynara initialized");
+}
+
+void peripheral_privilege_deinit(void)
+{
+       if (__cynara)
+               cynara_finish(__cynara);
+
+       _D("Cynara deinitialized");
+}
+
+int peripheral_privilege_check(GDBusMethodInvocation *invocation, GDBusConnection *connection)
+{
+       int ret;
+       int pid;
+       const char *sender;
+       char *session;
+       char *client;
+       char *user;
+
+       sender = g_dbus_method_invocation_get_sender(invocation);
+
+       cynara_creds_gdbus_get_pid(connection, sender, &pid);
+       session = cynara_session_from_pid(pid);
+
+       cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT, &client);
+       cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT, &user);
+
+       if (!session || !client || !user) {
+               _E("Failed to get client info");
+               return -1;
+       }
+
+       ret = cynara_check(__cynara, client, session, user, PERIPHERAL_PRIVILEGE);
+       if (ret != 0) {
+               g_free(session);
+               g_free(client);
+               g_free(user);
+               return -EACCES;
+       }
+
+       g_free(session);
+       g_free(client);
+       g_free(user);
+
+       return 0;
+}