mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-12-01 08:04:48 +08:00
core/advertising: Fix not waiting Add Advertising response
When registering a new instance it must wait MGMT_OP_ADD_ADVERTISING before replying to the client since the command can still fail.
This commit is contained in:
parent
95b4b4f795
commit
54906b01d1
@ -395,24 +395,48 @@ static bool parse_advertising_include_tx_power(GDBusProxy *proxy,
|
||||
return true;
|
||||
}
|
||||
|
||||
static void add_adverting_complete(struct advertisement *ad, uint8_t status)
|
||||
{
|
||||
DBusMessage *reply;
|
||||
|
||||
if (status) {
|
||||
error("Failed to add advertisement: %s (0x%02x)",
|
||||
mgmt_errstr(status), status);
|
||||
reply = btd_error_failed(ad->reg,
|
||||
"Failed to register advertisement");
|
||||
queue_remove(ad->manager->ads, ad);
|
||||
g_idle_add(advertisement_free_idle_cb, ad);
|
||||
|
||||
} else
|
||||
reply = dbus_message_new_method_return(ad->reg);
|
||||
|
||||
g_dbus_send_message(btd_get_dbus_connection(), reply);
|
||||
dbus_message_unref(ad->reg);
|
||||
ad->reg = NULL;
|
||||
}
|
||||
|
||||
static void add_advertising_callback(uint8_t status, uint16_t length,
|
||||
const void *param, void *user_data)
|
||||
{
|
||||
struct advertisement *ad = user_data;
|
||||
const struct mgmt_rp_add_advertising *rp = param;
|
||||
|
||||
if (status || !param) {
|
||||
error("Failed to add advertisement: %s (0x%02x)",
|
||||
mgmt_errstr(status), status);
|
||||
return;
|
||||
}
|
||||
if (status)
|
||||
goto done;
|
||||
|
||||
if (length < sizeof(*rp)) {
|
||||
error("Wrong size of add advertising response");
|
||||
return;
|
||||
if (!param || length < sizeof(*rp)) {
|
||||
status = MGMT_STATUS_FAILED;
|
||||
goto done;
|
||||
}
|
||||
|
||||
ad->instance = rp->instance;
|
||||
|
||||
g_dbus_client_set_disconnect_watch(ad->client, client_disconnect_cb,
|
||||
ad);
|
||||
DBG("Advertisement registered: %s", ad->path);
|
||||
|
||||
done:
|
||||
add_adverting_complete(ad, status);
|
||||
}
|
||||
|
||||
static size_t calc_max_adv_len(struct advertisement *ad, uint32_t flags)
|
||||
@ -541,24 +565,14 @@ static void advertisement_proxy_added(GDBusProxy *proxy, void *data)
|
||||
DBusMessage *reply;
|
||||
|
||||
reply = parse_advertisement(ad);
|
||||
if (!reply)
|
||||
return;
|
||||
|
||||
if (reply) {
|
||||
/* Failed to publish for some reason, remove. */
|
||||
queue_remove(ad->manager->ads, ad);
|
||||
/* Failed to publish for some reason, remove. */
|
||||
queue_remove(ad->manager->ads, ad);
|
||||
|
||||
g_idle_add(advertisement_free_idle_cb, ad);
|
||||
g_idle_add(advertisement_free_idle_cb, ad);
|
||||
|
||||
goto done;
|
||||
}
|
||||
|
||||
g_dbus_client_set_disconnect_watch(ad->client, client_disconnect_cb,
|
||||
ad);
|
||||
|
||||
reply = dbus_message_new_method_return(ad->reg);
|
||||
|
||||
DBG("Advertisement registered: %s", ad->path);
|
||||
|
||||
done:
|
||||
g_dbus_send_message(btd_get_dbus_connection(), reply);
|
||||
|
||||
dbus_message_unref(ad->reg);
|
||||
|
Loading…
Reference in New Issue
Block a user