7 #include <hal/hal-common.h>
12 #define HAL_RADIO_RETURN_IF_FAILED(arg, ret) \
15 _E("[%s]failed, return[%s]", #arg, #ret);\
20 typedef struct _hal_radio_s {
22 hal_backend_radio_funcs *funcs;
25 hal_radio_error_t hal_radio_get_backend(void **hal_radio_handle)
29 hal_radio_s *new_radio_handle;
31 HAL_RADIO_RETURN_IF_FAILED(hal_radio_handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
33 new_radio_handle = (hal_radio_s *)calloc(1, sizeof(hal_radio_s));
34 if (!new_radio_handle) {
35 _E("Failed to malloc hal radio handle");
36 return HAL_RADIO_ERROR_OUT_OF_MEMORY;
39 ret = hal_common_get_backend(HAL_MODULE_RADIO, (void **)&new_radio_handle->funcs);
40 if (ret != TIZEN_ERROR_NONE) {
41 _E("Failed to get backend");
42 free(new_radio_handle);
43 return HAL_RADIO_ERROR_INTERNAL;
46 if (!new_radio_handle->funcs) {
47 _E("Failed to load functions");
48 free(new_radio_handle);
49 return HAL_RADIO_ERROR_NOT_IMPLEMENTED;
52 *hal_radio_handle = new_radio_handle;
54 return HAL_RADIO_ERROR_NONE;
57 hal_radio_error_t hal_radio_put_backend(void *hal_radio_handle)
60 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
62 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
63 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
65 ret = hal_common_put_backend(HAL_MODULE_RADIO, (void *)handle->funcs);
67 memset(handle, 0x0, sizeof(hal_radio_s));
73 hal_radio_error_t hal_radio_init(void *hal_radio_handle)
75 int ret = HAL_RADIO_ERROR_NONE;
76 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
78 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
79 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
80 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->init, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
82 ret = handle->funcs->init(&handle->backend);
83 if (ret != HAL_RADIO_ERROR_NONE)
84 _E("backend init failed[0x%x]", ret);
89 hal_radio_error_t hal_radio_deinit(void *hal_radio_handle)
91 int ret = HAL_RADIO_ERROR_NONE;
92 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
94 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
95 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
96 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->deinit, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
98 ret = handle->funcs->deinit(handle->backend);
99 if (ret != HAL_RADIO_ERROR_NONE)
100 _E("backend deinit failed[0x%x]", ret);
105 hal_radio_error_t hal_radio_prepare(void *hal_radio_handle)
107 int ret = HAL_RADIO_ERROR_NONE;
108 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
110 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
111 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
112 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->prepare, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
114 ret = handle->funcs->prepare(handle->backend);
115 if (ret != HAL_RADIO_ERROR_NONE)
116 _E("backend prepare failed[0x%x]", ret);
121 hal_radio_error_t hal_radio_unprepare(void *hal_radio_handle)
123 int ret = HAL_RADIO_ERROR_NONE;
124 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
126 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
127 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
128 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->unprepare, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
130 ret = handle->funcs->unprepare(handle->backend);
131 if (ret != HAL_RADIO_ERROR_NONE)
132 _E("backend unprepare failed[0x%x]", ret);
137 hal_radio_error_t hal_radio_open(void *hal_radio_handle)
139 int ret = HAL_RADIO_ERROR_NONE;
140 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
142 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
143 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
144 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->open, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
146 ret = handle->funcs->open(handle->backend);
147 if (ret != HAL_RADIO_ERROR_NONE)
148 _E("backend open failed[0x%x]", ret);
153 hal_radio_error_t hal_radio_close(void *hal_radio_handle)
155 int ret = HAL_RADIO_ERROR_NONE;
156 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
158 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
159 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
160 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->close, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
162 ret = handle->funcs->close(handle->backend);
163 if (ret != HAL_RADIO_ERROR_NONE)
164 _E("backend close failed[0x%x]", ret);
169 hal_radio_error_t hal_radio_start(void *hal_radio_handle)
171 int ret = HAL_RADIO_ERROR_NONE;
172 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
174 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
175 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
176 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->start, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
178 ret = handle->funcs->start(handle->backend);
179 if (ret != HAL_RADIO_ERROR_NONE)
180 _E("backend start failed[0x%x]", ret);
185 hal_radio_error_t hal_radio_stop(void *hal_radio_handle)
187 int ret = HAL_RADIO_ERROR_NONE;
188 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
190 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
191 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
192 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->stop, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
194 ret = handle->funcs->stop(handle->backend);
195 if (ret != HAL_RADIO_ERROR_NONE)
196 _E("backend stop failed[0x%x]", ret);
201 hal_radio_error_t hal_radio_seek(void *hal_radio_handle, hal_radio_seek_direction_type_t direction)
203 int ret = HAL_RADIO_ERROR_NONE;
204 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
206 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
207 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
208 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->seek, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
210 ret = handle->funcs->seek(handle->backend, direction);
211 if (ret != HAL_RADIO_ERROR_NONE)
212 _E("backend seek [%s] failed[0x%x]", direction ? "down" : "up", ret);
217 hal_radio_error_t hal_radio_get_frequency(void *hal_radio_handle, uint32_t *frequency)
219 int ret = HAL_RADIO_ERROR_NONE;
220 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
223 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
224 HAL_RADIO_RETURN_IF_FAILED(frequency, HAL_RADIO_ERROR_INVALID_PARAMETER);
225 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
226 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->get_frequency, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
228 ret = handle->funcs->get_frequency(handle->backend, &get_freq);
229 if (ret != HAL_RADIO_ERROR_NONE) {
230 _E("backend get_frequency failed[0x%x]", ret);
234 *frequency = get_freq;
239 hal_radio_error_t hal_radio_set_frequency(void *hal_radio_handle, uint32_t frequency)
241 int ret = HAL_RADIO_ERROR_NONE;
242 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
244 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
245 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
246 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->set_frequency, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
248 ret = handle->funcs->set_frequency(handle->backend, frequency);
249 if (ret != HAL_RADIO_ERROR_NONE)
250 _E("backend set_frequency failed[0x%x]", ret);
255 hal_radio_error_t hal_radio_get_signal_strength(void *hal_radio_handle, int32_t *strength)
257 int ret = HAL_RADIO_ERROR_NONE;
258 hal_radio_s *handle = (hal_radio_s *)hal_radio_handle;
259 int32_t get_strength = 0;
261 HAL_RADIO_RETURN_IF_FAILED(handle, HAL_RADIO_ERROR_INVALID_PARAMETER);
262 HAL_RADIO_RETURN_IF_FAILED(strength, HAL_RADIO_ERROR_INVALID_PARAMETER);
263 HAL_RADIO_RETURN_IF_FAILED(handle->funcs, HAL_RADIO_ERROR_INVALID_PARAMETER);
264 HAL_RADIO_RETURN_IF_FAILED(handle->funcs->get_signal_strength, HAL_RADIO_ERROR_NOT_IMPLEMENTED);
266 ret = handle->funcs->get_signal_strength(handle->backend, &get_strength);
267 if (ret != HAL_RADIO_ERROR_NONE) {
268 _E("backend get_signal_strength failed[0x%x]", ret);
272 *strength = get_strength;