From 072db8ed2e02f4d4f0cbbea1bd8979c659f7a471 Mon Sep 17 00:00:00 2001 From: Grzegorz Kolodziejczyk Date: Thu, 25 Jan 2018 16:53:29 +0100 Subject: [PATCH] tools/btpclient: Clear advertising data on reset Advertising data should be cleared on gap reset command. Change-Id: Ie54922e09a782cabe10da4742506d641bb63eead Signed-off-by: Amit Purwar --- tools/btpclient.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tools/btpclient.c b/tools/btpclient.c index 1ba32e0..40848c2 100644 --- a/tools/btpclient.c +++ b/tools/btpclient.c @@ -396,6 +396,24 @@ static void unreg_advertising_setup(struct l_dbus_message *message, l_dbus_message_builder_destroy(builder); } +static void ad_cleanup_service(void *service) +{ + struct service_data *s = service; + + l_free(s->uuid); + l_free(s); +} + +static void ad_cleanup(void) +{ + l_free(ad.local_name); + l_queue_destroy(ad.uuids, l_free); + l_queue_destroy(ad.services, ad_cleanup_service); + l_queue_destroy(ad.manufacturers, l_free); + + memset(&ad, 0, sizeof(ad)); +} + static void unreg_advertising_reply(struct l_dbus_proxy *proxy, struct l_dbus_message *result, void *user_data) @@ -423,6 +441,8 @@ static void unreg_advertising_reply(struct l_dbus_proxy *proxy, l_info("Unable to remove propety instance"); if (!l_dbus_unregister_interface(dbus, AD_IFACE)) l_info("Unable to unregister ad interface"); + + ad_cleanup(); } static void btp_gap_reset(uint8_t index, const void *param, uint16_t length, @@ -455,7 +475,7 @@ static void btp_gap_reset(uint8_t index, const void *param, uint16_t length, NULL); } - if (adapter->ad_proxy) + if (adapter->ad_proxy && ad.registered) if (!l_dbus_proxy_method_call(adapter->ad_proxy, "UnregisterAdvertisement", unreg_advertising_setup, @@ -652,24 +672,6 @@ failed: btp_send_error(btp, BTP_GAP_SERVICE, index, status); } -static void ad_cleanup_service(void *service) -{ - struct service_data *s = service; - - l_free(s->uuid); - l_free(s); -} - -static void ad_cleanup(void) -{ - l_free(ad.local_name); - l_queue_destroy(ad.uuids, l_free); - l_queue_destroy(ad.services, ad_cleanup_service); - l_queue_destroy(ad.manufacturers, l_free); - - memset(&ad, 0, sizeof(ad)); -} - static void ad_init(void) { ad.uuids = l_queue_new(); -- 2.7.4