1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/*
* HAL (Hardware Abstract Layer) UWB API
*
* Copyright (c) 2021 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 <stdint.h>
#include <dlfcn.h>
#include <dlog.h>
#include <hal/hal-common.h>
#include "hal-uwb-interface.h"
#include "hal-uwb.h"
#include "common.h"
#ifndef EXPORT
#define EXPORT __attribute__ ((visibility("default")))
#endif
#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
static hal_backend_uwb_funcs *g_uwb_funcs = NULL;
EXPORT
int hal_uwb_get_backend(void)
{
int ret;
if (g_uwb_funcs)
return 0;
g_uwb_funcs = calloc(1, sizeof(hal_backend_uwb_funcs));
if (!g_uwb_funcs)
return -ENOMEM;
ret = hal_common_get_backend(HAL_MODULE_UWB, (void **)&g_uwb_funcs);
if (ret < 0) {
free(g_uwb_funcs);
g_uwb_funcs = NULL;
return -ENOTSUP;
}
return 0;
}
EXPORT
int hal_uwb_put_backend(void)
{
if (!g_uwb_funcs)
return -EINVAL;
hal_common_put_backend(HAL_MODULE_UWB, (void *)g_uwb_funcs);
free(g_uwb_funcs);
g_uwb_funcs = NULL;
return 0;
}
EXPORT
int hal_uwb_start(uwb_hal_event_cbs_s *event_cbs)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->start)
return -ENOTSUP;
return g_uwb_funcs->start(event_cbs);
}
EXPORT
int hal_uwb_stop(void)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->stop)
return -ENOTSUP;
return g_uwb_funcs->stop();
}
EXPORT
int hal_uwb_test(void)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->test)
return -ENOTSUP;
return g_uwb_funcs->test();
}
EXPORT
int hal_uwb_reset(void)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->reset)
return -ENOTSUP;
return g_uwb_funcs->reset();
}
EXPORT
int hal_uwb_factory_reset(void)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->factory_reset)
return -ENOTSUP;
return g_uwb_funcs->factory_reset();
}
EXPORT
int hal_uwb_enable_network(void)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->enable_network)
return -ENOTSUP;
return g_uwb_funcs->enable_network();
}
EXPORT
int hal_uwb_disable_network(void)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->disable_network)
return -ENOTSUP;
return g_uwb_funcs->disable_network();
}
EXPORT
int hal_uwb_get_network_info(uwb_hal_network_s **network_info)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->get_network_info)
return -ENOTSUP;
return g_uwb_funcs->get_network_info(network_info);
}
EXPORT
int hal_uwb_set_configurations(uint16_t node_id, const GVariant *configurations)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->set_configurations)
return -ENOTSUP;
return g_uwb_funcs->set_configurations(node_id, configurations);
}
EXPORT
int hal_uwb_get_configurations(uint16_t node_id, GVariant **configurations)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->get_configurations)
return -ENOTSUP;
return g_uwb_funcs->get_configurations(node_id, configurations);
}
EXPORT
int hal_uwb_set_position(uint64_t node_id, int x, int y, int z)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->set_position)
return -ENOTSUP;
return g_uwb_funcs->set_position(node_id, x, y, z);
}
EXPORT
int hal_uwb_get_own_node(uwb_hal_node_s **own_node)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->get_own_node)
return -ENOTSUP;
return g_uwb_funcs->get_own_node(own_node);
}
EXPORT
int hal_uwb_send_message(const unsigned char *message, int message_length)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->send_message)
return -ENOTSUP;
return g_uwb_funcs->send_message(message, message_length);
}
EXPORT
int hal_uwb_send_message_to(uint16_t node_id, const unsigned char *message, int message_length)
{
if (!g_uwb_funcs)
return -ENOTSUP;
if (!g_uwb_funcs->send_message_to)
return -ENOTSUP;
return g_uwb_funcs->send_message_to(node_id, message, message_length);
}
|