All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property
@ 2013-12-11 10:31 Szymon Janc
  2013-12-11 10:31 ` [PATCH 2/9] android/bluetooth: Add support for adapter bonded devices property Szymon Janc
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: Szymon Janc @ 2013-12-11 10:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This allows to get property with adapter type.
---
 android/bluetooth.c | 32 +++++++++++++++++++++++++++++---
 android/hal-msg.h   |  4 ++++
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index e456f3c..82003fd 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1674,13 +1674,39 @@ static uint8_t get_adapter_class(void)
 	return HAL_STATUS_SUCCESS;
 }
 
+static uint8_t settings2type(void)
+{
+	bool bredr, le;
+
+	bredr = adapter.current_settings & MGMT_SETTING_BREDR;
+	le = adapter.current_settings & MGMT_SETTING_LE;
+
+	if (bredr && le)
+		return HAL_TYPE_DUAL;
+
+	if (bredr && !le)
+		return HAL_TYPE_BREDR;
+
+	if (!bredr && le)
+		return HAL_TYPE_LE;
+
+	return 0;
+}
+
 static uint8_t get_adapter_type(void)
 {
-	DBG("Not implemented");
+	uint8_t type;
 
-	/* TODO: Add implementation */
+	DBG("");
 
-	return HAL_STATUS_FAILED;
+	type = settings2type();
+
+	if (!type)
+		return HAL_STATUS_FAILED;
+
+	send_adapter_property(HAL_PROP_ADAPTER_TYPE, sizeof(type), &type);
+
+	return HAL_STATUS_SUCCESS;
 }
 
 static uint8_t get_adapter_service_rec(void)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 80c4a25..3be91aa 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -116,6 +116,10 @@ struct hal_cmd_get_adapter_prop {
 #define HAL_ADAPTER_SCAN_MODE_CONN		0x01
 #define HAL_ADAPTER_SCAN_MODE_CONN_DISC	0x02
 
+#define HAL_TYPE_BREDR				0x01
+#define HAL_TYPE_LE				0x02
+#define HAL_TYPE_DUAL				0x03
+
 #define HAL_OP_SET_ADAPTER_PROP		0x05
 struct hal_cmd_set_adapter_prop {
 	uint8_t  type;
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/9] android/bluetooth: Add support for adapter bonded devices property
  2013-12-11 10:31 [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Szymon Janc
@ 2013-12-11 10:31 ` Szymon Janc
  2013-12-11 10:31 ` [PATCH 3/9] android/bluetooth: Add support for remote device friendly name Szymon Janc
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2013-12-11 10:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This allows to get property with list of bonded devices.
---
 android/bluetooth.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index 82003fd..b6ef3e6 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1729,11 +1729,26 @@ static uint8_t get_adapter_scan_mode(void)
 
 static uint8_t get_adapter_bonded_devices(void)
 {
-	DBG("Not implemented");
+	uint8_t buf[sizeof(bdaddr_t) * g_slist_length(devices)];
+	int i = 0;
+	GSList *l;
 
-	/* TODO: Add implementation */
+	DBG("");
 
-	return HAL_STATUS_FAILED;
+	for (l = devices; l; l = g_slist_next(l)) {
+		struct device *dev = l->data;
+
+		if (dev->bond_state != HAL_BOND_STATE_BONDED)
+			continue;
+
+		bdaddr2android(&dev->bdaddr, buf + (i * sizeof(bdaddr_t)));
+		i++;
+	}
+
+	send_adapter_property(HAL_PROP_ADAPTER_BONDED_DEVICES,
+						i * sizeof(bdaddr_t), buf);
+
+	return HAL_STATUS_SUCCESS;
 }
 
 static uint8_t get_adapter_discoverable_timeout(void)
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/9] android/bluetooth: Add support for remote device friendly name
  2013-12-11 10:31 [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Szymon Janc
  2013-12-11 10:31 ` [PATCH 2/9] android/bluetooth: Add support for adapter bonded devices property Szymon Janc
@ 2013-12-11 10:31 ` Szymon Janc
  2013-12-11 10:31 ` [PATCH 4/9] android/bluetooth: Free devices on service unregister Szymon Janc
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2013-12-11 10:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This allows to get and set remote device property with friendly name.
Storage support is still missing.
---
 android/bluetooth.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index b6ef3e6..e32ddd6 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -95,6 +95,7 @@ struct device {
 	bdaddr_t bdaddr;
 	int bond_state;
 	char *name;
+	char *friendly_name;
 };
 
 struct browse_req {
@@ -2282,11 +2283,13 @@ static uint8_t get_device_service_rec(struct device *dev)
 
 static uint8_t get_device_friendly_name(struct device *dev)
 {
-	DBG("Not implemented");
+	if (!dev->friendly_name)
+		return HAL_STATUS_FAILED;
 
-	/* TODO */
+	send_device_property(&dev->bdaddr, HAL_PROP_DEVICE_FRIENDLY_NAME,
+				strlen(dev->friendly_name), dev->friendly_name);
 
-	return HAL_STATUS_FAILED;
+	return HAL_STATUS_SUCCESS;
 }
 
 static uint8_t get_device_rssi(struct device *dev)
@@ -2377,13 +2380,20 @@ failed:
 								status);
 }
 
-static uint8_t set_device_friendly_name(struct device *dev)
+static uint8_t set_device_friendly_name(struct device *dev, const uint8_t *val,
+								uint16_t len)
 {
-	DBG("Not implemented");
+	DBG("");
 
-	/* TODO */
+	g_free(dev->friendly_name);
+	dev->friendly_name = g_strndup((const char *) val, len);
 
-	return HAL_STATUS_FAILED;
+	/* TODO store friendly name */
+
+	send_device_property(&dev->bdaddr, HAL_PROP_DEVICE_FRIENDLY_NAME,
+				strlen(dev->friendly_name), dev->friendly_name);
+
+	return HAL_STATUS_SUCCESS;
 }
 
 static uint8_t set_device_version_info(struct device *dev)
@@ -2419,7 +2429,7 @@ static void handle_set_remote_device_prop_cmd(const void *buf, uint16_t len)
 
 	switch (cmd->type) {
 	case HAL_PROP_DEVICE_FRIENDLY_NAME:
-		status = set_device_friendly_name(l->data);
+		status = set_device_friendly_name(l->data, cmd->val, cmd->len);
 		break;
 	case HAL_PROP_DEVICE_VERSION_INFO:
 		status = set_device_version_info(l->data);
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/9] android/bluetooth: Free devices on service unregister
  2013-12-11 10:31 [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Szymon Janc
  2013-12-11 10:31 ` [PATCH 2/9] android/bluetooth: Add support for adapter bonded devices property Szymon Janc
  2013-12-11 10:31 ` [PATCH 3/9] android/bluetooth: Add support for remote device friendly name Szymon Janc
@ 2013-12-11 10:31 ` Szymon Janc
  2013-12-11 10:31 ` [PATCH 5/9] android/bluetooth: Add support for remote device class Szymon Janc
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2013-12-11 10:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

There is no need to keep devices list in memory if service was
unregistered.
---
 android/bluetooth.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index e32ddd6..d6cefb7 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -154,6 +154,13 @@ static struct device *create_device(const bdaddr_t *bdaddr)
 	return dev;
 }
 
+static void free_device(struct device *dev)
+{
+	g_free(dev->name);
+	g_free(dev->friendly_name);
+	g_free(dev);
+}
+
 static struct device *get_device(const bdaddr_t *bdaddr)
 {
 	struct device *dev;
@@ -2557,5 +2564,8 @@ void bt_bluetooth_unregister(void)
 {
 	DBG("");
 
+	g_slist_free_full(devices, (GDestroyNotify) free_device);
+	devices = NULL;
+
 	ipc_unregister(HAL_SERVICE_ID_CORE);
 }
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/9] android/bluetooth: Add support for remote device class
  2013-12-11 10:31 [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Szymon Janc
                   ` (2 preceding siblings ...)
  2013-12-11 10:31 ` [PATCH 4/9] android/bluetooth: Free devices on service unregister Szymon Janc
@ 2013-12-11 10:31 ` Szymon Janc
  2013-12-11 10:31 ` [PATCH 6/9] android/bluetooth: Add support for remote device RSSI Szymon Janc
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2013-12-11 10:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This allows to cache remote device CoD and get it with get property
command.
---
 android/bluetooth.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index d6cefb7..0515468 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -96,6 +96,7 @@ struct device {
 	int bond_state;
 	char *name;
 	char *friendly_name;
+	uint32_t class;
 };
 
 struct browse_req {
@@ -594,6 +595,7 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
 {
 	const struct mgmt_ev_pin_code_request *ev = param;
 	struct hal_ev_pin_request hal_ev;
+	struct device *dev;
 	char dst[18];
 
 	if (length < sizeof(*ev)) {
@@ -603,19 +605,21 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
 
 	ba2str(&ev->addr.bdaddr, dst);
 
+	dev = get_device(&ev->addr.bdaddr);
+
 	/* Workaround for Android Bluetooth.apk issue: send remote
 	 * device property */
-	get_device_name(get_device(&ev->addr.bdaddr));
+	get_device_name(dev);
 
 	set_device_bond_state(&ev->addr.bdaddr, HAL_STATUS_SUCCESS,
 						HAL_BOND_STATE_BONDING);
 
 	DBG("%s type %u secure %u", dst, ev->addr.type, ev->secure);
 
-	/* TODO CoD of remote devices should probably be cached
-	 * Name we already send in remote device prop */
+	/* Name already sent in remote device prop */
 	memset(&hal_ev, 0, sizeof(hal_ev));
 	bdaddr2android(&ev->addr.bdaddr, hal_ev.bdaddr);
+	hal_ev.class_of_dev = dev->class;
 
 	ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_PIN_REQUEST,
 						sizeof(hal_ev), &hal_ev);
@@ -810,6 +814,8 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
 	}
 
 	if (eir.class) {
+		dev->class = eir.class;
+
 		size += fill_hal_prop(buf + size, HAL_PROP_DEVICE_CLASS,
 						sizeof(eir.class), &eir.class);
 		(*num_prop)++;
@@ -2263,11 +2269,10 @@ static uint8_t get_device_uuids(struct device *dev)
 
 static uint8_t get_device_class(struct device *dev)
 {
-	DBG("Not implemented");
+	send_device_property(&dev->bdaddr, HAL_PROP_DEVICE_CLASS,
+					sizeof(dev->class), &dev->class);
 
-	/* TODO */
-
-	return HAL_STATUS_FAILED;
+	return HAL_STATUS_SUCCESS;
 }
 
 static uint8_t get_device_type(struct device *dev)
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 6/9] android/bluetooth: Add support for remote device RSSI
  2013-12-11 10:31 [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Szymon Janc
                   ` (3 preceding siblings ...)
  2013-12-11 10:31 ` [PATCH 5/9] android/bluetooth: Add support for remote device class Szymon Janc
@ 2013-12-11 10:31 ` Szymon Janc
  2013-12-12  0:04   ` Anderson Lizardo
  2013-12-11 10:31 ` [PATCH 7/9] android/bluetooth: Add support for get remote device properties command Szymon Janc
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: Szymon Janc @ 2013-12-11 10:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This allows to cache remote device RSSI and get it with get property
command.
---
 android/bluetooth.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index 0515468..254ccb4 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -97,6 +97,7 @@ struct device {
 	char *name;
 	char *friendly_name;
 	uint32_t class;
+	int32_t rssi;
 };
 
 struct browse_req {
@@ -822,6 +823,8 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
 	}
 
 	if (rssi) {
+		dev->rssi = rssi;
+
 		size += fill_hal_prop(buf + size, HAL_PROP_DEVICE_RSSI,
 							sizeof(rssi), &rssi);
 		(*num_prop)++;
@@ -2306,11 +2309,13 @@ static uint8_t get_device_friendly_name(struct device *dev)
 
 static uint8_t get_device_rssi(struct device *dev)
 {
-	DBG("Not implemented");
+	if (!dev->rssi)
+		return HAL_STATUS_FAILED;
 
-	/* TODO */
+	send_device_property(&dev->bdaddr, HAL_PROP_DEVICE_RSSI,
+						sizeof(dev->rssi), &dev->rssi);
 
-	return HAL_STATUS_FAILED;
+	return HAL_STATUS_SUCCESS;
 }
 
 static uint8_t get_device_version_info(struct device *dev)
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 7/9] android/bluetooth: Add support for get remote device properties command
  2013-12-11 10:31 [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Szymon Janc
                   ` (4 preceding siblings ...)
  2013-12-11 10:31 ` [PATCH 6/9] android/bluetooth: Add support for remote device RSSI Szymon Janc
@ 2013-12-11 10:31 ` Szymon Janc
  2013-12-11 10:31 ` [PATCH 8/9] android/bluetooth: Add support for remote device type property Szymon Janc
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2013-12-11 10:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This allows to get all properties of specified remote device.
---
 android/bluetooth.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index 254ccb4..ffe1120 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -2338,10 +2338,34 @@ static uint8_t get_device_timestamp(struct device *dev)
 
 static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
 {
-	/* TODO */
+	const struct hal_cmd_get_remote_device_props *cmd = buf;
+	uint8_t status;
+	bdaddr_t addr;
+	GSList *l;
+
+	android2bdaddr(cmd->bdaddr, &addr);
+
+	l = g_slist_find_custom(devices, &addr, bdaddr_cmp);
+	if (!l) {
+		status = HAL_STATUS_INVALID;
+		goto failed;
+	}
 
+	get_device_name(l->data);
+	get_device_uuids(l->data);
+	get_device_class(l->data);
+	get_device_type(l->data);
+	get_device_service_rec(l->data);
+	get_device_friendly_name(l->data);
+	get_device_rssi(l->data);
+	get_device_version_info(l->data);
+	get_device_timestamp(l->data);
+
+	status = HAL_STATUS_SUCCESS;
+
+failed:
 	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_REMOTE_DEVICE_PROPS,
-							HAL_STATUS_FAILED);
+									status);
 }
 
 static void handle_get_remote_device_prop_cmd(const void *buf, uint16_t len)
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 8/9] android/bluetooth: Add support for remote device type property
  2013-12-11 10:31 [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Szymon Janc
                   ` (5 preceding siblings ...)
  2013-12-11 10:31 ` [PATCH 7/9] android/bluetooth: Add support for get remote device properties command Szymon Janc
@ 2013-12-11 10:31 ` Szymon Janc
  2013-12-11 10:31 ` [PATCH 9/9] android/bluetooth: Code style and whitespace cleanup Szymon Janc
  2013-12-11 13:50 ` [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Johan Hedberg
  8 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2013-12-11 10:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This makes daemon store remote device address type to be able to handle
remote device type property.
---
 android/bluetooth.c | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index ffe1120..b139ff7 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -93,6 +93,7 @@ static struct {
 
 struct device {
 	bdaddr_t bdaddr;
+	uint8_t bdaddr_type;
 	int bond_state;
 	char *name;
 	char *friendly_name;
@@ -135,7 +136,7 @@ static struct device *find_device(const bdaddr_t *bdaddr)
 	return NULL;
 }
 
-static struct device *create_device(const bdaddr_t *bdaddr)
+static struct device *create_device(const bdaddr_t *bdaddr, uint8_t type)
 {
 	struct device *dev;
 	char addr[18];
@@ -146,6 +147,7 @@ static struct device *create_device(const bdaddr_t *bdaddr)
 	dev = g_new0(struct device, 1);
 
 	bacpy(&dev->bdaddr, bdaddr);
+	dev->bdaddr_type = type;
 	dev->bond_state = HAL_BOND_STATE_NONE;
 
 	/* use address for name, will be change if one is present
@@ -163,7 +165,7 @@ static void free_device(struct device *dev)
 	g_free(dev);
 }
 
-static struct device *get_device(const bdaddr_t *bdaddr)
+static struct device *get_device(const bdaddr_t *bdaddr, uint8_t type)
 {
 	struct device *dev;
 
@@ -171,7 +173,7 @@ static struct device *get_device(const bdaddr_t *bdaddr)
 	if (dev)
 		return dev;
 
-	return create_device(bdaddr);
+	return create_device(bdaddr, type);
 }
 
 static  void send_adapter_property(uint8_t type, uint16_t len, const void *val)
@@ -369,7 +371,9 @@ static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
 
 	struct device *dev;
 
-	dev = get_device(addr);
+	dev = find_device(addr);
+	if (!dev)
+		return;
 
 	if (dev->bond_state != state) {
 		dev->bond_state = state;
@@ -606,7 +610,7 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
 
 	ba2str(&ev->addr.bdaddr, dst);
 
-	dev = get_device(&ev->addr.bdaddr);
+	dev = get_device(&ev->addr.bdaddr, BDADDR_BREDR);
 
 	/* Workaround for Android Bluetooth.apk issue: send remote
 	 * device property */
@@ -769,6 +773,14 @@ static int fill_hal_prop(void *buf, uint8_t type, uint16_t len,
 	return sizeof(*prop) + len;
 }
 
+static uint8_t bdaddr_type2android(uint8_t type)
+{
+	if (type == BDADDR_BREDR)
+		return HAL_TYPE_BREDR;
+
+	return HAL_TYPE_LE;
+}
+
 static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
 					int8_t rssi, bool confirm,
 					const uint8_t *data, uint8_t data_len)
@@ -789,8 +801,9 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
 	if (!dev) {
 		struct hal_ev_device_found *ev = (void *) buf;
 		bdaddr_t android_bdaddr;
+		uint8_t android_type;
 
-		dev = create_device(bdaddr);
+		dev = create_device(bdaddr, bdaddr_type);
 
 		size += sizeof(*ev);
 
@@ -802,6 +815,11 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
 		size += fill_hal_prop(buf + size, HAL_PROP_DEVICE_ADDR,
 				sizeof(android_bdaddr), &android_bdaddr);
 		(*num_prop)++;
+
+		android_type = bdaddr_type2android(dev->bdaddr_type);
+		size += fill_hal_prop(buf + size, HAL_PROP_DEVICE_TYPE,
+					sizeof(android_type), &android_type);
+		(*num_prop)++;
 	} else {
 		struct hal_ev_remote_device_props *ev = (void *) buf;
 
@@ -2280,11 +2298,12 @@ static uint8_t get_device_class(struct device *dev)
 
 static uint8_t get_device_type(struct device *dev)
 {
-	DBG("Not implemented");
+	uint8_t type = bdaddr_type2android(dev->bdaddr_type);
 
-	/* TODO */
+	send_device_property(&dev->bdaddr, HAL_PROP_DEVICE_TYPE,
+							sizeof(type), &type);
 
-	return HAL_STATUS_FAILED;
+	return HAL_STATUS_SUCCESS;
 }
 
 static uint8_t get_device_service_rec(struct device *dev)
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 9/9] android/bluetooth: Code style and whitespace cleanup
  2013-12-11 10:31 [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Szymon Janc
                   ` (6 preceding siblings ...)
  2013-12-11 10:31 ` [PATCH 8/9] android/bluetooth: Add support for remote device type property Szymon Janc
@ 2013-12-11 10:31 ` Szymon Janc
  2013-12-11 13:50 ` [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Johan Hedberg
  8 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2013-12-11 10:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This fix some random style or whitespace damages. Also moves statics
after last type definition.
---
 android/bluetooth.c | 63 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 33 insertions(+), 30 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index b139ff7..4bb2c92 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -52,20 +52,37 @@
 
 /* Default to DisplayYesNo */
 #define DEFAULT_IO_CAPABILITY 0x01
+
 /* Default discoverable timeout 120sec as in Android */
 #define DEFAULT_DISCOVERABLE_TIMEOUT 120
 
 #define BASELEN_PROP_CHANGED (sizeof(struct hal_ev_adapter_props_changed) \
-				+ (sizeof(struct hal_property)))
+					+ (sizeof(struct hal_property)))
 
 static uint16_t option_index = MGMT_INDEX_NONE;
 
 #define BASELEN_REMOTE_DEV_PROP (sizeof(struct hal_ev_remote_device_props) \
 					+ sizeof(struct hal_property))
-/* This list contains addresses which are asked for records */
-static GSList *browse_reqs;
 
-static struct mgmt *mgmt_if = NULL;
+struct device {
+	bdaddr_t bdaddr;
+	uint8_t bdaddr_type;
+
+	int bond_state;
+
+	char *name;
+	char *friendly_name;
+
+	uint32_t class;
+	int32_t rssi;
+};
+
+struct browse_req {
+	bdaddr_t bdaddr;
+	GSList *uuids;
+	int search_uuid;
+	int reconnect_attempt;
+};
 
 static struct {
 	uint16_t index;
@@ -91,23 +108,6 @@ static struct {
 	.uuids = NULL,
 };
 
-struct device {
-	bdaddr_t bdaddr;
-	uint8_t bdaddr_type;
-	int bond_state;
-	char *name;
-	char *friendly_name;
-	uint32_t class;
-	int32_t rssi;
-};
-
-struct browse_req {
-	bdaddr_t bdaddr;
-	GSList *uuids;
-	int search_uuid;
-	int reconnect_attempt;
-};
-
 static const uint16_t uuid_list[] = {
 	L2CAP_UUID,
 	PNP_INFO_SVCLASS_ID,
@@ -115,8 +115,12 @@ static const uint16_t uuid_list[] = {
 	0
 };
 
+static struct mgmt *mgmt_if = NULL;
 static GSList *devices = NULL;
 
+/* This list contains addresses which are asked for records */
+static GSList *browse_reqs;
+
 static int bdaddr_cmp(gconstpointer a, gconstpointer b)
 {
 	const bdaddr_t *bda = a;
@@ -349,7 +353,6 @@ static void store_link_key(const bdaddr_t *dst, const uint8_t *key,
 					uint8_t type, uint8_t pin_length)
 {
 	/* TODO store link key */
-
 }
 
 static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
@@ -368,7 +371,6 @@ static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
 static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
 								int state)
 {
-
 	struct device *dev;
 
 	dev = find_device(addr);
@@ -570,6 +572,7 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
 
 	browse_remote_sdp(&addr->bdaddr);
 }
+
 static  void send_device_property(const bdaddr_t *bdaddr, uint8_t type,
 						uint16_t len, const void *val)
 {
@@ -693,7 +696,8 @@ static void user_passkey_request_callback(uint16_t index, uint16_t length,
 }
 
 static void user_passkey_notify_callback(uint16_t index, uint16_t length,
-					const void *param, void *user_data)
+							const void *param,
+							void *user_data)
 {
 	const struct mgmt_ev_passkey_notify *ev = param;
 	char dst[18];
@@ -713,8 +717,7 @@ static void user_passkey_notify_callback(uint16_t index, uint16_t length,
 	set_device_bond_state(&ev->addr.bdaddr, HAL_STATUS_SUCCESS,
 						HAL_BOND_STATE_BONDING);
 
-	send_ssp_request(&ev->addr.bdaddr, HAL_SSP_VARIANT_NOTIF,
-								ev->passkey);
+	send_ssp_request(&ev->addr.bdaddr, HAL_SSP_VARIANT_NOTIF, ev->passkey);
 }
 
 static void mgmt_discovering_event(uint16_t index, uint16_t length,
@@ -760,7 +763,6 @@ static void confirm_device_name(const bdaddr_t *addr, uint8_t addr_type)
 		error("Failed to send confirm name request");
 }
 
-
 static int fill_hal_prop(void *buf, uint8_t type, uint16_t len,
 							const void *val)
 {
@@ -813,7 +815,8 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
 		bdaddr2android(bdaddr, &android_bdaddr);
 
 		size += fill_hal_prop(buf + size, HAL_PROP_DEVICE_ADDR,
-				sizeof(android_bdaddr), &android_bdaddr);
+							sizeof(android_bdaddr),
+							&android_bdaddr);
 		(*num_prop)++;
 
 		android_type = bdaddr_type2android(dev->bdaddr_type);
@@ -932,7 +935,8 @@ static void mgmt_device_connected_event(uint16_t index, uint16_t length,
 }
 
 static void mgmt_device_disconnected_event(uint16_t index, uint16_t length,
-					const void *param, void *user_data)
+							const void *param,
+							void *user_data)
 {
 	const struct mgmt_ev_device_disconnected *ev = param;
 	struct hal_ev_acl_state_changed hal_ev;
@@ -1699,7 +1703,6 @@ static uint8_t get_adapter_name(void)
 	return HAL_STATUS_SUCCESS;
 }
 
-
 static uint8_t get_adapter_class(void)
 {
 	DBG("");
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property
  2013-12-11 10:31 [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Szymon Janc
                   ` (7 preceding siblings ...)
  2013-12-11 10:31 ` [PATCH 9/9] android/bluetooth: Code style and whitespace cleanup Szymon Janc
@ 2013-12-11 13:50 ` Johan Hedberg
  8 siblings, 0 replies; 13+ messages in thread
From: Johan Hedberg @ 2013-12-11 13:50 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth

Hi Szymon,

On Wed, Dec 11, 2013, Szymon Janc wrote:
> This allows to get property with adapter type.
> ---
>  android/bluetooth.c | 32 +++++++++++++++++++++++++++++---
>  android/hal-msg.h   |  4 ++++
>  2 files changed, 33 insertions(+), 3 deletions(-)

All patches in this set have been applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 6/9] android/bluetooth: Add support for remote device RSSI
  2013-12-11 10:31 ` [PATCH 6/9] android/bluetooth: Add support for remote device RSSI Szymon Janc
@ 2013-12-12  0:04   ` Anderson Lizardo
  2013-12-12  8:58     ` Szymon Janc
  0 siblings, 1 reply; 13+ messages in thread
From: Anderson Lizardo @ 2013-12-12  0:04 UTC (permalink / raw)
  To: Szymon Janc; +Cc: BlueZ development

Hi Szymon,

On Wed, Dec 11, 2013 at 7:31 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
\> @@ -2306,11 +2309,13 @@ static uint8_t
get_device_friendly_name(struct device *dev)
>
>  static uint8_t get_device_rssi(struct device *dev)
>  {
> -       DBG("Not implemented");
> +       if (!dev->rssi)
> +               return HAL_STATUS_FAILED;

0 dBm is a valid RSSI value, so I suppose this code needs some other
way to identify an uninitialized value (e.g. a second boolean field.)

>
> -       /* TODO */
> +       send_device_property(&dev->bdaddr, HAL_PROP_DEVICE_RSSI,
> +                                               sizeof(dev->rssi), &dev->rssi);
>
> -       return HAL_STATUS_FAILED;
> +       return HAL_STATUS_SUCCESS;
>  }

Best Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 6/9] android/bluetooth: Add support for remote device RSSI
  2013-12-12  0:04   ` Anderson Lizardo
@ 2013-12-12  8:58     ` Szymon Janc
  2013-12-12 11:03       ` Anderson Lizardo
  0 siblings, 1 reply; 13+ messages in thread
From: Szymon Janc @ 2013-12-12  8:58 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: BlueZ development

Hi Anderson,

> Hi Szymon,
> 
> On Wed, Dec 11, 2013 at 7:31 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
> \> @@ -2306,11 +2309,13 @@ static uint8_t
> get_device_friendly_name(struct device *dev)
> >
> >  static uint8_t get_device_rssi(struct device *dev)
> >  {
> > -       DBG("Not implemented");
> > +       if (!dev->rssi)
> > +               return HAL_STATUS_FAILED;
> 
> 0 dBm is a valid RSSI value, so I suppose this code needs some other
> way to identify an uninitialized value (e.g. a second boolean field.)

Kernel sends rssi==0 if rssi info was not present on inquiry so I used this
value, but maybe it should use 127 for that.. ? (yet, this might cause trouble
as linux bluetoothd is checking 0 as well)

-- 
BR
Szymon Janc



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 6/9] android/bluetooth: Add support for remote device RSSI
  2013-12-12  8:58     ` Szymon Janc
@ 2013-12-12 11:03       ` Anderson Lizardo
  0 siblings, 0 replies; 13+ messages in thread
From: Anderson Lizardo @ 2013-12-12 11:03 UTC (permalink / raw)
  To: Szymon Janc; +Cc: BlueZ development

Hi Szymon,

On Thu, Dec 12, 2013 at 5:58 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
>> On Wed, Dec 11, 2013 at 7:31 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
>> \> @@ -2306,11 +2309,13 @@ static uint8_t
>> get_device_friendly_name(struct device *dev)
>> >
>> >  static uint8_t get_device_rssi(struct device *dev)
>> >  {
>> > -       DBG("Not implemented");
>> > +       if (!dev->rssi)
>> > +               return HAL_STATUS_FAILED;
>>
>> 0 dBm is a valid RSSI value, so I suppose this code needs some other
>> way to identify an uninitialized value (e.g. a second boolean field.)
>
> Kernel sends rssi==0 if rssi info was not present on inquiry so I used this
> value, but maybe it should use 127 for that.. ? (yet, this might cause trouble
> as linux bluetoothd is checking 0 as well)

I remember commenting on this when mgmt API (it was for TX Power,
which is more common to be 0 dBm, but I can't remember what was the
result of the discussion). In any case, I think handling this way will
make devices that use TX Power higher than 0 dBm (and thus can make a
0dBm RSSI possible) not report their RSSI. It is not common IMHO, but
it is possible.

Best Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2013-12-12 11:03 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-11 10:31 [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Szymon Janc
2013-12-11 10:31 ` [PATCH 2/9] android/bluetooth: Add support for adapter bonded devices property Szymon Janc
2013-12-11 10:31 ` [PATCH 3/9] android/bluetooth: Add support for remote device friendly name Szymon Janc
2013-12-11 10:31 ` [PATCH 4/9] android/bluetooth: Free devices on service unregister Szymon Janc
2013-12-11 10:31 ` [PATCH 5/9] android/bluetooth: Add support for remote device class Szymon Janc
2013-12-11 10:31 ` [PATCH 6/9] android/bluetooth: Add support for remote device RSSI Szymon Janc
2013-12-12  0:04   ` Anderson Lizardo
2013-12-12  8:58     ` Szymon Janc
2013-12-12 11:03       ` Anderson Lizardo
2013-12-11 10:31 ` [PATCH 7/9] android/bluetooth: Add support for get remote device properties command Szymon Janc
2013-12-11 10:31 ` [PATCH 8/9] android/bluetooth: Add support for remote device type property Szymon Janc
2013-12-11 10:31 ` [PATCH 9/9] android/bluetooth: Code style and whitespace cleanup Szymon Janc
2013-12-11 13:50 ` [PATCH 1/9] android/bluetooth: Add support for reporting adapter type property Johan Hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.