From db57e2e3306350144ea9b75e9630416ec313e797 Mon Sep 17 00:00:00 2001 From: DoHyun Pyun Date: Tue, 19 Dec 2017 13:57:34 +0900 Subject: [PATCH] Fix the crash connected as AVRCP target role Change-Id: I03b64d72243fdfdf4e7adb45fe5e7dc56dca8fea Signed-off-by: DoHyun Pyun --- profiles/audio/avrcp.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c index 596406a..c7f0964 100644 --- a/profiles/audio/avrcp.c +++ b/profiles/audio/avrcp.c @@ -2277,6 +2277,12 @@ static gboolean avrcp_get_play_status_rsp(struct avctp *conn, uint8_t code, { struct avrcp *session = user_data; struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return FALSE; +#endif + struct media_player *mp = player->user_data; struct avrcp_header *pdu = (void *) operands; uint32_t duration; @@ -2341,6 +2347,12 @@ static gboolean avrcp_player_value_rsp(struct avctp *conn, uint8_t code, { struct avrcp *session = user_data; struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return FALSE; +#endif + struct media_player *mp = player->user_data; struct avrcp_header *pdu = (void *) operands; uint8_t count; @@ -2501,6 +2513,11 @@ static gboolean avrcp_get_element_attributes_rsp(struct avctp *conn, struct avrcp_header *pdu = (void *) operands; uint8_t count; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return FALSE; +#endif + if (code == AVC_CTYPE_REJECTED) return FALSE; @@ -2613,6 +2630,12 @@ static struct media_item *parse_media_element(struct avrcp *session, } player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return NULL; +#endif + mp = player->user_data; item = media_player_create_item(mp, name, PLAYER_ITEM_TYPE_AUDIO, uid); @@ -2628,6 +2651,12 @@ static struct media_item *parse_media_folder(struct avrcp *session, uint8_t *operands, uint16_t len) { struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return NULL; +#endif + struct media_player *mp = player->user_data; struct media_item *item; uint16_t namelen; @@ -2666,6 +2695,12 @@ static gboolean avrcp_list_items_rsp(struct avctp *conn, uint8_t *operands, struct avrcp_browsing_header *pdu = (void *) operands; struct avrcp *session = user_data; struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return FALSE; +#endif + struct pending_list_items *p = player->p; uint16_t count; uint64_t items; @@ -2757,6 +2792,11 @@ static void avrcp_list_items(struct avrcp *session, uint32_t start, uint16_t length = AVRCP_BROWSING_HEADER_LENGTH + 10; uint32_t attribute; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return; +#endif + memset(buf, 0, sizeof(buf)); pdu->pdu_id = AVRCP_GET_FOLDER_ITEMS; @@ -2787,6 +2827,12 @@ static gboolean avrcp_change_path_rsp(struct avctp *conn, struct avrcp_browsing_header *pdu = (void *) operands; struct avrcp *session = user_data; struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return FALSE; +#endif + struct media_player *mp = player->user_data; int ret; @@ -2824,6 +2870,12 @@ static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn, { struct avrcp *session = user_data; struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return FALSE; +#endif + struct media_player *mp = player->user_data; struct avrcp_browsing_header *pdu = (void *) operands; uint32_t items; @@ -2895,6 +2947,12 @@ static gboolean avrcp_get_item_attributes_rsp(struct avctp *conn, { struct avrcp *session = user_data; struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return FALSE; +#endif + struct avrcp_browsing_header *pdu = (void *) operands; uint8_t count; @@ -2928,6 +2986,11 @@ static void avrcp_get_item_attributes(struct avrcp *session, uint64_t uid) uint8_t buf[AVRCP_BROWSING_HEADER_LENGTH + 12]; struct avrcp_browsing_header *pdu = (void *) buf; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return; +#endif + memset(buf, 0, sizeof(buf)); pdu->pdu_id = AVRCP_GET_ITEM_ATTRIBUTES; @@ -2999,6 +3062,11 @@ static gboolean avrcp_set_addressed_player_rsp(struct avctp *conn, uint8_t code, if (!pdu || code != AVC_CTYPE_ACCEPTED) return FALSE; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return FALSE; +#endif + player->addressed = true; return FALSE; @@ -3276,6 +3344,11 @@ static void avrcp_change_path(struct avrcp *session, uint8_t direction, uint8_t buf[AVRCP_BROWSING_HEADER_LENGTH + 11]; struct avrcp_browsing_header *pdu = (void *) buf; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return; +#endif + memset(buf, 0, sizeof(buf)); put_be16(player->uid_counter, &pdu->params[0]); pdu->params[2] = direction; @@ -3311,6 +3384,12 @@ static gboolean avrcp_search_rsp(struct avctp *conn, uint8_t *operands, struct avrcp_browsing_header *pdu = (void *) operands; struct avrcp *session = (void *) user_data; struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return FALSE; +#endif + struct media_player *mp = player->user_data; int ret; @@ -3375,6 +3454,11 @@ static void avrcp_play_item(struct avrcp *session, uint64_t uid) struct avrcp_header *pdu = (void *) buf; uint16_t length; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return; +#endif + memset(buf, 0, sizeof(buf)); set_company_id(pdu->company_id, IEEEID_BTSIG); @@ -3424,6 +3508,11 @@ static void avrcp_add_to_nowplaying(struct avrcp *session, uint64_t uid) struct avrcp_header *pdu = (void *) buf; uint16_t length; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return; +#endif + memset(buf, 0, sizeof(buf)); set_company_id(pdu->company_id, IEEEID_BTSIG); @@ -3471,6 +3560,12 @@ static gboolean avrcp_get_total_numberofitems_rsp(struct avctp *conn, struct avrcp_browsing_header *pdu = (void *) operands; struct avrcp *session = user_data; struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return EINVAL; +#endif + struct media_player *mp = player->user_data; uint32_t num_of_items = 0; @@ -3500,6 +3595,11 @@ static void avrcp_get_total_numberofitems(struct avrcp *session) struct avrcp_player *player = session->controller->player; struct avrcp_browsing_header *pdu = (void *) buf; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return; +#endif + memset(buf, 0, sizeof(buf)); pdu->pdu_id = AVRCP_GET_TOTAL_NUMBER_OF_ITEMS; @@ -3803,6 +3903,12 @@ static void avrcp_status_changed(struct avrcp *session, struct avrcp_header *pdu) { struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return; +#endif + struct media_player *mp = player->user_data; uint8_t value; const char *curval, *strval; @@ -3824,6 +3930,11 @@ static void avrcp_track_changed(struct avrcp *session, { if (session->browsing_id) { struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return; +#endif player->uid = get_be64(&pdu->params[1]); avrcp_get_item_attributes(session, player->uid); } else @@ -3834,6 +3945,12 @@ static void avrcp_playback_pos_changed(struct avrcp *session, struct avrcp_header *pdu) { struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return; +#endif + struct media_player *mp = player->user_data; uint32_t position; @@ -3845,6 +3962,12 @@ static void avrcp_setting_changed(struct avrcp *session, struct avrcp_header *pdu) { struct avrcp_player *player = session->controller->player; + +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return; +#endif + struct media_player *mp = player->user_data; uint8_t count = pdu->params[1]; int i; @@ -3901,6 +4024,11 @@ static void avrcp_uids_changed(struct avrcp *session, struct avrcp_header *pdu) { struct avrcp_player *player = session->controller->player; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + if (!player) + return; +#endif + player->uid_counter = get_be16(&pdu->params[1]); } @@ -4102,6 +4230,7 @@ static gboolean avrcp_get_capabilities_resp(struct avctp *conn, uint8_t code, if (!(events & (1 << AVRCP_EVENT_STATUS_CHANGED))) avrcp_get_element_attributes(session); + #ifdef TIZEN_FEATURE_BLUEZ_MODIFY if ((events & (1 << AVRCP_EVENT_STATUS_CHANGED)) == 0) { session->playback_status_id = g_timeout_add_seconds(1, @@ -4295,6 +4424,8 @@ static void controller_init(struct avrcp *session) DBG("%p version 0x%04x", controller, controller->version); #ifdef TIZEN_FEATURE_BLUEZ_MODIFY + session->controller->player = NULL; + if ((controller->version >= 0x0104) && (adapter_avrcp_ct_ver >= 0x0104)) session->supported_events |= (1 << AVRCP_EVENT_VOLUME_CHANGED); #endif -- 2.7.4