Skip to contentSkip to conversation

android: Add LE Peripheral role support

PATCH In review Martin Fuzzey 2 participants 5 messages Oct 13, 2017 – Nov 6, 2017 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

v2 cover android: Add LE Peripheral role support

This series adds a few missing pieces for Peripheral role support on Android 5.

This has been tested in the following configuration:
- Android 5.1.1
- Kernel 4.4
- nRF52 chip running Apache Newt firmware

Changes for V2:
- Only load keys if BRDE supported rather than always trying and ignoring error
- Use the bt_ad_* helper functions rather than open coding advertisement data
- free_adv_instance() accepts NULL like the other free family members
- Style fixes
- Remove SOBs

#1 lore raw

PATCH v2 1/3 android: Skip key loading for LE only devices.

Key loading is not supported for LE only devices.

---
 android/bluetooth.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
android/bluetooth.c +5 -1
index 51a31fe..c3ad5ce 100644
@@ -3265,7 +3265,11 @@ static void load_devices_info(bt_bluetooth_ready cb)
 	load_irks(irks);
 	g_slist_free_full(irks, g_free);
 
-	load_link_keys(keys, cb);
+	if (adapter.supported_settings & MGMT_SETTING_BREDR)
+		load_link_keys(keys, cb);
+	else
+		cb(0, &adapter.bdaddr);
+
 	g_slist_free_full(keys, g_free);
 
 	g_strfreev(devs);
#2 lore raw

PATCH v2 2/3 android: Get max advertising instances from kernel

In reply to Martin Fuzzey

Use the mgmnt "advinfo" operation to obtain the number of advertising instances supported by the kernel.

---
 android/bluetooth.c |   44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
android/bluetooth.c +43 -1
index c3ad5ce..b5a2eab 100644
@@ -3336,6 +3336,37 @@ static void clear_auto_connect_list(void)
 	error("Could not clear auto connect list");
 }
 
+static void read_adv_features_complete(uint8_t status, uint16_t length,
+					const void *param, void *user_data)
+{
+	const struct mgmt_rp_read_adv_features *rp = param;
+	bt_bluetooth_ready cb = user_data;
+	int err;
+
+	if (status) {
+		error("Failed to read advertising features for index %u: %s (0x%02x)",
+				adapter.index, mgmt_errstr(status), status);
+		err = -EIO;
+		goto failed;
+	}
+
+	if (length < sizeof(*rp)) {
+		error("Too small read advertising features response");
+		err = -EIO;
+		goto failed;
+	}
+
+	adapter.max_advert_instance = rp->max_instances;
+	info("Max LE advertising instances: %d", adapter.max_advert_instance);
+
+	load_devices_info(cb);
+
+	return;
+
+failed:
+	cb(err, NULL);
+}
+
 static void read_info_complete(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -3407,7 +3438,18 @@ static void read_info_complete(uint8_t status, uint16_t length,
 	if (missing_settings & MGMT_SETTING_BONDABLE)
 		set_mode(MGMT_OP_SET_BONDABLE, 0x01);
 
-	load_devices_info(cb);
+	if (adapter.supported_settings & MGMT_SETTING_LE) {
+		if (mgmt_send(mgmt_if, MGMT_OP_READ_ADV_FEATURES, adapter.index,
+			      0, NULL,
+			      read_adv_features_complete, cb, NULL) == 0) {
+			error("Cannot get LE adv features");
+			err = -EIO;
+			goto failed;
+		}
+	} else {
+		load_devices_info(cb);
+	}
+
 	load_devices_cache();
 
 	return;
#3 lore raw

PATCH v2 3/3 android: Enable multiadvertising

In reply to Martin Fuzzey

This is required for custom advertising data.

The HAL entry points related to multiadvertising are now implemented and map to the mgmnt "add advertising" operation.

---
 android/Android.mk  |    1 
 android/bluetooth.c |  129 +++++++++++++++++++++
 android/bluetooth.h |   25 ++++
 android/gatt.c      |  309 +++++++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 454 insertions(+), 10 deletions(-)
android/Android.mk +1 -0
index 38ef4aa..76a826b 100644
@@ -72,6 +72,7 @@ LOCAL_SRC_FILES := \
 	bluez/src/shared/crypto.c \
 	bluez/src/shared/uhid.c \
 	bluez/src/shared/att.c \
+	bluez/src/shared/ad.c \
 	bluez/src/sdpd-database.c \
 	bluez/src/sdpd-service.c \
 	bluez/src/sdpd-request.c \
android/bluetooth.c +129 -0

141 lines not on this page · raw message

android/bluetooth.h +25 -0
index 4b17209..b139cb1 100644
@@ -88,3 +88,28 @@ typedef void (*bt_paired_device_cb)(const bdaddr_t *addr);
 bool bt_paired_register(bt_paired_device_cb cb);
 void bt_paired_unregister(bt_paired_device_cb cb);
 bool bt_is_pairing(const bdaddr_t *addr);
+
+struct bt_ad;
+struct adv_instance {
+	uint8_t	instance;
+	int32_t timeout;
+	int32_t type;
+	struct bt_ad *ad;
+	struct bt_ad *sr;
+	unsigned include_tx_power:1;
+};
+
+/* Values below have no C API definition - only in Java (AdvertiseManager.java)
+ * and bluedroid
+ */
+enum android_adv_type {
+	ANDROID_ADVERTISING_EVENT_TYPE_CONNECTABLE = 0,
+	ANDROID_ADVERTISING_EVENT_TYPE_SCANNABLE = 2,
+	ANDROID_ADVERTISING_EVENT_TYPE_NON_CONNECTABLE = 3,
+};
+
+typedef void (*bt_le_addrm_advertising_done)(uint8_t status, void *user_data);
+bool bt_le_add_advertising(struct adv_instance *adv,
+		bt_le_addrm_advertising_done cb, void *user_data);
+bool bt_le_remove_advertising(struct adv_instance *adv,
+		bt_le_addrm_advertising_done cb, void *user_data);
android/gatt.c +299 -10

385 lines not on this page · raw message

#4 lore raw
In reply to Martin Fuzzey

Hi Martin,

Quoted 8 lines · On Friday, 13 October 2017 16:02:04 CET Martin Fuzzey wrote:

This series adds a few missing pieces for Peripheral role support on Android 5.

This has been tested in the following configuration:
- Android 5.1.1
- Kernel 4.4
- nRF52 chip running Apache Newt firmware

Quoted 7 lines

Changes for V2:
- Only load keys if BRDE supported rather than always trying and ignoring error - Use the bt_ad_* helper functions rather than open coding advertisement data - free_adv_instance() accepts NULL like the other free family members - Style fixes
- Remove SOBs

All patches applied, thanks.
Note that I had to fix last patch to build on Fedora (print formatters).

Signature · 2 lines
pozdrawiam
Szymon Janc