diff mbox series

[Bluez,v2,03/10] advertising: Detect if extended advertising mgmt commands are supported

Message ID 20200918151041.Bluez.v2.3.I50d9faa25e9da6e71d77c83c7d47a5b135e88799@changeid
State Superseded
Headers show
Series [Bluez,v2,01/10] doc/advertising-api: update API with new interface | expand

Commit Message

Daniel Winkler Sept. 18, 2020, 10:13 p.m. UTC
We need to know if kernel supports the new MGMT interface. To do so, we
check the return from adapter's MGMT_OP_READ_COMMANDS call for the new
commands. This will later be used to route our requests for new
advertisements.

The change is tested by manually verifying that the correct MGMT
commands are used when the feature is and is not available in kernel.

Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
Reviewed-by: Alain Michaud <alainm@chromium.org>
---

Changes in v2:
- Uses btd_has_kernel_features to detect kernel command support

 src/adapter.c     | 4 ++++
 src/adapter.h     | 1 +
 src/advertising.c | 3 +++
 3 files changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/src/adapter.c b/src/adapter.c
index b2bd8b3f1..7811122c4 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -9653,6 +9653,10 @@  static void read_commands_complete(uint8_t status, uint16_t length,
 			DBG("kernel supports exp features");
 			kernel_features |= KERNEL_EXP_FEATURES;
 			break;
+		case MGMT_OP_ADD_EXT_ADV_PARAMS:
+			DBG("kernel supports ext adv commands");
+			kernel_features |= KERNEL_HAS_EXT_ADV_ADD_CMDS;
+			break;
 		default:
 			break;
 		}
diff --git a/src/adapter.h b/src/adapter.h
index b4d872b15..99802e287 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -246,6 +246,7 @@  enum kernel_features {
 	KERNEL_SET_SYSTEM_CONFIG	= 1 << 2,
 	KERNEL_EXP_FEATURES		= 1 << 3,
 	KERNEL_HAS_RESUME_EVT		= 1 << 4,
+	KERNEL_HAS_EXT_ADV_ADD_CMDS	= 1 << 5,
 };
 
 bool btd_has_kernel_features(uint32_t feature);
diff --git a/src/advertising.c b/src/advertising.c
index e5f25948d..ad2eeefb9 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -57,6 +57,7 @@  struct btd_adv_manager {
 	uint8_t max_ads;
 	uint32_t supported_flags;
 	unsigned int instance_bitmap;
+	bool extended_add_cmds;
 };
 
 #define AD_TYPE_BROADCAST 0
@@ -1426,6 +1427,8 @@  static struct btd_adv_manager *manager_create(struct btd_adapter *adapter,
 	manager->mgmt_index = btd_adapter_get_index(adapter);
 	manager->clients = queue_new();
 	manager->supported_flags = MGMT_ADV_FLAG_LOCAL_NAME;
+	manager->extended_add_cmds =
+			btd_has_kernel_features(KERNEL_HAS_EXT_ADV_ADD_CMDS);
 
 	if (!g_dbus_register_interface(btd_get_dbus_connection(),
 					adapter_get_path(manager->adapter),