Didn't check RADIO_READY state in radio_scan_start
[platform/core/api/radio.git] / src / radio.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <mm_types.h>
21 #include <radio_private.h>
22 #include <dlog.h>
23 #include <glib.h>
24 #include <system_info.h>
25
26 #ifdef LOG_TAG
27 #undef LOG_TAG
28 #endif
29 #define LOG_TAG "TIZEN_N_RADIO"
30
31 /*
32 * Internal Macros
33 */
34 #define RADIO_CHECK_CONDITION(condition, error, msg)    \
35         do {    \
36                 if (condition) { \
37                 } else {        \
38                         LOGE("[%s] %s(0x%08x)", (char *)__FUNCTION__, msg, error); \
39                         return error;   \
40                 } \
41         } while (0)
42
43 #define RADIO_INSTANCE_CHECK(radio)     \
44         RADIO_CHECK_CONDITION(radio != NULL, RADIO_ERROR_INVALID_PARAMETER, "RADIO_ERROR_INVALID_PARAMETER")
45
46 #define RADIO_STATE_CHECK(radio, expected_state)        \
47         RADIO_CHECK_CONDITION(radio->state == expected_state, RADIO_ERROR_INVALID_STATE, "RADIO_ERROR_INVALID_STATE")
48
49 #define RADIO_NULL_ARG_CHECK(arg)       \
50         RADIO_CHECK_CONDITION(arg != NULL, RADIO_ERROR_INVALID_PARAMETER, "RADIO_ERROR_INVALID_PARAMETER")
51
52 #define RADIO_SUPPORT_CHECK(arg)        \
53         RADIO_CHECK_CONDITION(arg != false, RADIO_ERROR_NOT_SUPPORTED, "RADIO_ERROR_NOT_SUPPORTED")
54
55 /*
56 * Internal Implementation
57 */
58 static int __convert_error_code(int code, char *func_name)
59 {
60         int ret = RADIO_ERROR_NONE;
61         char *msg = "RADIO_ERROR_NONE";
62         LOGI("[%s] Enter code :%x", __func__, code);
63         switch (code) {
64         case MM_ERROR_NONE:
65                 ret = RADIO_ERROR_NONE;
66                 msg = "RADIO_ERROR_NONE";
67                 break;
68
69         case MM_ERROR_RADIO_NO_FREE_SPACE:
70                 ret = RADIO_ERROR_OUT_OF_MEMORY;
71                 msg = "RADIO_ERROR_OUT_OF_MEMORY";
72                 break;
73         case MM_ERROR_RADIO_NOT_INITIALIZED:
74         case MM_ERROR_RADIO_NO_OP:
75         case MM_ERROR_RADIO_INVALID_STATE:
76                 ret = RADIO_ERROR_INVALID_STATE;
77                 msg = "RADIO_ERROR_INVALID_STATE";
78                 break;
79         case MM_ERROR_COMMON_INVALID_ARGUMENT:
80         case MM_ERROR_INVALID_ARGUMENT:
81                 ret = RADIO_ERROR_INVALID_PARAMETER;
82                 msg = "RADIO_ERROR_INVALID_PARAMETER";
83                 break;
84         case MM_ERROR_POLICY_BLOCKED:
85         case MM_ERROR_POLICY_INTERRUPTED:
86         case MM_ERROR_POLICY_INTERNAL:
87         case MM_ERROR_POLICY_DUPLICATED:
88                 ret = RADIO_ERROR_SOUND_POLICY;
89                 msg = "RADIO_ERROR_SOUND_POLICY";
90                 break;
91         case MM_ERROR_RADIO_INTERNAL:
92         case MM_ERROR_RADIO_RESPONSE_TIMEOUT:
93                 ret = RADIO_ERROR_INVALID_OPERATION;
94                 msg = "RADIO_ERROR_INVALID_OPERATION";
95                 break;
96         case MM_ERROR_RADIO_DEVICE_NOT_FOUND:
97                 ret = RADIO_ERROR_NOT_SUPPORTED;
98                 msg = "RADIO_ERROR_NOT_SUPPORTED";
99                 break;
100         case MM_ERROR_RADIO_NO_ANTENNA:
101                 ret = RADIO_ERROR_NO_ANTENNA;
102                 msg = "RADIO_ERROR_NO_ANTENNA";
103                 break;
104         case MM_ERROR_RADIO_DEVICE_NOT_OPENED:
105         default:
106                 ret = RADIO_ERROR_PERMISSION_DENIED;
107                 msg = "RADIO_ERROR_PERMISSION_DENIED";
108         }
109         LOGE("[%s] %s(0x%08x) : core fw error(0x%x)", func_name, msg, ret, code);
110         return ret;
111 }
112
113 static radio_state_e __convert_radio_state(MMRadioStateType state)
114 {
115         int converted_state = RADIO_STATE_READY;
116         LOGI("[%s] Enter state: %d", __func__, state);
117         switch (state) {
118
119         case MM_RADIO_STATE_PLAYING:
120                 converted_state = RADIO_STATE_PLAYING;
121                 break;
122         case MM_RADIO_STATE_SCANNING:
123                 converted_state = RADIO_STATE_SCANNING;
124                 break;
125         case MM_RADIO_STATE_NULL:
126         case MM_RADIO_STATE_READY:
127         default:
128                 converted_state = RADIO_STATE_READY;
129                 break;
130         }
131         LOGI("[%s] Leave converted_state: %d", __func__, converted_state);
132         return converted_state;
133 }
134
135 static radio_interrupted_code_e __convert_interrupted_code(int code)
136 {
137         LOGI("[%s] Enter code: %d", __func__, code);
138         radio_interrupted_code_e ret = RADIO_INTERRUPTED_BY_RESOURCE_CONFLICT;
139         switch (code) {
140         case MM_MSG_CODE_INTERRUPTED_BY_CALL_END:
141         case MM_MSG_CODE_INTERRUPTED_BY_ALARM_END:
142         case MM_MSG_CODE_INTERRUPTED_BY_EMERGENCY_END:
143         case MM_MSG_CODE_INTERRUPTED_BY_NOTIFICATION_END:
144                 ret = RADIO_INTERRUPTED_COMPLETED;
145                 break;
146         case MM_MSG_CODE_INTERRUPTED_BY_MEDIA:
147         case MM_MSG_CODE_INTERRUPTED_BY_OTHER_PLAYER_APP:
148                 ret = RADIO_INTERRUPTED_BY_MEDIA;
149                 break;
150         case MM_MSG_CODE_INTERRUPTED_BY_CALL_START:
151                 ret = RADIO_INTERRUPTED_BY_CALL;
152                 break;
153         case MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG:
154                 ret = RADIO_INTERRUPTED_BY_EARJACK_UNPLUG;
155                 break;
156         case MM_MSG_CODE_INTERRUPTED_BY_ALARM_START:
157                 ret = RADIO_INTERRUPTED_BY_ALARM;
158                 break;
159         case MM_MSG_CODE_INTERRUPTED_BY_NOTIFICATION_START:
160                 ret = RADIO_INTERRUPTED_BY_NOTIFICATION;
161                 break;
162         case MM_MSG_CODE_INTERRUPTED_BY_EMERGENCY_START:
163                 ret = RADIO_INTERRUPTED_BY_EMERGENCY;
164                 break;
165         case MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT:
166         default:
167                 ret = RADIO_INTERRUPTED_BY_RESOURCE_CONFLICT;
168                 break;
169         }
170         LOGE("[%s] interrupted code(%d) => ret(%d)", __FUNCTION__, code, ret);
171         return ret;
172 }
173
174 static int __set_callback(_radio_event_e type, radio_h radio, void *callback, void *user_data)
175 {
176         RADIO_INSTANCE_CHECK(radio);
177         RADIO_NULL_ARG_CHECK(callback);
178         radio_s *handle = (radio_s *)radio;
179         handle->user_cb[type] = callback;
180         handle->user_data[type] = user_data;
181         LOGI("[%s] Event type : %d ", __FUNCTION__, type);
182         return RADIO_ERROR_NONE;
183 }
184
185 static int __unset_callback(_radio_event_e type, radio_h radio)
186 {
187         RADIO_INSTANCE_CHECK(radio);
188         radio_s *handle = (radio_s *)radio;
189         handle->user_cb[type] = NULL;
190         handle->user_data[type] = NULL;
191         LOGI("[%s] Event type : %d ", __FUNCTION__, type);
192         return RADIO_ERROR_NONE;
193 }
194
195 static int __msg_callback(int message, void *param, void *user_data)
196 {
197         radio_s *handle = (radio_s *)user_data;
198         MMMessageParamType *msg = (MMMessageParamType *)param;
199         LOGI("[%s] Got message type : 0x%x", __FUNCTION__, message);
200         switch (message) {
201         case MM_MESSAGE_RADIO_SCAN_INFO:
202                 if (handle->user_cb[_RADIO_EVENT_TYPE_SCAN_INFO])
203                         ((radio_scan_updated_cb)handle->user_cb[_RADIO_EVENT_TYPE_SCAN_INFO])(msg->radio_scan.frequency, handle->user_data[_RADIO_EVENT_TYPE_SCAN_INFO]);
204                 break;
205         case MM_MESSAGE_RADIO_SCAN_STOP:
206                 if (handle->user_cb[_RADIO_EVENT_TYPE_SCAN_STOP])
207                         ((radio_scan_stopped_cb)handle->user_cb[_RADIO_EVENT_TYPE_SCAN_STOP])(handle->user_data[_RADIO_EVENT_TYPE_SCAN_STOP]);
208                 break;
209         case MM_MESSAGE_RADIO_SCAN_FINISH:
210                 if (handle->user_cb[_RADIO_EVENT_TYPE_SCAN_FINISH])
211                         ((radio_scan_completed_cb)handle->user_cb[_RADIO_EVENT_TYPE_SCAN_FINISH])(handle->user_data[_RADIO_EVENT_TYPE_SCAN_FINISH]);
212                 break;
213         case MM_MESSAGE_RADIO_SEEK_FINISH:
214                 if (handle->user_cb[_RADIO_EVENT_TYPE_SEEK_FINISH])
215                         ((radio_seek_completed_cb)handle->user_cb[_RADIO_EVENT_TYPE_SEEK_FINISH])(msg->radio_scan.frequency, handle->user_data[_RADIO_EVENT_TYPE_SEEK_FINISH]);
216                 break;
217         case MM_MESSAGE_STATE_INTERRUPTED:
218                 if (handle->user_cb[_RADIO_EVENT_TYPE_INTERRUPT])
219                         ((radio_interrupted_cb)handle->user_cb[_RADIO_EVENT_TYPE_INTERRUPT])(__convert_interrupted_code(msg->code), handle->user_data[_RADIO_EVENT_TYPE_INTERRUPT]);
220                 break;
221         case MM_MESSAGE_READY_TO_RESUME:
222                 if (handle->user_cb[_RADIO_EVENT_TYPE_INTERRUPT])
223                         ((radio_interrupted_cb)handle->user_cb[_RADIO_EVENT_TYPE_INTERRUPT])(RADIO_INTERRUPTED_COMPLETED, handle->user_data[_RADIO_EVENT_TYPE_INTERRUPT]);
224                 break;
225         case MM_MESSAGE_ERROR:
226                 __convert_error_code(msg->code, (char *)__FUNCTION__);
227                 break;
228         case MM_MESSAGE_RADIO_SCAN_START:
229                 LOGI("[%s] Scan Started");
230                 break;
231         case MM_MESSAGE_STATE_CHANGED:
232                 handle->state = __convert_radio_state(msg->state.current);
233                 LOGI("[%s] State Changed --- from : %d , to : %d", __FUNCTION__, __convert_radio_state(msg->state.previous), handle->state);
234                 break;
235         case MM_MESSAGE_RADIO_SEEK_START:
236                 LOGI("[%s] Seek Started", __FUNCTION__);
237                 break;
238         default:
239                 break;
240         }
241         return 1;
242 }
243
244 static int __radio_check_system_info_feature_supported()
245 {
246         bool bValue = false;
247         int nRetVal = false;
248
249         nRetVal = system_info_get_platform_bool("http://tizen.org/feature/fmradio", &bValue);
250
251         if (nRetVal != SYSTEM_INFO_ERROR_NONE) {
252                 LOGE("[%s] SYSTEM_INFO_ERROR : ", __FUNCTION__);
253                 return false;
254         }
255
256         if (false == bValue)
257                 LOGI("system_info_get_platform_bool returned Unsupported feature capability\n");
258         else
259                 LOGI("system_info_get_platform_bool returned Supported status feature\n");
260
261         return bValue;
262 }
263
264 /*
265 * Public Implementation
266 */
267 int radio_create(radio_h *radio)
268 {
269         LOGI("[%s] Enter", __func__);
270         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
271         RADIO_INSTANCE_CHECK(radio);
272         radio_s *handle;
273
274         handle = (radio_s *)malloc(sizeof(radio_s));
275         if (handle != NULL) {
276                 memset(handle, 0, sizeof(radio_s));
277         } else {
278                 LOGE("[%s] RADIO_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, RADIO_ERROR_OUT_OF_MEMORY);
279                 return RADIO_ERROR_OUT_OF_MEMORY;
280         }
281         int ret = mm_radio_create(&handle->mm_handle);
282         if (ret != MM_ERROR_NONE) {
283                 free(handle);
284                 handle = NULL;
285                 return __convert_error_code(ret, (char *)__FUNCTION__);
286         } else {
287                 *radio = (radio_h)handle;
288
289                 ret = mm_radio_set_message_callback(handle->mm_handle, __msg_callback, (void *)handle);
290                 if (ret != MM_ERROR_NONE)
291                         LOGW("[%s] Failed to set message callback function (0x%x)", __FUNCTION__, ret);
292
293                 ret = mm_radio_realize(handle->mm_handle);
294                 if (ret != MM_ERROR_NONE)
295                         return __convert_error_code(ret, (char *)__FUNCTION__);
296
297                 handle->state = RADIO_STATE_READY;
298                 handle->mute = FALSE;
299                 return RADIO_ERROR_NONE;
300         }
301 }
302
303 int radio_destroy(radio_h radio)
304 {
305         LOGI("[%s] Enter", __func__);
306         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
307         RADIO_INSTANCE_CHECK(radio);
308         radio_s *handle = (radio_s *)radio;
309
310         int ret;
311         ret = mm_radio_unrealize(handle->mm_handle);
312         if (ret != MM_ERROR_NONE)
313                 LOGW("[%s] Failed to unrealize (0x%x)", __FUNCTION__, ret);
314
315         ret = mm_radio_destroy(handle->mm_handle);
316         if (ret != MM_ERROR_NONE) {
317                 return __convert_error_code(ret, (char *)__FUNCTION__);
318         } else {
319                 free(handle);
320                 handle = NULL;
321                 return RADIO_ERROR_NONE;
322         }
323 }
324
325 int radio_get_state(radio_h radio, radio_state_e *state)
326 {
327         LOGI("[%s] Enter", __func__);
328         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
329         RADIO_INSTANCE_CHECK(radio);
330         RADIO_NULL_ARG_CHECK(state);
331         radio_s *handle = (radio_s *)radio;
332         MMRadioStateType currentStat = MM_RADIO_STATE_NULL;
333         int ret = mm_radio_get_state(handle->mm_handle, &currentStat);
334         if (ret != MM_ERROR_NONE) {
335                 *state = handle->state;
336                 return __convert_error_code(ret, (char *)__FUNCTION__);
337         } else {
338                 handle->state = __convert_radio_state(currentStat);
339                 *state = handle->state;
340                 return RADIO_ERROR_NONE;
341         }
342 }
343
344 int radio_start(radio_h radio)
345 {
346         LOGI("[%s] Enter", __func__);
347         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
348         RADIO_INSTANCE_CHECK(radio);
349         radio_s *handle = (radio_s *)radio;
350         RADIO_STATE_CHECK(handle, RADIO_STATE_READY);
351
352         int ret = mm_radio_start(handle->mm_handle);
353         if (ret != MM_ERROR_NONE) {
354                 return __convert_error_code(ret, (char *)__FUNCTION__);
355         } else {
356                 handle->state = RADIO_STATE_PLAYING;
357                 return RADIO_ERROR_NONE;
358         }
359 }
360
361 int radio_stop(radio_h radio)
362 {
363         LOGI("[%s] Enter", __func__);
364         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
365         RADIO_INSTANCE_CHECK(radio);
366         radio_s *handle = (radio_s *)radio;
367         RADIO_STATE_CHECK(handle, RADIO_STATE_PLAYING);
368
369         int ret = mm_radio_stop(handle->mm_handle);
370         if (ret != MM_ERROR_NONE) {
371                 return __convert_error_code(ret, (char *)__FUNCTION__);
372         } else {
373                 handle->state = RADIO_STATE_READY;
374                 return RADIO_ERROR_NONE;
375         }
376 }
377
378 int radio_seek_up(radio_h radio, radio_seek_completed_cb callback, void *user_data)
379 {
380         LOGI("[%s] Enter", __func__);
381         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
382         RADIO_INSTANCE_CHECK(radio);
383         radio_s *handle = (radio_s *)radio;
384         RADIO_STATE_CHECK(handle, RADIO_STATE_PLAYING);
385
386         if (callback != NULL)
387                 __set_callback(_RADIO_EVENT_TYPE_SEEK_FINISH, radio, callback, user_data);
388         else
389                 __unset_callback(_RADIO_EVENT_TYPE_SEEK_FINISH, radio);
390
391         int ret = mm_radio_seek(handle->mm_handle, MM_RADIO_SEEK_UP);
392         if (ret != MM_ERROR_NONE)
393                 return __convert_error_code(ret, (char *)__FUNCTION__);
394         else
395                 return RADIO_ERROR_NONE;
396 }
397
398 int radio_seek_down(radio_h radio, radio_seek_completed_cb callback, void *user_data)
399 {
400         LOGI("[%s] Enter", __func__);
401         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
402         RADIO_INSTANCE_CHECK(radio);
403         radio_s *handle = (radio_s *)radio;
404         RADIO_STATE_CHECK(handle, RADIO_STATE_PLAYING);
405
406         if (callback != NULL)
407                 __set_callback(_RADIO_EVENT_TYPE_SEEK_FINISH, radio, callback, user_data);
408         else
409                 __unset_callback(_RADIO_EVENT_TYPE_SEEK_FINISH, radio);
410
411         int ret = mm_radio_seek(handle->mm_handle, MM_RADIO_SEEK_DOWN);
412         if (ret != MM_ERROR_NONE)
413                 return __convert_error_code(ret, (char *)__FUNCTION__);
414         else
415                 return RADIO_ERROR_NONE;
416 }
417
418 int radio_set_frequency(radio_h radio, int frequency)
419 {
420         LOGI("[%s] Enter", __func__);
421         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
422         RADIO_INSTANCE_CHECK(radio);
423         if (frequency < 87500 || frequency > 108000) {
424                 LOGE("[%s] RADIO_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (87500 ~ 108000)", __FUNCTION__, RADIO_ERROR_INVALID_PARAMETER);
425                 return RADIO_ERROR_INVALID_PARAMETER;
426         }
427         int freq = frequency;
428         radio_s *handle = (radio_s *)radio;
429         int ret = mm_radio_set_frequency(handle->mm_handle, freq);
430         if (ret != MM_ERROR_NONE)
431                 return __convert_error_code(ret, (char *)__FUNCTION__);
432         else
433                 return RADIO_ERROR_NONE;
434 }
435
436 int radio_get_frequency(radio_h radio, int *frequency)
437 {
438         LOGI("[%s] Enter", __func__);
439         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
440         RADIO_INSTANCE_CHECK(radio);
441         RADIO_NULL_ARG_CHECK(frequency);
442         radio_s *handle = (radio_s *)radio;
443
444         int freq;
445         int ret = mm_radio_get_frequency(handle->mm_handle, &freq);
446         if (ret != MM_ERROR_NONE) {
447                 return __convert_error_code(ret, (char *)__FUNCTION__);
448         } else {
449                 *frequency = freq;
450                 return RADIO_ERROR_NONE;
451         }
452 }
453
454 int radio_get_signal_strength(radio_h radio, int *strength)
455 {
456         LOGI("[%s] Enter", __func__);
457         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
458         RADIO_INSTANCE_CHECK(radio);
459         RADIO_NULL_ARG_CHECK(strength);
460         radio_s *handle = (radio_s *)radio;
461
462         int _strength;
463         int ret = mm_radio_get_signal_strength(handle->mm_handle, &_strength);
464         if (ret != MM_ERROR_NONE) {
465                 return __convert_error_code(ret, (char *)__FUNCTION__);
466         } else {
467                 *strength = _strength;
468                 return RADIO_ERROR_NONE;
469         }
470 }
471
472 int radio_scan_start(radio_h radio, radio_scan_updated_cb callback, void *user_data)
473 {
474         LOGI("[%s] Enter", __func__);
475         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
476         RADIO_INSTANCE_CHECK(radio);
477         radio_s *handle = (radio_s *)radio;
478
479         if (callback != NULL)
480                 __set_callback(_RADIO_EVENT_TYPE_SCAN_INFO, radio, callback, user_data);
481         else
482                 __unset_callback(_RADIO_EVENT_TYPE_SCAN_INFO, radio);
483
484         int ret = mm_radio_scan_start(handle->mm_handle);
485         if (ret != MM_ERROR_NONE) {
486                 return __convert_error_code(ret, (char *)__FUNCTION__);
487         } else {
488                 handle->state = RADIO_STATE_SCANNING;
489                 return RADIO_ERROR_NONE;
490         }
491 }
492
493 int radio_scan_stop(radio_h radio, radio_scan_stopped_cb callback, void *user_data)
494 {
495         LOGI("[%s] Enter", __func__);
496         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
497         RADIO_INSTANCE_CHECK(radio);
498         radio_s *handle = (radio_s *)radio;
499         RADIO_STATE_CHECK(handle, RADIO_STATE_SCANNING);
500
501         if (callback != NULL)
502                 __set_callback(_RADIO_EVENT_TYPE_SCAN_STOP, radio, callback, user_data);
503         else
504                 __unset_callback(_RADIO_EVENT_TYPE_SCAN_STOP, radio);
505
506         int ret = mm_radio_scan_stop(handle->mm_handle);
507         if (ret != MM_ERROR_NONE) {
508                 return __convert_error_code(ret, (char *)__FUNCTION__);
509         } else {
510                 handle->state = RADIO_STATE_READY;
511                 return RADIO_ERROR_NONE;
512         }
513 }
514
515 int radio_set_mute(radio_h radio, bool muted)
516 {
517         LOGI("[%s] Enter", __func__);
518         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
519         RADIO_INSTANCE_CHECK(radio);
520         radio_s *handle = (radio_s *)radio;
521
522         int ret = mm_radio_set_mute(handle->mm_handle, muted);
523         if (ret != MM_ERROR_NONE) {
524                 return __convert_error_code(ret, (char *)__FUNCTION__);
525         } else {
526                 handle->mute = muted;
527                 return RADIO_ERROR_NONE;
528         }
529 }
530
531 int radio_is_muted(radio_h radio, bool *muted)
532 {
533         LOGI("[%s] Enter", __func__);
534         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
535         RADIO_INSTANCE_CHECK(radio);
536         RADIO_NULL_ARG_CHECK(muted);
537         radio_s *handle = (radio_s *)radio;
538         *muted = handle->mute;
539         return RADIO_ERROR_NONE;
540 }
541
542 int radio_set_scan_completed_cb(radio_h radio, radio_scan_completed_cb callback, void *user_data)
543 {
544         LOGI("[%s] Enter", __func__);
545         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
546         return __set_callback(_RADIO_EVENT_TYPE_SCAN_FINISH, radio, callback, user_data);
547 }
548
549 int radio_unset_scan_completed_cb(radio_h radio)
550 {
551         LOGI("[%s] Enter", __func__);
552         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
553         return __unset_callback(_RADIO_EVENT_TYPE_SCAN_FINISH, radio);
554 }
555
556 int radio_set_interrupted_cb(radio_h radio, radio_interrupted_cb callback, void *user_data)
557 {
558         LOGI("[%s] Enter", __func__);
559         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
560         return __set_callback(_RADIO_EVENT_TYPE_INTERRUPT, radio, callback, user_data);
561 }
562
563 int radio_unset_interrupted_cb(radio_h radio)
564 {
565         LOGI("[%s] Enter", __func__);
566         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
567         return __unset_callback(_RADIO_EVENT_TYPE_INTERRUPT, radio);
568 }
569
570 int radio_get_frequency_range(radio_h radio, int *min_freq, int *max_freq)
571 {
572         LOGI("[%s] Enter", __func__);
573         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
574         RADIO_INSTANCE_CHECK(radio);
575         RADIO_NULL_ARG_CHECK(min_freq);
576         RADIO_NULL_ARG_CHECK(max_freq);
577         radio_s *handle = (radio_s *)radio;
578
579         unsigned int min = 0;
580         unsigned int max = 0;
581
582         int ret = mm_radio_get_region_frequency_range(handle->mm_handle, &min, &max);
583         if (ret != MM_ERROR_NONE) {
584                 return __convert_error_code(ret, (char *)__FUNCTION__);
585         } else {
586                 *min_freq = min;
587                 *max_freq = max;
588                 return RADIO_ERROR_NONE;
589         }
590 }
591
592 int radio_get_channel_spacing(radio_h radio, int *channel_spacing)
593 {
594         LOGI("[%s] Enter", __func__);
595         RADIO_SUPPORT_CHECK(__radio_check_system_info_feature_supported());
596         RADIO_INSTANCE_CHECK(radio);
597
598         radio_s *handle = (radio_s *)radio;
599
600         int ret = mm_radio_get_channel_spacing(handle->mm_handle, channel_spacing);
601
602         if (ret != MM_ERROR_NONE)
603                 return __convert_error_code(ret, (char *)__FUNCTION__);
604         else
605                 return RADIO_ERROR_NONE;
606 }