Zigbee hal : Implementation of HAL interface
[platform/hal/api/zigbee.git] / src / hal-api-zigbee.c
1 /*
2  * HAL (Hardware Abstract Layer) ZIGBEE API
3  *
4  * Copyright (c) 2021 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 #include <stdio.h>
20 #include <stdint.h>
21 #include <dlfcn.h>
22 #include <dlog.h>
23
24 #include <hal/hal-common.h>
25
26 #include "hal-zigbee-interface.h"
27 #include "hal-zigbee.h"
28 #include "common.h"
29
30 #ifndef EXPORT
31 #define EXPORT __attribute__ ((visibility("default")))
32 #endif
33
34 #define ARRAY_SIZE(name)        (sizeof(name)/sizeof(name[0]))
35
36 static hal_backend_zigbee_funcs *g_zigbee_funcs = NULL;
37
38 EXPORT
39 int hal_zigbee_get_backend(void)
40 {
41         int ret;
42
43         if (g_zigbee_funcs)
44                 return 0;
45
46         ret = hal_common_get_backend(HAL_MODULE_ZIGBEE, (void **)&g_zigbee_funcs);
47         if (ret < 0) {
48                 _E("Failed to get backend\n");
49                 return -EINVAL;
50         }
51
52         return 0;
53 }
54
55 EXPORT
56 int hal_zigbee_put_backend(void)
57 {
58         int ret;
59
60         if (!g_zigbee_funcs)
61                 return -EINVAL;
62
63         ret = hal_common_put_backend(HAL_MODULE_ZIGBEE, (void *)g_zigbee_funcs);
64         if (ret < 0) {
65                 _E("Failed to put backend\n");
66                 return -EINVAL;
67         }
68         g_zigbee_funcs = NULL;
69
70         return 0;
71 }
72
73 EXPORT
74 int hal_zigbee_get_descriptor(void *descriptor)
75 {
76         if (!g_zigbee_funcs)
77                 return -ENOTSUP;
78         return g_zigbee_funcs->get_descriptor(descriptor);
79 }