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