--- /dev/null
+/*
+ * Copyright (c) 2022 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 __HAL_BACKEND_DEVICE_COMMON_POWER_H__
+#define __HAL_BACKEND_DEVICE_COMMON_POWER_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int hal_backend_device_common_read_wakeup_sources(char ***wakeup_source_name, int *wakeup_source_number);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_BACKEND_DEVICE_COMMON_POWER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2022 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 <errno.h>
+#include <glib.h>
+#include <string.h>
+
+#include "hal-backend-common.h"
+
+#define WAKEUP_SOURCES_PATH "/sys/kernel/debug/wakeup_sources"
+
+#define MAX_NAME_LENGTH 50
+#define MAX_NUM_WAKEUP_SOURCES 100
+#define NUM_INFORMATION 10
+
+struct wakeup_source {
+ char name[MAX_NAME_LENGTH + 1];
+ int active_count;
+ int event_count;
+ int wakeup_count;
+ int expire_count;
+ int active_since;
+ int total_time;
+ int max_time;
+ int last_change;
+ int prevent_suspend_time;
+};
+
+static struct wakeup_source source[MAX_NUM_WAKEUP_SOURCES];
+
+static int read_wakeup_sources(char ***wakeup_source_name, int *wakeup_source_number)
+{
+ char **new_wakeup_source_name;
+ char buf[MAX_NAME_LENGTH + 1] = {0, };
+ struct wakeup_source input = {0, };
+ int source_index = 0; /* for iteration of all wakeup sources */
+ int changed_source_number = 0; /* the number of wakeup sources that increase wakeup_count */
+ int ret;
+ FILE *fp;
+
+ if (!wakeup_source_name || !wakeup_source_number)
+ return -EINVAL;
+
+ fp = fopen(WAKEUP_SOURCES_PATH, "r");
+ if (!fp) {
+ _E("There is no node %s", WAKEUP_SOURCES_PATH);
+ return -errno;
+ }
+
+ for (int i = 0; i < NUM_INFORMATION; ++i) {
+ ret = fscanf(fp, "%50s", buf);
+ if (ret < 1)
+ goto parse_err;
+ }
+
+ new_wakeup_source_name = calloc(MAX_NUM_WAKEUP_SOURCES, sizeof(char*));
+ if (!new_wakeup_source_name) {
+ _E("Failed to allocate memory");
+ return -errno;
+ }
+
+ while (!feof(fp)) {
+ if (source_index >= MAX_NUM_WAKEUP_SOURCES) {
+ _E("Exceed max wakeup source number");
+ for (int i = 0; i < changed_source_number; ++i)
+ free(new_wakeup_source_name[i]);
+ free(new_wakeup_source_name);
+ return -EPERM;
+ }
+
+ ret = fscanf(fp, "%50s %d %d %d %d %d %d %d %d %d\n", input.name,
+ &input.active_count, &input.event_count,
+ &input.wakeup_count, &input.expire_count,
+ &input.active_since, &input.total_time,
+ &input.max_time, &input.last_change,
+ &input.prevent_suspend_time);
+
+ if (ret < 10)
+ goto parse_err;
+
+ /* check whether the wakeup count increases */
+ if (source[source_index].wakeup_count < input.wakeup_count) {
+ new_wakeup_source_name[changed_source_number] =
+ calloc(MAX_NAME_LENGTH + 1, sizeof(char));
+ strncpy(new_wakeup_source_name[changed_source_number++],
+ input.name, MAX_NAME_LENGTH + 1);
+ _D("%s wakeup source detected", input.name);
+ }
+
+ source[source_index++] = input;
+ }
+
+ fclose(fp);
+ *wakeup_source_number = changed_source_number;
+ *wakeup_source_name = new_wakeup_source_name;
+ return 0;
+
+parse_err:
+ _E("Failed to parse %s", WAKEUP_SOURCES_PATH);
+ for (int i = 0; i < changed_source_number; ++i)
+ free(new_wakeup_source_name[i]);
+ free(new_wakeup_source_name);
+ fclose(fp);
+ return -EINVAL;
+}
+
+EXPORT int hal_backend_device_common_read_wakeup_sources(char ***wakeup_source_name, int *wakeup_source_number)
+{
+ return read_wakeup_sources(wakeup_source_name, wakeup_source_number);
+}