Fix invalid UTF-8 charactor error in AVRCP track info
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / audio / avrcp / bt-service-avrcp-ctrl.c
1 /*
2  * Bluetooth-frwk
3  *
4  * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:  Nilesh Trimbake <t.shripati@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *              http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <sys/socket.h>
23 #include <sys/errno.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <vconf.h>
27
28 #include "oal-hardware.h"
29 #include "oal-device-mgr.h"
30 #include <oal-manager.h>
31 #include <oal-avrcp-ct.h>
32
33 #include <bt-service-avrcp-ctrl.h>
34 #include <bluetooth-media-control.h>
35 #include <bt-service-event.h>
36
37 static int __media_prop_to_oal_type(int type)
38 {
39         int oal_type;
40
41         switch (type) {
42         case EQUALIZER:
43                 oal_type = OAL_EQUALIZER;
44                 break;
45         case SHUFFLE:
46                 oal_type = OAL_SHUFFLE;
47                 break;
48         case REPEAT:
49                 oal_type = OAL_REPEAT;
50                 break;
51         case SCAN:
52                 oal_type = OAL_SCAN;
53                 break;
54         case POSITION:
55                 oal_type = OAL_PLAY_POSITION;
56                 break;
57         case STATUS:
58                 oal_type = OAL_PLAY_STATUS;
59                 break;
60         default:
61                 BT_ERR("Unknown type: %d", type);
62                 oal_type = -1;
63         }
64
65         return oal_type;
66 }
67
68 static int __oal_type_to_media_prop(int oal_type)
69 {
70         int type;
71
72         switch (oal_type) {
73         case OAL_EQUALIZER:
74                 type = EQUALIZER;
75                 break;
76         case OAL_SHUFFLE:
77                 type = SHUFFLE;
78                 break;
79         case OAL_REPEAT:
80                 type = REPEAT;
81                 break;
82         case OAL_SCAN:
83                 type = SCAN;
84                 break;
85         case OAL_PLAY_POSITION:
86                 type = POSITION;
87                 break;
88         case OAL_PLAY_STATUS:
89                 type = STATUS;
90                 break;
91         default:
92                 BT_ERR("Unknown type: %d", oal_type);
93                 type = -1;
94         }
95
96         return type;
97 }
98
99 int _bt_avrcp_connect_remote_target(bluetooth_device_address_t *device_address)
100 {
101         oal_status_t status = OAL_STATUS_SUCCESS;
102         int result = BLUETOOTH_ERROR_NONE;
103         BT_INFO("+");
104
105         status = avrcp_ct_connect((bt_address_t*)device_address);
106         if (status != OAL_STATUS_SUCCESS) {
107                 BT_ERR("Connection could not be established, err: [%d]", status);
108                 result = BLUETOOTH_ERROR_INTERNAL;
109         }
110         return result;
111 }
112
113 int _bt_avrcp_disconnect_remote_target(bluetooth_device_address_t *device_address)
114 {
115         oal_status_t status = OAL_STATUS_SUCCESS;
116         int result = BLUETOOTH_ERROR_NONE;
117         BT_INFO("+");
118
119         status = avrcp_ct_disconnect((bt_address_t*)device_address);
120         if (status != OAL_STATUS_SUCCESS) {
121                 BT_ERR("DisConnection err: [%d]", status);
122                 result = BLUETOOTH_ERROR_INTERNAL;
123         }
124         return result;
125 }
126
127 int _bt_avrcp_control_cmd(int type)
128 {
129         char connected_address[BT_ADDRESS_STRING_SIZE + 1];
130         gboolean connected;
131         bluetooth_device_address_t device_address;
132         oal_status_t status = OAL_STATUS_SUCCESS;
133         int result = BLUETOOTH_ERROR_NONE;
134         BT_INFO("+");
135
136         connected = _bt_is_headset_type_connected(BT_AVRCP, connected_address);
137
138         if (connected) {
139                 _bt_convert_addr_string_to_type(device_address.addr,
140                                 connected_address);
141                 switch (type) {
142                 case RC_PASS_CMD_PLAY:
143                         status = avrcp_ct_play((bt_address_t*)&device_address);
144                         break;
145                 case RC_PASS_CMD_PAUSE:
146                         status = avrcp_ct_pause((bt_address_t*)&device_address);
147                         break;
148                 case RC_PASS_CMD_STOP:
149                         status = avrcp_ct_stop((bt_address_t*)&device_address);
150                         break;
151                 case RC_PASS_CMD_NEXT:
152                         status = avrcp_ct_next_track((bt_address_t*)&device_address);
153                         break;
154                 case RC_PASS_CMD_PREVIOUS:
155                         status = avrcp_ct_prev_track((bt_address_t*)&device_address);
156                         break;
157                 case RC_PASS_CMD_PRESS_FAST_FORWARD:
158                         status = avrcp_ct_fforward((bt_address_t*)&device_address, PRESS_STATE);
159                         break;
160                 case RC_PASS_CMD_RELEASE_FAST_FORWARD:
161                         status = avrcp_ct_fforward((bt_address_t*)&device_address, RELEASE_STATE);
162                         break;
163                 case RC_PASS_CMD_PRESS_REWIND:
164                         status = avrcp_ct_rewind((bt_address_t*)&device_address, PRESS_STATE);
165                         break;
166                 case RC_PASS_CMD_RELEASE_REWIND:
167                         status = avrcp_ct_rewind((bt_address_t*)&device_address, RELEASE_STATE);
168                         break;
169                 default:
170                         break;
171                 }
172
173                 if (status != OAL_STATUS_SUCCESS) {
174                         BT_ERR("Send pass through command err: [%d]", status);
175                         result = BLUETOOTH_ERROR_INTERNAL;
176                 }
177         } else {
178                 BT_ERR("Device is not connected:");
179                 return BLUETOOTH_ERROR_NOT_CONNECTED;
180         }
181
182         return result;
183 }
184
185 int _bt_avrcp_control_set_property(int type, unsigned int value)
186 {
187         char connected_address[BT_ADDRESS_STRING_SIZE + 1];
188         gboolean connected;
189         bluetooth_device_address_t device_address;
190         oal_status_t status = OAL_STATUS_SUCCESS;
191         int result = BLUETOOTH_ERROR_NONE;
192         BT_INFO("+");
193         connected = _bt_is_headset_type_connected(BT_AVRCP, connected_address);
194
195         if (connected) {
196                 int oal_type;
197
198                 oal_type = __media_prop_to_oal_type(type);
199                 retv_if(0 > oal_type, BLUETOOTH_ERROR_INVALID_PARAM);
200
201                 _bt_convert_addr_string_to_type(device_address.addr,
202                                 connected_address);
203                 status = avrcp_ct_set_property((bt_address_t*)&device_address,
204                                 oal_type, value);
205                 if (status != OAL_STATUS_SUCCESS) {
206                         BT_ERR("Set peoperty err: [%d]", status);
207                         result = BLUETOOTH_ERROR_INTERNAL;
208                 }
209         } else {
210                 BT_ERR("Device is not connected:");
211                 return BLUETOOTH_ERROR_NOT_CONNECTED;
212         }
213         return result;
214 }
215
216 int _bt_avrcp_transport_set_property(int type, unsigned int value)
217 {
218         char connected_address[BT_ADDRESS_STRING_SIZE + 1];
219         gboolean connected;
220         bluetooth_device_address_t device_address;
221         oal_status_t status = OAL_STATUS_SUCCESS;
222         int result = BLUETOOTH_ERROR_NONE;
223         BT_INFO("+");
224         connected = _bt_is_headset_type_connected(BT_AVRCP, connected_address);
225
226         if (connected) {
227                 _bt_convert_addr_string_to_type(device_address.addr,
228                                 connected_address);
229                 status = avrcp_transport_set_property((bt_address_t*)&device_address,
230                                 type, value);
231                 if (status != OAL_STATUS_SUCCESS) {
232                         BT_ERR("Set peoperty err: [%d]", status);
233                         result = BLUETOOTH_ERROR_INTERNAL;
234                 }
235         } else {
236                 BT_ERR("Device is not connected:");
237                 return BLUETOOTH_ERROR_NOT_CONNECTED;
238         }
239         return result;
240 }
241
242 int _bt_avrcp_control_get_property(int type)
243 {
244         char connected_address[BT_ADDRESS_STRING_SIZE + 1];
245         gboolean connected;
246         bt_address_t device_address;
247         oal_status_t status = OAL_STATUS_SUCCESS;
248         int result = BLUETOOTH_ERROR_NONE;
249         BT_INFO("+");
250         connected = _bt_is_headset_type_connected(BT_AVRCP, connected_address);
251
252         if (connected) {
253                 avrcp_ct_player_property_type_t oal_type;
254
255                 _bt_convert_addr_string_to_type(
256                                 device_address.addr,
257                                 connected_address);
258                 if (type == STATUS) {
259                         status = avrcp_ct_get_play_status(&device_address);
260                         if (status != OAL_STATUS_SUCCESS) {
261                                 BT_ERR("Get play status err: [%d]", status);
262                                 result = BLUETOOTH_ERROR_INTERNAL;
263                         }
264                 } else {
265                         oal_type = __media_prop_to_oal_type(type);
266                         retv_if(0 > oal_type, BLUETOOTH_ERROR_INVALID_PARAM);
267
268                         status = avrcp_ct_get_property(&device_address, oal_type);
269                         if (status != OAL_STATUS_SUCCESS) {
270                                 BT_ERR("Get peoperty err: [%d]", status);
271                                 result = BLUETOOTH_ERROR_INTERNAL;
272                         }
273                 }
274         } else {
275                 BT_ERR("Device is not connected:");
276                 return BLUETOOTH_ERROR_NOT_CONNECTED;
277         }
278         return result;
279 }
280
281 int _bt_avrcp_control_get_track_info(void)
282 {
283         char connected_address[BT_ADDRESS_STRING_SIZE + 1];
284         gboolean connected;
285         bluetooth_device_address_t device_address;
286         oal_status_t status = OAL_STATUS_SUCCESS;
287         int result = BLUETOOTH_ERROR_NONE;
288         BT_INFO("+");
289         connected = _bt_is_headset_type_connected(BT_AVRCP, connected_address);
290
291         if (connected) {
292                 _bt_convert_addr_string_to_type(
293                                 device_address.addr,
294                                 connected_address);
295
296                 status = avrcp_ct_get_media_attribute((bt_address_t*)&device_address);
297                 if (status != OAL_STATUS_SUCCESS) {
298                         BT_ERR("Get track info err: [%d]", status);
299                         result = BLUETOOTH_ERROR_INTERNAL;
300                 }
301         } else {
302                 BT_ERR("Device is not connected:");
303                 return BLUETOOTH_ERROR_NOT_CONNECTED;
304         }
305         return result;
306 }
307
308 static void __bt_reply_avrcp_ct_connection_pending_request(bluetooth_device_address_t *address)
309 {
310         BT_DBG("+");
311         char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
312         int result = BLUETOOTH_ERROR_NONE;
313         bluetooth_device_address_t device_address;
314         GArray *out_param;
315         invocation_info_t *req_info;
316         memcpy(device_address.addr, address->addr, BLUETOOTH_ADDRESS_LENGTH);
317         _bt_convert_addr_type_to_string(addr, address->addr);
318
319         req_info = _bt_get_request_info_data(BT_AVRCP_CONTROL_CONNECT, addr);
320         if (NULL == req_info) {
321                 BT_INFO("AVRCP CT Connect request not found or possibly already replied");
322                 return;
323         } else {
324                 BT_INFO("AVRCP CT Connect request found for [%s]", addr);
325         }
326
327         out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
328         g_array_append_vals(out_param, addr, BT_ADDRESS_STRING_SIZE);
329         _bt_service_method_return(req_info->context,
330                         out_param, result);
331         g_array_free(out_param, TRUE);
332         g_free(req_info->user_data);
333         _bt_free_info_from_invocation_list(req_info);
334 }
335
336 static void __bt_handle_avrcp_target_connected_state(bluetooth_device_address_t *address)
337 {
338         char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
339         GVariant *param;
340         int result = BLUETOOTH_ERROR_NONE;
341         ret_if(NULL == address);
342         BT_INFO("+");
343
344         _bt_convert_addr_type_to_string(addr, address->addr);
345         BT_INFO("Address of connected device [%s]", addr);
346
347         /* Add data from the connected list */
348         _bt_add_headset_to_list(BT_AVRCP, BT_STATE_CONNECTED, addr);
349
350         /* Replay to avrcp cotroller connect */
351         __bt_reply_avrcp_ct_connection_pending_request(address);
352
353         /* Send AVRCP(TARGET Role) connected event to Application */
354         param = g_variant_new("(is)", result, addr);
355         _bt_send_event(BT_AVRCP_CONTROL_EVENT, BLUETOOTH_EVENT_AVRCP_CONNECTED, param);
356
357         BT_INFO("-");
358 }
359
360 static void __bt_reply_avrcp_ct_disconnection_pending_request(bluetooth_device_address_t *address)
361 {
362         char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
363         int result = BLUETOOTH_ERROR_NONE;
364         GArray *out_param;
365         invocation_info_t *req_info;
366
367         BT_DBG("+");
368         _bt_convert_addr_type_to_string(addr, address->addr);
369
370         req_info = _bt_get_request_info_data(BT_AVRCP_CONTROL_DISCONNECT, addr);
371         if (NULL == req_info) {
372                 BT_INFO("AVRCP CT Disconnect request not found or possibly already replied");
373                 return;
374         } else {
375                 BT_INFO("AVRCP CT Disconnect request found for [%s]", addr);
376         }
377
378         out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
379         g_array_append_vals(out_param, addr, BT_ADDRESS_STRING_SIZE);
380         _bt_service_method_return(req_info->context,
381                         out_param, result);
382         g_array_free(out_param, TRUE);
383         g_free(req_info->user_data);
384         _bt_free_info_from_invocation_list(req_info);
385 }
386
387 static void __bt_avrcp_ct_reply_pending_requests(void)
388 {
389         BT_INFO("+");
390         int result = BLUETOOTH_ERROR_INTERNAL;
391         GArray *out_param;
392         invocation_info_t *req_info;
393         GSList *l;
394
395         for (l = _bt_get_invocation_list(); l != NULL;) {
396                 req_info = l->data;
397                 l = g_slist_next(l);
398
399                 if (req_info == NULL)
400                         continue;
401
402                 /* Create out param */
403                 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
404
405                 BT_INFO("service_function: [0x%X]", req_info->service_function);
406                 switch (req_info->service_function) {
407                 case BT_AVRCP_GET_TRACK_INFO:
408                 case BT_AVRCP_CONTROL_GET_PROPERTY: {
409                         _bt_service_method_return(req_info->context, out_param, result);
410                         break;
411                 }
412                 default:
413                         break;
414                 }
415                 _bt_free_info_from_invocation_list(req_info);
416                 g_array_free(out_param, TRUE);
417         }
418         BT_INFO("-");
419 }
420
421 static void __bt_handle_avrcp_target_disconnected_state(bluetooth_device_address_t *address)
422 {
423         char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
424         GVariant *param;
425         int result = BLUETOOTH_ERROR_NONE;
426         ret_if(NULL == address);
427         BT_INFO("+");
428
429         _bt_convert_addr_type_to_string(addr, address->addr);
430         BT_INFO("Address of disconnected device [%s]", addr);
431
432         /* Remove data from the connected list */
433         _bt_remove_headset_from_list(BT_AVRCP, addr);
434
435         /* Reply to avrcp cotroller connect */
436         __bt_reply_avrcp_ct_disconnection_pending_request(address);
437
438         /* Reply AVRCP CT pending requests */
439         __bt_avrcp_ct_reply_pending_requests();
440
441         /* Send AVRCP(TARGET Role) disconnected event to Application */
442         param = g_variant_new("(is)", result, addr);
443         _bt_send_event(BT_AVRCP_CONTROL_EVENT, BLUETOOTH_EVENT_AVRCP_DISCONNECTED, param);
444
445         BT_INFO("-");
446 }
447
448 static int __bt_oal_to_bt_event(int oal_event)
449 {
450         int ret = 0;
451
452         switch (oal_event) {
453         case OAL_EVENT_AVRCP_CT_EQUALIZER_STATUS:
454                 ret = BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS;
455                 break;
456         case OAL_EVENT_AVRCP_CT_REPEAT_STATUS:
457                 ret = BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS;
458                 break;
459         case OAL_EVENT_AVRCP_CT_SHUFFLE_STATUS:
460                 ret = BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS;
461                 break;
462         case OAL_EVENT_AVRCP_CT_SCAN_STATUS:
463                 ret = BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS;
464                 break;
465         case OAL_EVENT_AVRCP_CT_NOTIF_PLAY_POS_CHANGED:
466                 ret = BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS;
467                 break;
468         case OAL_EVENT_AVRCP_CT_NOTIF_PLAY_STATUS_CHANGED:
469                 ret = BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED;
470                 break;
471         default:
472                 break;
473         }
474         return ret;
475 }
476
477 static void __bt_handle_avrcp_target_player_property(unsigned int property_value, int oal_event)
478 {
479         GVariant *param;
480         BT_INFO("+");
481         /* Send AVRCP Target player property event to Application */
482         param = g_variant_new("(u)", property_value);
483         _bt_send_event(BT_AVRCP_CONTROL_EVENT,
484                         __bt_oal_to_bt_event(oal_event), param);
485 }
486
487 static void __bt_handle_avrcp_track_info_changed(event_avrcp_ct_media_info_t* metadata)
488 {
489         GVariant *param;
490         unsigned int total_track = 0;
491         unsigned int track_number = 0;
492         unsigned int playing_time = 0;
493         GVariant *title;
494         GVariant *artist;
495         GVariant *album;
496         GVariant *genre;
497
498         BT_INFO("+");
499
500         total_track = (unsigned int)(metadata->total_track);
501         track_number = (unsigned int)(metadata->track_number);
502         playing_time = (unsigned int)(metadata->playing_time);
503
504         title = g_variant_new_from_data((const GVariantType *)"ay",
505                         metadata->title_info, MEDIA_ATTIRBUTE_STRING_LENGTH,
506                         TRUE, NULL, NULL);
507         artist = g_variant_new_from_data((const GVariantType *)"ay",
508                         metadata->artist_info, MEDIA_ATTIRBUTE_STRING_LENGTH,
509                         TRUE, NULL, NULL);
510         album = g_variant_new_from_data((const GVariantType *)"ay",
511                         metadata->album_info, MEDIA_ATTIRBUTE_STRING_LENGTH,
512                         TRUE, NULL, NULL);
513         genre = g_variant_new_from_data((const GVariantType *)"ay",
514                         metadata->genre_info, MEDIA_ATTIRBUTE_STRING_LENGTH,
515                         TRUE, NULL, NULL);
516
517         /* Send AVRCP Target player track info changed event to application*/
518         param = g_variant_new("(@ay@ay@ay@ayuuu)",
519                         title, artist, album, genre,
520                         total_track, track_number, playing_time);
521
522         BT_INFO("Total_track: %u, track_number: %u, playing_time: %u",
523                         total_track, track_number, playing_time);
524         _bt_send_event(BT_AVRCP_CONTROL_EVENT,
525                         BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED, param);
526 }
527
528 static invocation_info_t* __bt_get_request_info(int service_function)
529 {
530         GSList *l;
531         invocation_info_t *req_info = NULL;
532
533         BT_DBG("+");
534         /* Get method invocation context */
535         for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
536                 req_info = l->data;
537                 if (req_info == NULL || req_info->service_function != service_function)
538                         continue;
539                 return req_info;
540         }
541         return NULL;
542 }
543
544 static void __bt_handle_avrcp_track_info(event_avrcp_ct_media_info_t* metadata)
545 {
546         media_metadata_t meta_data;
547         invocation_info_t *req_info = NULL;
548         GArray *out_param = NULL;
549         int result = BLUETOOTH_ERROR_NONE;
550
551         req_info = __bt_get_request_info(BT_AVRCP_GET_TRACK_INFO);
552         ret_if(NULL == req_info);
553
554         memset(&meta_data, 0x00, sizeof(media_metadata_t));
555
556         memcpy(&meta_data.title, &metadata->title_info,
557                         strlen((char *)metadata->title_info));
558         meta_data.title[strlen((char *)metadata->title_info)] = '\0';
559
560         memcpy(&meta_data.artist, &metadata->artist_info,
561                         strlen((char *)metadata->artist_info));
562         meta_data.artist[strlen((char *)metadata->artist_info)] = '\0';
563
564         memcpy(&meta_data.album, &metadata->album_info,
565                         strlen((char *)metadata->album_info));
566         meta_data.album[strlen((char *)metadata->album_info)] = '\0';
567
568         memcpy(&meta_data.genre, &metadata->genre_info,
569                         strlen((char *)metadata->genre_info));
570         meta_data.genre[strlen((char *)metadata->genre_info)] = '\0';
571
572         meta_data.total_tracks = metadata->total_track;
573         meta_data.number = metadata->track_number;
574         meta_data.duration = metadata->playing_time;
575
576         out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
577         g_array_append_vals(out_param, &meta_data, sizeof(media_metadata_t));
578
579         _bt_service_method_return(req_info->context, out_param, result);
580         g_array_free(out_param, TRUE);
581         _bt_free_info_from_invocation_list(req_info);
582 }
583
584 static void __bt_handle_avrcp_pass_cmd_res(avrcp_ct_pass_cmd_t *pass_cmd)
585 {
586         BT_INFO(" Send Command Response [%d]", pass_cmd->key_code);
587 }
588
589 static void __bt_handle_avrcp_player_setting_res(avrcp_ct_playersetting_t *player_setting_res)
590 {
591         BT_INFO("Set Property Response [%d]", player_setting_res->accepted);
592 }
593
594 static void __bt_handle_avrcp_get_property_res_event(avrcp_ct_player_property_type_t oal_type, int value)
595 {
596         invocation_info_t *req_info = NULL;
597         GArray *out_param = NULL;
598         int result = BLUETOOTH_ERROR_NONE;
599         int prop_type;
600         int type;
601         GSList *l;
602
603         BT_DBG("+");
604
605         prop_type = __oal_type_to_media_prop(oal_type);
606         ret_if(0 > prop_type);
607
608         out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
609         g_array_append_vals(out_param, &value, sizeof(value));
610
611         /* Find and reply to all get requests for prop_type */
612         for (l = _bt_get_invocation_list(); l != NULL;) {
613                 req_info = l->data;
614                 l = g_slist_next(l);
615
616                 if (req_info == NULL)
617                         continue;
618
619                 type = *((int *)req_info->user_data);
620                 if (req_info->service_function != BT_AVRCP_CONTROL_GET_PROPERTY
621                                 || type != prop_type)
622                         continue;
623
624                 BT_INFO("Request found");
625                 _bt_service_method_return(req_info->context, out_param, result);
626                 g_free(req_info->user_data);
627                 _bt_free_info_from_invocation_list(req_info);
628         }
629
630         g_array_free(out_param, TRUE);
631         BT_DBG("-");
632 }
633
634 void _bt_avrcp_ctrl_event_handler(int oal_event, gpointer event_data)
635 {
636         BT_INFO("+");
637         bluetooth_device_address_t* bd_addr;
638
639         switch (oal_event) {
640         case OAL_EVENT_AVRCP_CT_CONNECTED: {
641                 BT_INFO("AVRCP Controller Profile connected..");
642                 bd_addr = (bluetooth_device_address_t*)event_data;
643                 __bt_handle_avrcp_target_connected_state(bd_addr);
644                 break;
645         }
646         case OAL_EVENT_AVRCP_CT_DISCONNECTED: {
647                 BT_INFO("AVRCP Controller Profile dissconnected..");
648                 bd_addr = (bluetooth_device_address_t*)event_data;
649                 __bt_handle_avrcp_target_disconnected_state(bd_addr);
650                 break;
651         }
652         case OAL_EVENT_AVRCP_CT_EQUALIZER_STATUS:
653         case OAL_EVENT_AVRCP_CT_REPEAT_STATUS:
654         case OAL_EVENT_AVRCP_CT_SHUFFLE_STATUS:
655         case OAL_EVENT_AVRCP_CT_SCAN_STATUS: {
656                 avrcp_ct_property_value_t* property_val;
657                 property_val = (avrcp_ct_property_value_t*)event_data;
658                 __bt_handle_avrcp_target_player_property(property_val->value, oal_event);
659                 break;
660         }
661         case OAL_EVENT_AVRCP_CT_NOTIF_PLAY_STATUS_CHANGED:{
662                 event_notif_avrcp_ct_notif_info_t* play_status_val;
663                 play_status_val = (event_notif_avrcp_ct_notif_info_t*)event_data;
664                 __bt_handle_avrcp_target_player_property(play_status_val->play_status, oal_event);
665                 break;
666         }
667         case OAL_EVENT_AVRCP_CT_NOTIF_PLAY_POS_CHANGED: {
668                 event_notif_avrcp_ct_notif_info_t* play_position;
669                 play_position = (event_notif_avrcp_ct_notif_info_t*)event_data;
670                 __bt_handle_avrcp_target_player_property(play_position->song_pos, oal_event);
671                 break;
672         }
673         case OAL_EVENT_AVRCP_CT_NOTIF_TRACK_CHANGE: {
674                 BT_INFO("AVRCP Controller Track Changed event..");
675                 event_avrcp_ct_media_info_t* metadata = event_data;
676
677                 __bt_handle_avrcp_track_info_changed(metadata);
678                 break;
679         }
680         case OAL_EVENT_AVRCP_CT_MEDIA_INFO: {
681                 BT_INFO("AVRCP Controller Track Info event..");
682                 event_avrcp_ct_media_info_t* metadata;
683
684                 metadata = (event_avrcp_ct_media_info_t*)event_data;
685                 __bt_handle_avrcp_track_info(metadata);
686                 break;
687         }
688         case OAL_EVENT_AVRCP_CT_GET_PROPERTY_RES: {
689                 BT_INFO("AVRCP Controller Get Property response event..");
690                 avrcp_ct_property_value_t *property = (avrcp_ct_property_value_t *)event_data;
691                 __bt_handle_avrcp_get_property_res_event(property->type, property->value);
692                 break;
693         }
694         case OAL_EVENT_AVRCP_CT_PLAY_STATUS: {
695                 BT_INFO("AVRCP Controller Get Play status response event..");
696                 event_avrcp_ct_play_status_t *play_status_info = (event_avrcp_ct_play_status_t *)event_data;
697                 __bt_handle_avrcp_get_property_res_event(OAL_PLAY_STATUS, play_status_info->play_status);
698                 break;
699         }
700         case OAL_EVENT_AVRCP_CT_PASS_CMD_RES: {
701                 BT_INFO("AVRCP Controller Pass Command Res");
702                 avrcp_ct_pass_cmd_t *pass_cmd;
703
704                 pass_cmd = (avrcp_ct_pass_cmd_t *)event_data;
705                 __bt_handle_avrcp_pass_cmd_res(pass_cmd);
706                 break;
707         }
708         case OAL_EVENT_AVRCP_CT_PLAYER_SETTING_RES: {
709                 BT_INFO("AVRCP Player setting response");
710                 avrcp_ct_playersetting_t *player_setting_res;
711
712                 player_setting_res = (avrcp_ct_playersetting_t *)event_data;
713                 __bt_handle_avrcp_player_setting_res(player_setting_res);
714                 break;
715         }
716         default:
717                 BT_INFO("Invalid Event = %d", oal_event);
718                 break;
719         }
720
721         BT_INFO("-");
722 }