audio/A2DP: Add implemention of SEP open indication
Luiz Augusto von Dentz
maintainerPATCH 1/12 audio/A2DP: Add implemention of SEP open indication
From: Luiz Augusto von Dentz <[email protected]>
--- android/a2dp.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-)
android/a2dp.c +35 -14
@@ -581,9 +581,44 @@ static gboolean sep_setconf_ind(struct avdtp *session,return TRUE; } +static struct a2dp_setup *find_setup (uint8_t id) +{ +GSList *l; + +for (l = setups; l; l =g_slist_next (l)) { +struct a2dp_setup *setup = l->data; + +if (setup->endpoint->id == id) +return setup; + } + +return NULL ; +} + +static gboolean sep_open_ind (struct avdtp *session,struct avdtp_local_sep *sep, +struct avdtp_stream *stream,uint8_t *err, +void *user_data) +{ +struct a2dp_endpoint *endpoint = user_data; +struct a2dp_setup *setup; + +DBG ("" ); + + setup =find_setup (endpoint->id); +if (!setup) { +error ("Unable to find stream setup for endpoint %u" , + endpoint->id); + *err =AVDTP_SEP_NOT_IN_USE ; +return FALSE; + } + +return TRUE; +} +static struct avdtp_sep_ind sep_ind = { .get_capability = sep_getcap_ind, .set_configuration = sep_setconf_ind, + .open = sep_open_ind, }; static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec,
@@ -713,20 +748,6 @@ static void bt_audio_close(const void *buf, uint16_t len)audio_ipc_send_rsp (AUDIO_OP_CLOSE ,AUDIO_STATUS_SUCCESS ); } -static struct a2dp_setup *find_setup (uint8_t id) -{ -GSList *l; - -for (l = setups; l; l =g_slist_next (l)) { -struct a2dp_setup *setup = l->data; - -if (setup->endpoint->id == id) -return setup; - } - -return NULL ; -} -static void bt_stream_open (const void *buf,uint16_t len) {const struct audio_cmd_open_stream *cmd = buf;
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerPATCH 2/12 audio/A2DP: Add implemention of SEP close indication
From: Luiz Augusto von Dentz <[email protected]>
--- android/a2dp.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
android/a2dp.c +31 -0
@@ -514,6 +514,12 @@ static void setup_free(void *data)g_free (setup); } +static void setup_remove (struct a2dp_setup *setup) +{ + setups =g_slist_remove (setups, setup); +setup_free (setup); +} +static void setup_add (struct a2dp_device *dev,struct a2dp_endpoint *endpoint,struct a2dp_preset *preset,struct avdtp_stream *stream) {
@@ -615,10 +621,35 @@ static gboolean sep_open_ind(struct avdtp *session, struct avdtp_local_sep *sep,return TRUE; } +static gboolean sep_close_ind (struct avdtp *session, +struct avdtp_local_sep *sep, +struct avdtp_stream *stream, +uint8_t *err, +void *user_data) +{ +struct a2dp_endpoint *endpoint = user_data; +struct a2dp_setup *setup; + +DBG ("" ); + + setup =find_setup (endpoint->id); +if (!setup) { +error ("Unable to find stream setup for endpoint %u" , + endpoint->id); + *err =AVDTP_SEP_NOT_IN_USE ; +return FALSE; + } + +setup_remove (setup); + +return TRUE; +} +static struct avdtp_sep_ind sep_ind = { .get_capability = sep_getcap_ind, .set_configuration = sep_setconf_ind, .open = sep_open_ind, + .close = sep_close_ind, }; static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec,
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerPATCH 3/12 audio/A2DP: Add implemention of SEP start indication
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/a2dp.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
android/a2dp.c +23 -0
@@ -645,11 +645,34 @@ static gboolean sep_close_ind(struct avdtp *session,return TRUE; } +static gboolean sep_start_ind (struct avdtp *session, +struct avdtp_local_sep *sep, +struct avdtp_stream *stream, +uint8_t *err, +void *user_data) +{ +struct a2dp_endpoint *endpoint = user_data; +struct a2dp_setup *setup; + +DBG ("" ); + + setup =find_setup (endpoint->id); +if (!setup) { +error ("Unable to find stream setup for endpoint %u" , + endpoint->id); + *err =AVDTP_SEP_NOT_IN_USE ; +return FALSE; + } + +return TRUE; +} +static struct avdtp_sep_ind sep_ind = { .get_capability = sep_getcap_ind, .set_configuration = sep_setconf_ind, .open = sep_open_ind, .close = sep_close_ind, + .start = sep_start_ind, }; static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec,
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerPATCH 4/12 audio/A2DP: Add implemention of SEP suspend indication
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/a2dp.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
android/a2dp.c +23 -0
@@ -667,12 +667,35 @@ static gboolean sep_start_ind(struct avdtp *session,return TRUE; } +static gboolean sep_suspend_ind (struct avdtp *session, +struct avdtp_local_sep *sep, +struct avdtp_stream *stream, +uint8_t *err, +void *user_data) +{ +struct a2dp_endpoint *endpoint = user_data; +struct a2dp_setup *setup; + +DBG ("" ); + + setup =find_setup (endpoint->id); +if (!setup) { +error ("Unable to find stream setup for endpoint %u" , + endpoint->id); + *err =AVDTP_SEP_NOT_IN_USE ; +return FALSE; + } + +return TRUE; +} +static struct avdtp_sep_ind sep_ind = { .get_capability = sep_getcap_ind, .set_configuration = sep_setconf_ind, .open = sep_open_ind, .close = sep_close_ind, .start = sep_start_ind, + .suspend = sep_suspend_ind, }; static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec,
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerPATCH 5/12 android/A2DP: Discover endpoints when initiator
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/a2dp.c | 244 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 184 insertions(+), 60 deletions(-)
android/a2dp.c +184 -60
@@ -173,6 +173,166 @@ static void disconnect_cb(void *user_data)bt_a2dp_notify_state (dev,HAL_A2DP_STATE_DISCONNECTED ); } +static int sbc_check_config (void *caps,uint8_t caps_len,void *conf, +uint8_t conf_len) +{ +a2dp_sbc_t *cap, *config; + +if (conf_len != caps_len || conf_len !=sizeof (a2dp_sbc_t)) { +error ("SBC: Invalid configuration size (%u)" , conf_len); +return -EINVAL ; + } + + cap = caps; + config = conf; + +if (!(cap->frequency & config->frequency)) { +error ("SBC: Unsupported frequency (%u) by endpoint" , + config->frequency); +return -EINVAL ; + } + +if (!(cap->channel_mode & config->channel_mode)) { +error ("SBC: Unsupported channel mode (%u) by endpoint" , + config->channel_mode); +return -EINVAL ; + } + +if (!(cap->block_length & config->block_length)) { +error ("SBC: Unsupported block length (%u) by endpoint" , + config->block_length); +return -EINVAL ; + } + +if (!(cap->allocation_method & config->allocation_method)) { +error ("SBC: Unsupported allocation method (%u) by endpoint" , + config->block_length); +return -EINVAL ; + } + +return 0 ; +} + +static int check_capabilities (struct a2dp_preset *preset, +struct avdtp_media_codec_capability *codec, +uint8_t codec_len) +{ +/* Codec specific */ +switch (codec->media_codec_type) { +case A2DP_CODEC_SBC : +return sbc_check_config (codec->data, codec_len, preset->data, + preset->len); +default : +return -EINVAL ; + } +} + +static struct a2dp_preset *select_preset (struct a2dp_endpoint *endpoint, +struct avdtp_remote_sep *rsep) +{ +struct avdtp_service_capability *service; +struct avdtp_media_codec_capability *codec; +GSList *l; + + service =avdtp_get_codec (rsep); + codec = (struct avdtp_media_codec_capability *) service->data; + +for (l = endpoint->presets; l; l =g_slist_next (l)) { +struct a2dp_preset *preset = l->data; + +if (check_capabilities (preset, codec, + service->length -sizeof (*codec)) ==0 ) +return preset; + } + +return NULL ; +} + +static void setup_add (struct a2dp_device *dev,struct a2dp_endpoint *endpoint, +struct a2dp_preset *preset,struct avdtp_stream *stream) +{ +struct a2dp_setup *setup; + + setup = g_new0(struct a2dp_setup, 1); + setup->dev = dev; + setup->endpoint = endpoint; + setup->preset = preset; + setup->stream = stream; + setups =g_slist_append (setups, setup); +} + +static int select_configuration (struct a2dp_device *dev, +struct a2dp_endpoint *endpoint, +struct avdtp_remote_sep *rsep) +{ +struct a2dp_preset *preset; +struct avdtp_stream *stream; +struct avdtp_service_capability *service; +struct avdtp_media_codec_capability *codec; +GSList *caps; +int err; + + preset =select_preset (endpoint, rsep); +if (!preset) { +error ("Unable to select codec preset" ); +return -EINVAL ; + } + + service =avdtp_service_cap_new (AVDTP_MEDIA_TRANSPORT ,NULL ,0 ); + caps =g_slist_append (NULL , service); + + codec =g_malloc0 (sizeof (*codec) +sizeof (preset->len)); + codec->media_type =AVDTP_MEDIA_TYPE_AUDIO ; + codec->media_codec_type = endpoint->codec; +memcpy (codec->data, preset->data, preset->len); + + service =avdtp_service_cap_new (AVDTP_MEDIA_CODEC , codec, +sizeof (*codec) + preset->len); + caps =g_slist_append (caps, service); + + err =avdtp_set_configuration (dev->session, rsep, endpoint->sep, caps, + &stream); +g_slist_free_full (caps, g_free); +if (err <0 ) { +error ("avdtp_set_configuration: %s" ,strerror (-err)); +return err; + } + +setup_add (dev, endpoint, preset, stream); + +return 0 ; +} + +static void discover_cb (struct avdtp *session,GSList *seps, +struct avdtp_error *err,void *user_data) +{ +struct a2dp_device *dev = user_data; +struct a2dp_endpoint *endpoint =NULL ; +struct avdtp_remote_sep *rsep =NULL ; +GSList *l; + +for (l = endpoints; l; l =g_slist_next (l)) { + endpoint = l->data; + + rsep =avdtp_find_remote_sep (session, endpoint->sep); +if (rsep) +break ; + } + +if (!rsep) { +error ("Unable to find matching endpoint" ); + goto failed; + } + +if (select_configuration (dev, endpoint, rsep) <0 ) + goto failed; + +return ; + +failed: +avdtp_shutdown (session); +} +static void signaling_connect_cb (GIOChannel *chan,GError *err,gpointer user_data) {
@@ -192,20 +352,17 @@ static void signaling_connect_cb(GIOChannel *chan, GError *err,BT_IO_OPT_OMTU , &omtu, BT_IO_OPT_INVALID);if (gerr) { -bt_a2dp_notify_state (dev,HAL_A2DP_STATE_DISCONNECTED );error ("%s" , gerr->message);g_error_free (gerr); -return ; + goto failed; } fd =g_io_channel_unix_get_fd (chan);/* FIXME: Add proper version */ dev->session =avdtp_new (fd, imtu, omtu,0x0100 ); -if (!dev->session) { -bt_a2dp_notify_state (dev,HAL_A2DP_STATE_DISCONNECTED ); -return ; - } +if (!dev->session) + goto failed;avdtp_add_disconnect_cb (dev->session, disconnect_cb, dev);
@@ -214,7 +371,23 @@ static void signaling_connect_cb(GIOChannel *chan, GError *err, dev->io =NULL ; } +/* Proceed to stream setup if initiator */ +if (dev->state ==HAL_A2DP_STATE_CONNECTING ) { +int perr; + + perr =avdtp_discover (dev->session, discover_cb, dev); +if (perr <0 ) { +error ("avdtp_discover: %s" ,strerror (-perr)); + goto failed; + } + } +bt_a2dp_notify_state (dev,HAL_A2DP_STATE_CONNECTED ); + +return ; + +failed: +bt_a2dp_notify_state (dev,HAL_A2DP_STATE_DISCONNECTED ); }static void bt_a2dp_connect (const void *buf,uint16_t len)
@@ -428,50 +601,11 @@ static gboolean sep_getcap_ind(struct avdtp *session,return TRUE; } -static int sbc_check_config (struct a2dp_endpoint *endpoint, -struct a2dp_preset *conf) -{ -a2dp_sbc_t *caps, *config; - -if (conf->len !=sizeof (a2dp_sbc_t)) { -error ("SBC: Invalid configuration size (%u)" , conf->len); -return -EINVAL ; - } - - caps = endpoint->caps->data; - config = conf->data; - -if (!(caps->frequency & config->frequency)) { -error ("SBC: Unsupported frequency (%u) by endpoint" , - config->frequency); -return -EINVAL ; - } - -if (!(caps->channel_mode & config->channel_mode)) { -error ("SBC: Unsupported channel mode (%u) by endpoint" , - config->channel_mode); -return -EINVAL ; - } - -if (!(caps->block_length & config->block_length)) { -error ("SBC: Unsupported block length (%u) by endpoint" , - config->block_length); -return -EINVAL ; - } - -if (!(caps->allocation_method & config->allocation_method)) { -error ("SBC: Unsupported allocation method (%u) by endpoint" , - config->block_length); -return -EINVAL ; - } - -return 0 ; -} -static int check_config (struct a2dp_endpoint *endpoint,struct a2dp_preset *config) {GSList *l; +struct a2dp_preset *caps;for (l = endpoint->presets; l; l =g_slist_next (l)) {struct a2dp_preset *preset = l->data;
@@ -483,10 +617,13 @@ static int check_config(struct a2dp_endpoint *endpoint,return 0 ; } + caps = endpoint->caps; +/* Codec specific */ switch (endpoint->codec) {case A2DP_CODEC_SBC : -return sbc_check_config (endpoint, config); +return sbc_check_config (caps->data, caps->len, config->data, + config->len);default :return -EINVAL ; }
@@ -520,19 +657,6 @@ static void setup_remove(struct a2dp_setup *setup)setup_free (setup); } -static void setup_add (struct a2dp_device *dev,struct a2dp_endpoint *endpoint, -struct a2dp_preset *preset,struct avdtp_stream *stream) -{ -struct a2dp_setup *setup; - - setup = g_new0(struct a2dp_setup, 1); - setup->dev = dev; - setup->endpoint = endpoint; - setup->preset = preset; - setup->stream = stream; - setups =g_slist_append (setups, setup); -} - static gboolean sep_setconf_ind(struct avdtp *session, struct avdtp_local_sep *sep, struct avdtp_stream *stream,
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerPATCH 6/12 audio/A2DP: Add implemention of SEP set_configuration confirmation
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/a2dp.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)
android/a2dp.c +38 -2
@@ -822,6 +822,42 @@ static struct avdtp_sep_ind sep_ind = { .suspend = sep_suspend_ind, }; +static void sep_setconf_cfm (struct avdtp *session,struct avdtp_local_sep *sep, +struct avdtp_stream *stream, +struct avdtp_error *err,void *user_data) +{ +struct a2dp_endpoint *endpoint = user_data; +struct a2dp_setup *setup; +int ret; + +DBG ("" ); + + setup =find_setup (endpoint->id); +if (!setup) { +error ("Unable to find stream setup for endpoint %u" , + endpoint->id); +return ; + } + +if (err) + goto failed; + + ret =avdtp_open (session, stream); +if (ret <0 ) { +error ("avdtp_open: %s" ,strerror (-ret)); + goto failed; + } + +return ; + +failed: +setup_remove (setup); +} + +static struct avdtp_sep_cfm sep_cfm = { + .set_configuration = sep_setconf_cfm, +}; +static uint8_t register_endpoint (const uint8_t *uuid,uint8_t codec,GSList *presets) {
@@ -834,8 +870,8 @@ static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec, endpoint->codec = codec; endpoint->sep =avdtp_register_sep (AVDTP_SEP_TYPE_SOURCE ,AVDTP_MEDIA_TYPE_AUDIO , - codec, FALSE, &sep_ind,NULL , - endpoint); + codec, FALSE, &sep_ind, + &sep_cfm, endpoint); endpoint->caps = presets->data; endpoint->presets =g_slist_copy (g_slist_nth (presets,1 ));
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerPATCH 7/12 audio/A2DP: Add implemention of SEP open confirmation
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/a2dp.c | 56 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 14 deletions(-)
android/a2dp.c +42 -14
@@ -657,6 +657,33 @@ static void setup_remove(struct a2dp_setup *setup)setup_free (setup); } +static struct a2dp_setup *find_setup (uint8_t id) +{ +GSList *l; + +for (l = setups; l; l =g_slist_next (l)) { +struct a2dp_setup *setup = l->data; + +if (setup->endpoint->id == id) +return setup; + } + +return NULL ; +} + +static void setup_remove_by_id (uint8_t id) +{ +struct a2dp_setup *setup; + + setup =find_setup (id); +if (!setup) { +error ("Unable to find stream setup for endpoint %u" , id); +return ; + } + +setup_remove (setup); +} + static gboolean sep_setconf_ind(struct avdtp *session, struct avdtp_local_sep *sep, struct avdtp_stream *stream,
@@ -711,20 +738,6 @@ static gboolean sep_setconf_ind(struct avdtp *session,return TRUE; } -static struct a2dp_setup *find_setup (uint8_t id) -{ -GSList *l; - -for (l = setups; l; l =g_slist_next (l)) { -struct a2dp_setup *setup = l->data; - -if (setup->endpoint->id == id) -return setup; - } - -return NULL ; -} -static gboolean sep_open_ind (struct avdtp *session,struct avdtp_local_sep *sep,struct avdtp_stream *stream,uint8_t *err,void *user_data)
@@ -854,8 +867,23 @@ failed:setup_remove (setup); } +static void sep_open_cfm (struct avdtp *session,struct avdtp_local_sep *sep, +struct avdtp_stream *stream,struct avdtp_error *err, +void *user_data) +{ +struct a2dp_endpoint *endpoint = user_data; + +DBG ("" ); + +if (!err) +return ; + +setup_remove_by_id (endpoint->id); +} +static struct avdtp_sep_cfm sep_cfm = { .set_configuration = sep_setconf_cfm, + .open = sep_open_cfm, }; static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec,
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerPATCH 8/12 audio/A2DP: Add implemention of SEP start confirmation
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/a2dp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
android/a2dp.c +15 -0
@@ -881,9 +881,24 @@ static void sep_open_cfm(struct avdtp *session, struct avdtp_local_sep *sep,setup_remove_by_id (endpoint->id); } +static void sep_start_cfm (struct avdtp *session,struct avdtp_local_sep *sep, +struct avdtp_stream *stream,struct avdtp_error *err, +void *user_data) +{ +struct a2dp_endpoint *endpoint = user_data; + +DBG ("" ); + +if (!err) +return ; + +setup_remove_by_id (endpoint->id); +} +static struct avdtp_sep_cfm sep_cfm = { .set_configuration = sep_setconf_cfm, .open = sep_open_cfm, + .start = sep_start_cfm, }; static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec,
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerPATCH 9/12 audio/A2DP: Add implemention of SEP suspend confirmation
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/a2dp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
android/a2dp.c +15 -0
@@ -895,10 +895,25 @@ static void sep_start_cfm(struct avdtp *session, struct avdtp_local_sep *sep,setup_remove_by_id (endpoint->id); } +static void sep_suspend_cfm (struct avdtp *session,struct avdtp_local_sep *sep, +struct avdtp_stream *stream,struct avdtp_error *err, +void *user_data) +{ +struct a2dp_endpoint *endpoint = user_data; + +DBG ("" ); + +if (!err) +return ; + +setup_remove_by_id (endpoint->id); +} +static struct avdtp_sep_cfm sep_cfm = { .set_configuration = sep_setconf_cfm, .open = sep_open_cfm, .start = sep_start_cfm, + .suspend = sep_suspend_cfm, }; static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec,
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerPATCH 10/12 audio/A2DP: Add implemention of SEP close confirmation
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/a2dp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
android/a2dp.c +15 -0
@@ -909,11 +909,26 @@ static void sep_suspend_cfm(struct avdtp *session, struct avdtp_local_sep *sep,setup_remove_by_id (endpoint->id); } +static void sep_close_cfm (struct avdtp *session,struct avdtp_local_sep *sep, +struct avdtp_stream *stream,struct avdtp_error *err, +void *user_data) +{ +struct a2dp_endpoint *endpoint = user_data; + +DBG ("" ); + +if (err) +return ; + +setup_remove_by_id (endpoint->id); +} +static struct avdtp_sep_cfm sep_cfm = { .set_configuration = sep_setconf_cfm, .open = sep_open_cfm, .start = sep_start_cfm, .suspend = sep_suspend_cfm, + .close = sep_close_cfm, }; static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec,
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerPATCH 11/12 audio/A2DP: Add implemention of SEP abort confirmation
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/a2dp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
android/a2dp.c +15 -0
@@ -923,12 +923,27 @@ static void sep_close_cfm(struct avdtp *session, struct avdtp_local_sep *sep,setup_remove_by_id (endpoint->id); } +static void sep_abort_cfm (struct avdtp *session,struct avdtp_local_sep *sep, +struct avdtp_stream *stream,struct avdtp_error *err, +void *user_data) +{ +struct a2dp_endpoint *endpoint = user_data; + +DBG ("" ); + +if (err) +return ; + +setup_remove_by_id (endpoint->id); +} +static struct avdtp_sep_cfm sep_cfm = { .set_configuration = sep_setconf_cfm, .open = sep_open_cfm, .start = sep_start_cfm, .suspend = sep_suspend_cfm, .close = sep_close_cfm, + .abort = sep_abort_cfm, }; static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec,
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerPATCH 12/12 android/AVDTP: Fix invalid free of struct discover
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
If callback releases the last reference it can cause the following:
Invalid free() / delete / delete[] / realloc()
at 0x4A07577: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x386244EF7E: g_free (in /usr/lib64/libglib-2.0.so.0.3800.2)
by 0x410356: finalize_discovery (avdtp.c:933)
by 0x414462: session_cb (avdtp.c:2555)
by 0x38624492A5: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3800.2) by 0x3862449627: ??? (in /usr/lib64/libglib-2.0.so.0.3800.2)
by 0x3862449A39: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3800.2) by 0x403A95: main (main.c:439)
Address 0x4cf7af0 is 0 bytes inside a block of size 24 free'd
at 0x4A07577: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x386244EF7E: g_free (in /usr/lib64/libglib-2.0.so.0.3800.2)
by 0x410356: finalize_discovery (avdtp.c:933)
by 0x4110BC: avdtp_unref (avdtp.c:1026)
by 0x416491: a2dp_device_free (a2dp.c:122)
by 0x4165DF: bt_a2dp_notify_state (a2dp.c:166)
by 0x417170: discover_cb (a2dp.c:333)
by 0x41034E: finalize_discovery (avdtp.c:931)
by 0x414462: session_cb (avdtp.c:2555)
by 0x38624492A5: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3800.2) by 0x3862449627: ??? (in /usr/lib64/libglib-2.0.so.0.3800.2)
by 0x3862449A39: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3800.2)
--- android/avdtp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
android/avdtp.c +2 -1
@@ -923,6 +923,8 @@ static void finalize_discovery(struct avdtp *session, int err)if (!discover)return ; + session->discover =NULL ; +avdtp_error_init (&avdtp_err,AVDTP_ERRNO , err);if (discover->id >0 )
@@ -931,7 +933,6 @@ static void finalize_discovery(struct avdtp *session, int err) discover->cb (session, session->seps, err ? &avdtp_err :NULL , discover->user_data);g_free (discover); - session->discover =NULL ; }static void release_stream (struct avdtp_stream *stream,struct avdtp *session)
Signature · 1 line
1.8.4.2