Apply next HAL architecture (hal api + backend)
[platform/adaptation/samsung_exynos/device-manager-plugin-artik.git] / hw / board / board.c
1 /*
2  * libdevice-node
3  *
4  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #define _GNU_SOURCE
20 #include <hal/device/hal-board-interface.h>
21 #include <hal/hal-common-interface.h>
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <errno.h>
26 #include <string.h>
27
28 #include "common.h"
29
30 #define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number"
31 #define LINE_LEN 64
32
33 static int get_device_serial(char **out)
34 {
35         FILE *fp;
36         char *line, *p;
37
38         fp = fopen(SERIAL_FILE_PATH, "r");
39         if (!fp)
40                 return -1;
41
42         line = malloc(LINE_LEN);
43         p = fgets(line, LINE_LEN, fp);
44         fclose(fp);
45         if (p == NULL) {
46                 free(line);
47                 return -1;
48         }
49
50         *out = p;
51         return 0;
52 }
53
54 static int board_init(void **data)
55 {
56         hal_backend_board_funcs *board_funcs;
57
58         board_funcs = calloc(1, sizeof(hal_backend_board_funcs));
59         if (!board_funcs)
60                 return -ENOMEM;
61
62         board_funcs->get_device_serial = get_device_serial;
63
64         *data = (void *)board_funcs;
65
66         return 0;
67 }
68
69 static int board_exit(void *data)
70 {
71         if (!data)
72                 return 0;
73
74         free(data);
75         return 0;
76 }
77
78 hal_backend EXPORT hal_backend_device_board_data = {
79         .name = "board",
80         .vendor = "ARTIK",
81         .abi_version = HAL_ABI_VERSION_TIZEN_6_5,
82         .init = board_init,
83         .exit = board_exit,
84 };