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