* [PATCH BlueZ 1/2] core: Fix not replying to DisconnectProfile
From: Luiz Augusto von Dentz @ 2013-12-10 8:41 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
btd_service_disconnect may cause a service to disconnect before returning
which cause dev->disconnect to be set after device_profile_disconnected.
---
src/device.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/device.c b/src/device.c
index d7a00ec..953a338 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1434,11 +1434,14 @@ static DBusMessage *disconnect_profile(DBusConnection *conn, DBusMessage *msg,
if (!service)
return btd_error_invalid_args(msg);
+ dev->disconnect = dbus_message_ref(msg);
+
err = btd_service_disconnect(service);
- if (err == 0) {
- dev->disconnect = dbus_message_ref(msg);
+ if (err == 0)
return NULL;
- }
+
+ dbus_message_unref(dev->disconnect);
+ dev->disconnect = NULL;
if (err == -ENOTSUP)
return btd_error_not_supported(msg);
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCHv2] Fix eir parsing function.
From: Johan Hedberg @ 2013-12-10 8:33 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1386663340-12730-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Tue, Dec 10, 2013, Andrei Emeltchenko wrote:
> Currently eir_parse always return 0 but it is checked throughout the code
> (in android/bluetooth code as well in src/adapteri, etc) for return value
> (err < 0) which never happens. Make function eir_parse return void. This
> fixes warnings from static analyzer tools.
> ---
> android/bluetooth.c | 7 +------
> src/adapter.c | 7 +------
> src/eir.c | 8 +++-----
> src/eir.h | 2 +-
> unit/test-eir.c | 8 ++------
> 5 files changed, 8 insertions(+), 24 deletions(-)
Applied (after fixing up the subject a bit). Thanks.
Johan
^ permalink raw reply
* Re: [PATCHv2] Fix eir parsing function.
From: Bastien Nocera @ 2013-12-10 8:24 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1386663340-12730-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
On Tue, 2013-12-10 at 10:15 +0200, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Currently eir_parse always return 0 but it is checked throughout the code
> (in android/bluetooth code as well in src/adapteri, etc) for return value
^
typo?
> (err < 0) which never happens. Make function eir_parse return void. This
> fixes warnings from static analyzer tools.
^ permalink raw reply
* Missing AuthorizeService callback?
From: Bastien Nocera @ 2013-12-10 8:23 UTC (permalink / raw)
To: linux-bluetooth
Heya,
This mouse is particularly troublesome, and refuses to forget about a
previous setup with my computer. It tries to connect when started, which
shouldn't be as much of a problem if I did get an AuthorizeService
callback to allow the device to connect:
Dec 10 09:15:03 nuvo bluetoothd[20264]: src/adapter.c:connected_callback() hci0 device 00:0A:94:C0:AB:9B connected eir_len 5
Dec 10 09:15:03 nuvo bluetoothd[20264]: src/device.c:device_create() dst 00:0A:94:C0:AB:9B
Dec 10 09:15:03 nuvo bluetoothd[20264]: src/device.c:device_new() address 00:0A:94:C0:AB:9B
Dec 10 09:15:03 nuvo bluetoothd[20264]: src/device.c:device_new() Creating device /org/bluez/hci0/dev_00_0A_94_C0_AB_9B
Dec 10 09:15:03 nuvo bluetoothd[20264]: src/device.c:device_set_temporary() temporary 1
Dec 10 09:15:03 nuvo bluetoothd[20264]: src/adapter.c:adapter_connect_list_remove() device /org/bluez/hci0/dev_00_0A_94_C0_AB_9B is not on the list, ignoring
Dec 10 09:15:03 nuvo bluetoothd[20264]: src/device.c:device_set_class() /org/bluez/hci0/dev_00_0A_94_C0_AB_9B 0x002580
Dec 10 09:15:03 nuvo bluetoothd[20264]: profiles/input/server.c:connect_event_cb() Incoming connection from 00:0A:94:C0:AB:9B on PSM 17
Dec 10 09:15:03 nuvo bluetoothd[20264]: profiles/input/device.c:input_device_set_channel() idev (nil) psm 17
Dec 10 09:15:03 nuvo bluetoothd[20264]: Refusing input device connect: No such file or directory (2)
Dec 10 09:15:03 nuvo bluetoothd[20264]: profiles/input/server.c:confirm_event_cb()
Dec 10 09:15:03 nuvo bluetoothd[20264]: Refusing connection from 00:0A:94:C0:AB:9B: unknown device
Seems that we have the same problem I mentioned earlier with the device
getting created, and deleted straight away.
^ permalink raw reply
* [PATCHv2] Fix eir parsing function.
From: Andrei Emeltchenko @ 2013-12-10 8:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <20131129082247.GA6800@x220.p-661hnu-f1>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Currently eir_parse always return 0 but it is checked throughout the code
(in android/bluetooth code as well in src/adapteri, etc) for return value
(err < 0) which never happens. Make function eir_parse return void. This
fixes warnings from static analyzer tools.
---
android/bluetooth.c | 7 +------
src/adapter.c | 7 +------
src/eir.c | 8 +++-----
src/eir.h | 2 +-
unit/test-eir.c | 8 ++------
5 files changed, 8 insertions(+), 24 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 6174b1f..a3145cb 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -798,16 +798,11 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
uint8_t *num_prop;
uint8_t opcode;
int size = 0;
- int err;
memset(buf, 0, sizeof(buf));
memset(&eir, 0, sizeof(eir));
- err = eir_parse(&eir, data, data_len);
- if (err < 0) {
- error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
- return;
- }
+ eir_parse(&eir, data, data_len);
if (!g_slist_find_custom(found_devices, bdaddr, bdaddr_cmp)) {
bdaddr_t *new_bdaddr;
diff --git a/src/adapter.c b/src/adapter.c
index 8ec9e92..9480103 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -4083,16 +4083,11 @@ static void update_found_devices(struct btd_adapter *adapter,
struct btd_device *dev;
struct eir_data eir_data;
char addr[18];
- int err;
GSList *list;
bool name_known;
memset(&eir_data, 0, sizeof(eir_data));
- err = eir_parse(&eir_data, data, data_len);
- if (err < 0) {
- error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
- return;
- }
+ eir_parse(&eir_data, data, data_len);
/* Avoid creating LE device if it's not discoverable */
if (bdaddr_type != BDADDR_BREDR &&
diff --git a/src/eir.c b/src/eir.c
index 084884e..7745ff3 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -129,7 +129,7 @@ static char *name2utf8(const uint8_t *name, uint8_t len)
return g_strdup(utf8_name);
}
-int eir_parse(struct eir_data *eir, const uint8_t *eir_data, uint8_t eir_len)
+void eir_parse(struct eir_data *eir, const uint8_t *eir_data, uint8_t eir_len)
{
uint16_t len = 0;
@@ -138,7 +138,7 @@ int eir_parse(struct eir_data *eir, const uint8_t *eir_data, uint8_t eir_len)
/* No EIR data to parse */
if (eir_data == NULL)
- return 0;
+ return;
while (len < eir_len - 1) {
uint8_t field_len = eir_data[0];
@@ -226,8 +226,6 @@ int eir_parse(struct eir_data *eir, const uint8_t *eir_data, uint8_t eir_len)
eir_data += field_len + 1;
}
-
- return 0;
}
int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len)
@@ -248,7 +246,7 @@ int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len)
/* optional OOB EIR data */
if (eir_len > 0)
- return eir_parse(eir, eir_data, eir_len);
+ eir_parse(eir, eir_data, eir_len);
return 0;
}
diff --git a/src/eir.h b/src/eir.h
index 1b6242d..411986e 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -52,7 +52,7 @@ struct eir_data {
};
void eir_data_free(struct eir_data *eir);
-int eir_parse(struct eir_data *eir, const uint8_t *eir_data, uint8_t eir_len);
+void eir_parse(struct eir_data *eir, const uint8_t *eir_data, uint8_t eir_len);
int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len);
int eir_create_oob(const bdaddr_t *addr, const char *name, uint32_t cod,
const uint8_t *hash, const uint8_t *randomizer,
diff --git a/unit/test-eir.c b/unit/test-eir.c
index 1a6e1c9..6d9d554 100644
--- a/unit/test-eir.c
+++ b/unit/test-eir.c
@@ -537,13 +537,11 @@ static void test_basic(void)
{
struct eir_data data;
unsigned char buf[HCI_MAX_EIR_LENGTH];
- int err;
memset(buf, 0, sizeof(buf));
memset(&data, 0, sizeof(data));
- err = eir_parse(&data, buf, HCI_MAX_EIR_LENGTH);
- g_assert(err == 0);
+ eir_parse(&data, buf, HCI_MAX_EIR_LENGTH);
g_assert(data.services == NULL);
g_assert(data.name == NULL);
@@ -554,12 +552,10 @@ static void test_parsing(gconstpointer data)
{
const struct test_data *test = data;
struct eir_data eir;
- int err;
memset(&eir, 0, sizeof(eir));
- err = eir_parse(&eir, test->eir_data, test->eir_size);
- g_assert(err == 0);
+ eir_parse(&eir, test->eir_data, test->eir_size);
if (g_test_verbose() == TRUE) {
GSList *list;
--
1.8.3.2
^ permalink raw reply related
* Re: [PATCH] adapter: Remove not needed struct adapter_keys
From: Johan Hedberg @ 2013-12-10 5:31 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1386583893-22676-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Mon, Dec 09, 2013, Szymon Janc wrote:
> This is a leftover from using old storage format.
> ---
> src/adapter.c | 21 ++++++++-------------
> 1 file changed, 8 insertions(+), 13 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH] core: Fix crash due to agent callback freeing the agent
From: Johan Hedberg @ 2013-12-10 5:22 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1386616856-16140-1-git-send-email-szymon.janc@gmail.com>
Hi Szymon,
On Mon, Dec 09, 2013, Szymon Janc wrote:
> Similar fix was provided for simple_agent_reply in a2f5d438 but missed
> pincode_reply case.
>
> Fix following:
>
> src/agent.c:agent_disconnect() Agent :1.48 disconnected
> src/agent.c:set_default_agent() Default agent cleared
> src/agent.c:agent_destroy() agent :1.48
> src/agent.c:agent_unref() 0x4701c68: ref=1
> Agent /org/bluez/agent replied with an error:
> org.freedesktop.DBus.Error.NoReply, Message did not receive a reply
> (timeout by message bus)
> src/adapter.c:btd_adapter_pincode_reply() hci0 addr 6C:0E:0D:DB:D1:16
> pinlen 0
> src/agent.c:agent_unref() 0x4701c68: ref=0
> src/adapter.c:btd_adapter_pincode_reply() hci0 addr 6C:0E:0D:DB:D1:16
> pinlen 0
> src/agent.c:agent_unref() 0x4701c68: ref=-1
> src/adapter.c:btd_adapter_pincode_reply() hci0 addr 6C:0E:0D:DB:D1:16
> pinlen 0
> src/agent.c:agent_unref() 0x4701c68: ref=-2
> ...
> ---
> src/agent.c | 4 ++++
> 1 file changed, 4 insertions(+)
Applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH] core: Fix crash due to agent callback freeing the agent
From: Bastien Nocera @ 2013-12-10 0:10 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1386634100.5021.2.camel@nuvo>
On Tue, 2013-12-10 at 01:08 +0100, Bastien Nocera wrote:
> On Mon, 2013-12-09 at 20:20 +0100, Szymon Janc wrote:
> > Similar fix was provided for simple_agent_reply in a2f5d438 but missed
> > pincode_reply case.
>
> That fixes the bug I reported in:
> http://thread.gmane.org/gmane.linux.bluez.kernel/41496
Though I'd still add an assertion in all the unref() calls you can find
in the bluez tree.
^ permalink raw reply
* Re: [PATCH] core: Fix crash due to agent callback freeing the agent
From: Bastien Nocera @ 2013-12-10 0:08 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1386616856-16140-1-git-send-email-szymon.janc@gmail.com>
On Mon, 2013-12-09 at 20:20 +0100, Szymon Janc wrote:
> Similar fix was provided for simple_agent_reply in a2f5d438 but missed
> pincode_reply case.
That fixes the bug I reported in:
http://thread.gmane.org/gmane.linux.bluez.kernel/41496
Cheers
^ permalink raw reply
* Re: pull request: bluetooth-next 2013-12-04
From: John W. Linville @ 2013-12-09 20:32 UTC (permalink / raw)
To: Gustavo Padovan, linux-wireless, linux-bluetooth, linux-kernel
In-Reply-To: <20131204132527.GD1608@joana>
On Wed, Dec 04, 2013 at 11:25:27AM -0200, Gustavo Padovan wrote:
> Hi John,
>
> This is the first batch of patches intended for 3.14. There is nothing big here.
> Most of the code are refactors, clean up, small fixes, plus some new device id
> support.
>
> Please pull or let me know of any problems! Thanks.
>
> Gustavo
>
> ---
> The following changes since commit 4b074b07625f603d40d4d04937f8874a00415dc4:
>
> Merge branch 'for-john' of git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next (2013-12-02 14:25:38 -0500)
>
> are available in the git repository at:
>
>
> git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git for-upstream
>
> for you to fetch changes up to 201a5929c8c788f9ef53b010065c9ce70c9c06f0:
>
> Bluetooth: Remove dead code from SMP encryption function (2013-12-04 11:09:05 -0200)
Pulling now...
--
John W. Linville Someday the world will need a hero, and you
linville@tuxdriver.com might be all we have. Be ready.
^ permalink raw reply
* [PATCH] core: Fix crash due to agent callback freeing the agent
From: Szymon Janc @ 2013-12-09 19:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Similar fix was provided for simple_agent_reply in a2f5d438 but missed
pincode_reply case.
Fix following:
src/agent.c:agent_disconnect() Agent :1.48 disconnected
src/agent.c:set_default_agent() Default agent cleared
src/agent.c:agent_destroy() agent :1.48
src/agent.c:agent_unref() 0x4701c68: ref=1
Agent /org/bluez/agent replied with an error:
org.freedesktop.DBus.Error.NoReply, Message did not receive a reply
(timeout by message bus)
src/adapter.c:btd_adapter_pincode_reply() hci0 addr 6C:0E:0D:DB:D1:16
pinlen 0
src/agent.c:agent_unref() 0x4701c68: ref=0
src/adapter.c:btd_adapter_pincode_reply() hci0 addr 6C:0E:0D:DB:D1:16
pinlen 0
src/agent.c:agent_unref() 0x4701c68: ref=-1
src/adapter.c:btd_adapter_pincode_reply() hci0 addr 6C:0E:0D:DB:D1:16
pinlen 0
src/agent.c:agent_unref() 0x4701c68: ref=-2
...
---
src/agent.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/agent.c b/src/agent.c
index bcba969..4c63cb9 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -426,6 +426,9 @@ static void pincode_reply(DBusPendingCall *call, void *user_data)
* is only called after a reply has been received */
message = dbus_pending_call_steal_reply(call);
+ /* Protect from the callback freeing the agent */
+ agent_ref(agent);
+
dbus_error_init(&err);
if (dbus_set_error_from_message(&err, message)) {
error("Agent %s replied with an error: %s, %s",
@@ -465,6 +468,7 @@ done:
dbus_pending_call_cancel(req->call);
agent->request = NULL;
agent_request_free(req, TRUE);
+ agent_unref(agent);
}
static int pincode_request_new(struct agent_request *req, const char *device_path,
--
1.8.5.1
^ permalink raw reply related
* [PATCH] autopair: Don't handle the iCade
From: Bastien Nocera @ 2013-12-09 17:08 UTC (permalink / raw)
To: linux-bluetooth
We can't easily enter digits other than 1 through 4 (inclusive)
so leave it up to the agent to figure out a good passcode
for the iCade.
Note that we can not use the VID/PID of the device, as it is not
yet known at that point.
---
plugins/autopair.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/plugins/autopair.c b/plugins/autopair.c
index 8c98c12..5d2f6f7 100644
--- a/plugins/autopair.c
+++ b/plugins/autopair.c
@@ -57,13 +57,23 @@ static ssize_t autopair_pincb(struct btd_adapter *adapter,
{
char addr[18];
char pinstr[7];
+ char name[25];
uint32_t class;
ba2str(device_get_address(device), addr);
class = btd_device_get_class(device);
- DBG("device %s 0x%x", addr, class);
+ device_get_name(device, name, sizeof(name));
+ name[sizeof(name) - 1] = 0;
+
+ DBG("device %s (%s) 0x%x", addr, name, class);
+
+ g_message ("vendor 0x%X product: 0x%X", btd_device_get_vendor (device), btd_device_get_product (device));
+
+ /* The iCade shouldn't use random PINs like normal keyboards */
+ if (name != NULL && strstr(name, "iCade") != NULL)
+ return 0;
/* This is a class-based pincode guesser. Ignore devices with an
* unknown class.
--
1.8.4.2
^ permalink raw reply related
* [PATCH 8/8] android/bluetooth: Add send_adapter_property helper function
From: Szymon Janc @ 2013-12-09 15:14 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1386602049-5533-1-git-send-email-szymon.janc@tieto.com>
Adapter property notification are send from multiple places so it make
sense to have helper for that. This is especially usefull for 'simple'
properties.
---
android/bluetooth.c | 88 +++++++++++++++--------------------------------------
1 file changed, 25 insertions(+), 63 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index fd69c86..517b71e 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -147,24 +147,26 @@ static struct device *get_device(const bdaddr_t *bdaddr)
return dev;
}
-static void adapter_name_changed(const uint8_t *name)
+static void send_adapter_property(uint8_t type, uint16_t len, const void *val)
{
- struct hal_ev_adapter_props_changed *ev;
- size_t len = strlen((const char *) name);
uint8_t buf[BASELEN_PROP_CHANGED + len];
+ struct hal_ev_adapter_props_changed *ev = (void *) buf;
- memset(buf, 0, sizeof(buf));
- ev = (void *) buf;
-
- ev->num_props = 1;
ev->status = HAL_STATUS_SUCCESS;
- ev->props[0].type = HAL_PROP_ADAPTER_NAME;
- /* Android expects value without NULL terminator */
+ ev->num_props = 1;
+ ev->props[0].type = type;
ev->props[0].len = len;
- memcpy(ev->props->val, name, len);
+ memcpy(ev->props[0].val, val, len);
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), ev);
+ sizeof(buf), buf);
+}
+
+static void adapter_name_changed(const uint8_t *name)
+{
+ /* Android expects string value without NULL terminator */
+ send_adapter_property(HAL_PROP_ADAPTER_NAME,
+ strlen((const char *) name), name);
}
static void adapter_set_name(const uint8_t *name)
@@ -226,39 +228,19 @@ static uint8_t settings2scan_mode(void)
static void scan_mode_changed(void)
{
- uint8_t buf[BASELEN_PROP_CHANGED + 1];
- struct hal_ev_adapter_props_changed *ev = (void *) buf;
- uint8_t *mode;
-
- ev->num_props = 1;
- ev->status = HAL_STATUS_SUCCESS;
-
- ev->props[0].type = HAL_PROP_ADAPTER_SCAN_MODE;
- ev->props[0].len = 1;
+ uint8_t mode;
- mode = ev->props[0].val;
- *mode = settings2scan_mode();
+ mode = settings2scan_mode();
- DBG("mode %u", *mode);
+ DBG("mode %u", mode);
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), buf);
+ send_adapter_property(HAL_PROP_ADAPTER_SCAN_MODE, sizeof(mode), &mode);
}
static void adapter_class_changed(void)
{
- uint8_t buf[BASELEN_PROP_CHANGED + sizeof(uint32_t)];
- struct hal_ev_adapter_props_changed *ev = (void *) buf;
-
- ev->num_props = 1;
- ev->status = HAL_STATUS_SUCCESS;
-
- ev->props[0].type = HAL_PROP_ADAPTER_CLASS;
- ev->props[0].len = sizeof(uint32_t);
- memcpy(ev->props->val, &adapter.dev_class, sizeof(uint32_t));
-
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), buf);
+ send_adapter_property(HAL_PROP_ADAPTER_CLASS, sizeof(adapter.dev_class),
+ &adapter.dev_class);
}
static void settings_changed(uint32_t settings)
@@ -1652,18 +1634,11 @@ static bool set_discoverable(uint8_t mode, uint16_t timeout)
static uint8_t get_adapter_address(void)
{
- uint8_t buf[BASELEN_PROP_CHANGED + sizeof(bdaddr_t)];
- struct hal_ev_adapter_props_changed *ev = (void *) buf;
-
- ev->num_props = 1;
- ev->status = HAL_STATUS_SUCCESS;
+ uint8_t buf[6];
- ev->props[0].type = HAL_PROP_ADAPTER_ADDR;
- ev->props[0].len = sizeof(bdaddr_t);
- bdaddr2android(&adapter.bdaddr, ev->props[0].val);
+ bdaddr2android(&adapter.bdaddr, buf);
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), buf);
+ send_adapter_property(HAL_PROP_ADAPTER_ADDR, sizeof(buf), buf);
return HAL_STATUS_SUCCESS;
}
@@ -1726,22 +1701,9 @@ static uint8_t get_adapter_bonded_devices(void)
static uint8_t get_adapter_discoverable_timeout(void)
{
- struct hal_ev_adapter_props_changed *ev;
- uint8_t buf[BASELEN_PROP_CHANGED + sizeof(uint32_t)];
-
- memset(buf, 0, sizeof(buf));
- ev = (void *) buf;
-
- ev->num_props = 1;
- ev->status = HAL_STATUS_SUCCESS;
-
- ev->props[0].type = HAL_PROP_ADAPTER_DISC_TIMEOUT;
- ev->props[0].len = sizeof(uint32_t);
- memcpy(&ev->props[0].val, &adapter.discoverable_timeout,
- sizeof(uint32_t));
-
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), ev);
+ send_adapter_property(HAL_PROP_ADAPTER_DISC_TIMEOUT,
+ sizeof(adapter.discoverable_timeout),
+ &adapter.discoverable_timeout);
return HAL_STATUS_SUCCESS;
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH 7/8] android/bluetooth: Add send_device_property helper function
From: Szymon Janc @ 2013-12-09 15:14 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1386602049-5533-1-git-send-email-szymon.janc@tieto.com>
Remote device property notification will be send from multiple places
so it make sense to have helper for that. This will be especially
usefull for 'simple' properties.
---
android/bluetooth.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 7528921..fd69c86 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -557,26 +557,27 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
browse_remote_sdp(&addr->bdaddr);
}
-
-static uint8_t get_device_name(struct device *dev)
+static void send_device_property(const bdaddr_t *bdaddr, uint8_t type,
+ uint16_t len, const void *val)
{
- struct hal_ev_remote_device_props *ev;
- size_t ev_len;
-
- ev_len = BASELEN_REMOTE_DEV_PROP + strlen(dev->name);
- ev = g_malloc0(ev_len);
+ uint8_t buf[BASELEN_REMOTE_DEV_PROP + len];
+ struct hal_ev_remote_device_props *ev = (void *) buf;
ev->status = HAL_STATUS_SUCCESS;
- bdaddr2android(&dev->bdaddr, ev->bdaddr);
+ bdaddr2android(bdaddr, ev->bdaddr);
ev->num_props = 1;
- ev->props[0].type = HAL_PROP_DEVICE_NAME;
- ev->props[0].len = strlen(dev->name);
- memcpy(&ev->props[0].val, dev->name, strlen(dev->name));
+ ev->props[0].type = type;
+ ev->props[0].len = len;
+ memcpy(ev->props[0].val, val, len);
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_REMOTE_DEVICE_PROPS,
- ev_len, ev);
+ sizeof(buf), buf);
+}
- g_free(ev);
+static uint8_t get_device_name(struct device *dev)
+{
+ send_device_property(&dev->bdaddr, HAL_PROP_DEVICE_NAME,
+ strlen(dev->name), dev->name);
return HAL_STATUS_SUCCESS;
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH 6/8] android/bluetooth: Add stubs for set device property command
From: Szymon Janc @ 2013-12-09 15:14 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1386602049-5533-1-git-send-email-szymon.janc@tieto.com>
This adds per property stubs.
---
android/bluetooth.c | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 4b17f60..7528921 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -2362,10 +2362,30 @@ failed:
status);
}
+static uint8_t set_device_friendly_name(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t set_device_version_info(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
static void handle_set_remote_device_prop_cmd(const void *buf, uint16_t len)
{
const struct hal_cmd_set_remote_device_prop *cmd = buf;
uint8_t status;
+ bdaddr_t addr;
+ GSList *l;
if (len != sizeof(*cmd) + cmd->len) {
error("Invalid set remote device prop cmd (0x%x), terminating",
@@ -2374,15 +2394,27 @@ static void handle_set_remote_device_prop_cmd(const void *buf, uint16_t len)
return;
}
- /* TODO */
+ android2bdaddr(cmd->bdaddr, &addr);
+
+ l = g_slist_find_custom(devices, &addr, bdaddr_cmp);
+ if (!l) {
+ status = HAL_STATUS_INVALID;
+ goto failed;
+ }
switch (cmd->type) {
+ case HAL_PROP_DEVICE_FRIENDLY_NAME:
+ status = set_device_friendly_name(l->data);
+ break;
+ case HAL_PROP_DEVICE_VERSION_INFO:
+ status = set_device_version_info(l->data);
+ break;
default:
- DBG("Unhandled property type 0x%x", cmd->type);
status = HAL_STATUS_FAILED;
break;
}
+failed:
ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_REMOTE_DEVICE_PROP,
status);
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH 5/8] android/bluetooth: Add stubs for get device properties command
From: Szymon Janc @ 2013-12-09 15:14 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1386602049-5533-1-git-send-email-szymon.janc@tieto.com>
This adds per property stubs.
---
android/bluetooth.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 119 insertions(+), 2 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 879cf8d..4b17f60 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -2229,6 +2229,78 @@ static void handle_get_adapter_props_cmd(const void *buf, uint16_t len)
HAL_STATUS_SUCCESS);
}
+static uint8_t get_device_uuids(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_class(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_type(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_service_rec(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_friendly_name(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_rssi(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_version_info(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_timestamp(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
{
/* TODO */
@@ -2239,10 +2311,55 @@ static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
static void handle_get_remote_device_prop_cmd(const void *buf, uint16_t len)
{
- /* TODO */
+ const struct hal_cmd_get_remote_device_prop *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;
+ }
+
+ switch (cmd->type) {
+ case HAL_PROP_DEVICE_NAME:
+ status = get_device_name(l->data);
+ break;
+ case HAL_PROP_DEVICE_UUIDS:
+ status = get_device_uuids(l->data);
+ break;
+ case HAL_PROP_DEVICE_CLASS:
+ status = get_device_class(l->data);
+ break;
+ case HAL_PROP_DEVICE_TYPE:
+ status = get_device_type(l->data);
+ break;
+ case HAL_PROP_DEVICE_SERVICE_REC:
+ status = get_device_service_rec(l->data);
+ break;
+ case HAL_PROP_DEVICE_FRIENDLY_NAME:
+ status = get_device_friendly_name(l->data);
+ break;
+ case HAL_PROP_DEVICE_RSSI:
+ status = get_device_rssi(l->data);
+ break;
+ case HAL_PROP_DEVICE_VERSION_INFO:
+ status = get_device_version_info(l->data);
+ break;
+ case HAL_PROP_DEVICE_TIMESTAMP:
+ status = get_device_timestamp(l->data);
+ break;
+ default:
+ status = HAL_STATUS_FAILED;
+ break;
+ }
+
+failed:
ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_REMOTE_DEVICE_PROP,
- HAL_STATUS_FAILED);
+ status);
}
static void handle_set_remote_device_prop_cmd(const void *buf, uint16_t len)
--
1.8.3.2
^ permalink raw reply related
* [PATCH 4/8] android/bluetooth: Refactor send_remote_device_name_prop
From: Szymon Janc @ 2013-12-09 15:14 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1386602049-5533-1-git-send-email-szymon.janc@tieto.com>
Rename send_remote_device_name_prop to get_device_name and make it
accept struct device as parameter. Also return HAL status code.
This will allow to use this function also in get device property
command handler.
---
android/bluetooth.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 4ceb40f..879cf8d 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -558,19 +558,16 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
browse_remote_sdp(&addr->bdaddr);
}
-static void send_remote_device_name_prop(const bdaddr_t *bdaddr)
+static uint8_t get_device_name(struct device *dev)
{
struct hal_ev_remote_device_props *ev;
- struct device *dev;
size_t ev_len;
- dev = get_device(bdaddr);
-
ev_len = BASELEN_REMOTE_DEV_PROP + strlen(dev->name);
ev = g_malloc0(ev_len);
ev->status = HAL_STATUS_SUCCESS;
- bdaddr2android(bdaddr, ev->bdaddr);
+ bdaddr2android(&dev->bdaddr, ev->bdaddr);
ev->num_props = 1;
ev->props[0].type = HAL_PROP_DEVICE_NAME;
ev->props[0].len = strlen(dev->name);
@@ -580,6 +577,8 @@ static void send_remote_device_name_prop(const bdaddr_t *bdaddr)
ev_len, ev);
g_free(ev);
+
+ return HAL_STATUS_SUCCESS;
}
static void pin_code_request_callback(uint16_t index, uint16_t length,
@@ -598,7 +597,7 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
/* Workaround for Android Bluetooth.apk issue: send remote
* device property */
- send_remote_device_name_prop(&ev->addr.bdaddr);
+ get_device_name(get_device(&ev->addr.bdaddr));
set_device_bond_state(&ev->addr.bdaddr, HAL_STATUS_SUCCESS,
HAL_BOND_STATE_BONDING);
--
1.8.3.2
^ permalink raw reply related
* [PATCH 3/8] android/bluetooth: Fix coding style issue in set_device_bond_state
From: Szymon Janc @ 2013-12-09 15:14 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1386602049-5533-1-git-send-email-szymon.janc@tieto.com>
---
android/bluetooth.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 3c27b74..4ceb40f 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -355,7 +355,8 @@ 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) {
+ int state)
+{
struct device *dev;
--
1.8.3.2
^ permalink raw reply related
* [PATCH 2/8] android/bluetooth: Use single list for device caching
From: Szymon Janc @ 2013-12-09 15:14 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1386602049-5533-1-git-send-email-szymon.janc@tieto.com>
This makes code much simpler and easier to follow. It is also
a preparation for supporting remote device properties getting, setting
and storing.
---
android/bluetooth.c | 140 ++++++++++++++++++----------------------------------
1 file changed, 49 insertions(+), 91 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index e2fa211..3c27b74 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -111,9 +111,42 @@ static const uint16_t uuid_list[] = {
0
};
-static GSList *found_devices = NULL;
static GSList *devices = NULL;
+static int bdaddr_cmp(gconstpointer a, gconstpointer b)
+{
+ const bdaddr_t *bda = a;
+ const bdaddr_t *bdb = b;
+
+ return bacmp(bdb, bda);
+}
+
+static struct device *get_device(const bdaddr_t *bdaddr)
+{
+ struct device *dev;
+ char addr[18];
+ GSList *l;
+
+ l = g_slist_find_custom(devices, bdaddr, bdaddr_cmp);
+ if (l)
+ return dev = l->data;
+
+ ba2str(bdaddr, addr);
+ DBG("new device: %s", addr);
+
+ dev = g_new0(struct device, 1);
+
+ bacpy(&dev->bdaddr, bdaddr);
+ dev->bond_state = HAL_BOND_STATE_NONE;
+
+ /* use address for name, will be change if one is present
+ * eg. in EIR or set by set_property. */
+ dev->name = g_strdup(addr);
+ devices = g_slist_prepend(devices, dev);
+
+ return dev;
+}
+
static void adapter_name_changed(const uint8_t *name)
{
struct hal_ev_adapter_props_changed *ev;
@@ -308,14 +341,6 @@ static void store_link_key(const bdaddr_t *dst, const uint8_t *key,
}
-static int bdaddr_cmp(gconstpointer a, gconstpointer b)
-{
- const bdaddr_t *bda = a;
- const bdaddr_t *bdb = b;
-
- return bacmp(bdb, bda);
-}
-
static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
uint8_t state)
{
@@ -329,46 +354,12 @@ static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
sizeof(ev), &ev);
}
-static void cache_device_name(const bdaddr_t *addr, const char *name)
-{
- struct device *dev = NULL;
- GSList *l;
-
- l = g_slist_find_custom(devices, addr, bdaddr_cmp);
- if (l)
- dev = l->data;
-
- if (!dev) {
- dev = g_new0(struct device, 1);
- bacpy(&dev->bdaddr, addr);
- dev->bond_state = HAL_BOND_STATE_NONE;
- devices = g_slist_prepend(devices, dev);
- }
-
- if (!g_strcmp0(dev->name, name))
- return;
-
- g_free(dev->name);
- dev->name = g_strdup(name);
- /*TODO: Do some real caching here */
-}
-
static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
int state) {
- struct device *dev = NULL;
- GSList *l;
-
- l = g_slist_find_custom(devices, addr, bdaddr_cmp);
- if (l)
- dev = l->data;
+ struct device *dev;
- if (!dev) {
- dev = g_new0(struct device, 1);
- bacpy(&dev->bdaddr, addr);
- dev->bond_state = HAL_BOND_STATE_NONE;
- devices = g_slist_prepend(devices, dev);
- }
+ dev = get_device(addr);
if (dev->bond_state != state) {
dev->bond_state = state;
@@ -566,42 +557,23 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
browse_remote_sdp(&addr->bdaddr);
}
-static const char *get_device_name(const bdaddr_t *addr)
-{
- GSList *l;
-
- l = g_slist_find_custom(devices, addr, bdaddr_cmp);
- if (l) {
- struct device *dev = l->data;
- return dev->name;
- }
-
- return NULL;
-}
-
static void send_remote_device_name_prop(const bdaddr_t *bdaddr)
{
struct hal_ev_remote_device_props *ev;
- const char *name;
+ struct device *dev;
size_t ev_len;
- char dst[18];
- /* Use cached name or bdaddr string */
- name = get_device_name(bdaddr);
- if (!name) {
- ba2str(bdaddr, dst);
- name = dst;
- }
+ dev = get_device(bdaddr);
- ev_len = BASELEN_REMOTE_DEV_PROP + strlen(name);
+ ev_len = BASELEN_REMOTE_DEV_PROP + strlen(dev->name);
ev = g_malloc0(ev_len);
ev->status = HAL_STATUS_SUCCESS;
bdaddr2android(bdaddr, ev->bdaddr);
ev->num_props = 1;
ev->props[0].type = HAL_PROP_DEVICE_NAME;
- ev->props[0].len = strlen(name);
- memcpy(&ev->props[0].val, name, strlen(name));
+ ev->props[0].len = strlen(dev->name);
+ memcpy(&ev->props[0].val, dev->name, strlen(dev->name));
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_REMOTE_DEVICE_PROPS,
ev_len, ev);
@@ -749,14 +721,10 @@ static void mgmt_discovering_event(uint16_t index, uint16_t length,
DBG("new discovering state %u", ev->discovering);
- if (adapter.discovering) {
+ if (adapter.discovering)
cp.state = HAL_DISCOVERY_STATE_STARTED;
- } else {
- g_slist_free_full(found_devices, g_free);
- found_devices = NULL;
-
+ else
cp.state = HAL_DISCOVERY_STATE_STOPPED;
- }
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH,
HAL_EV_DISCOVERY_STATE_CHANGED, sizeof(cp), &cp);
@@ -793,10 +761,11 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
const uint8_t *data, uint8_t data_len)
{
uint8_t buf[BLUEZ_HAL_MTU];
- bool new_dev = false;
struct eir_data eir;
+ struct device *dev;
uint8_t *num_prop;
uint8_t opcode;
+ bool new_dev;
int size = 0;
int err;
@@ -809,20 +778,8 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
return;
}
- if (!g_slist_find_custom(found_devices, bdaddr, bdaddr_cmp)) {
- bdaddr_t *new_bdaddr;
- char addr[18];
-
- new_bdaddr = g_new0(bdaddr_t, 1);
- bacpy(new_bdaddr, bdaddr);
-
- found_devices = g_slist_prepend(found_devices, new_bdaddr);
-
- ba2str(new_bdaddr, addr);
- DBG("New device found: %s", addr);
-
- new_dev = true;
- }
+ new_dev = !g_slist_find_custom(devices, bdaddr, bdaddr_cmp);
+ dev = get_device(bdaddr);
if (new_dev) {
struct hal_ev_device_found *ev = (void *) buf;
@@ -863,7 +820,8 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
}
if (eir.name) {
- cache_device_name(bdaddr, eir.name);
+ g_free(dev->name);
+ dev->name = g_strdup(eir.name);
size += fill_hal_prop(buf + size, HAL_PROP_DEVICE_NAME,
strlen(eir.name), eir.name);
--
1.8.3.2
^ permalink raw reply related
* [PATCH 1/8] android/bluetooth: Rename functions to match adapter properties names
From: Szymon Janc @ 2013-12-09 15:14 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This match adapter properties handling functions with properties names.
Will make code easier to understand and avoid clashes with remote
device properties functions.
---
android/bluetooth.c | 72 ++++++++++++++++++++++++++---------------------------
1 file changed, 36 insertions(+), 36 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 6174b1f..e2fa211 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1133,7 +1133,7 @@ static void uuid16_to_uint128(uint16_t uuid, uint128_t *u128)
ntoh128(&uuid128.value.uuid128, u128);
}
-static uint8_t get_uuids(void)
+static uint8_t get_adapter_uuids(void)
{
struct hal_ev_adapter_props_changed *ev;
GSList *list = adapter.uuids;
@@ -1183,7 +1183,7 @@ static void remove_uuid_complete(uint8_t status, uint16_t length,
mgmt_dev_class_changed_event(adapter.index, length, param, NULL);
- get_uuids();
+ get_adapter_uuids();
}
static void remove_uuid(uint16_t uuid)
@@ -1209,7 +1209,7 @@ static void add_uuid_complete(uint8_t status, uint16_t length,
mgmt_dev_class_changed_event(adapter.index, length, param, NULL);
- get_uuids();
+ get_adapter_uuids();
}
static void add_uuid(uint8_t svc_hint, uint16_t uuid)
@@ -1378,7 +1378,7 @@ static uint8_t set_adapter_name(const uint8_t *name, uint16_t len)
return HAL_STATUS_FAILED;
}
-static uint8_t set_discoverable_timeout(const void *buf, uint16_t len)
+static uint8_t set_adapter_discoverable_timeout(const void *buf, uint16_t len)
{
const uint32_t *timeout = buf;
@@ -1691,7 +1691,7 @@ static bool set_discoverable(uint8_t mode, uint16_t timeout)
return false;
}
-static uint8_t get_address(void)
+static uint8_t get_adapter_address(void)
{
uint8_t buf[BASELEN_PROP_CHANGED + sizeof(bdaddr_t)];
struct hal_ev_adapter_props_changed *ev = (void *) buf;
@@ -1709,7 +1709,7 @@ static uint8_t get_address(void)
return HAL_STATUS_SUCCESS;
}
-static uint8_t get_name(void)
+static uint8_t get_adapter_name(void)
{
if (!adapter.name)
return HAL_STATUS_FAILED;
@@ -1720,7 +1720,7 @@ static uint8_t get_name(void)
}
-static uint8_t get_class(void)
+static uint8_t get_adapter_class(void)
{
DBG("");
@@ -1729,7 +1729,7 @@ static uint8_t get_class(void)
return HAL_STATUS_SUCCESS;
}
-static uint8_t get_type(void)
+static uint8_t get_adapter_type(void)
{
DBG("Not implemented");
@@ -1738,7 +1738,7 @@ static uint8_t get_type(void)
return HAL_STATUS_FAILED;
}
-static uint8_t get_service(void)
+static uint8_t get_adapter_service_rec(void)
{
DBG("Not implemented");
@@ -1747,7 +1747,7 @@ static uint8_t get_service(void)
return HAL_STATUS_FAILED;
}
-static uint8_t get_scan_mode(void)
+static uint8_t get_adapter_scan_mode(void)
{
DBG("");
@@ -1756,7 +1756,7 @@ static uint8_t get_scan_mode(void)
return HAL_STATUS_SUCCESS;
}
-static uint8_t get_devices(void)
+static uint8_t get_adapter_bonded_devices(void)
{
DBG("Not implemented");
@@ -1765,7 +1765,7 @@ static uint8_t get_devices(void)
return HAL_STATUS_FAILED;
}
-static uint8_t get_discoverable_timeout(void)
+static uint8_t get_adapter_discoverable_timeout(void)
{
struct hal_ev_adapter_props_changed *ev;
uint8_t buf[BASELEN_PROP_CHANGED + sizeof(uint32_t)];
@@ -1794,31 +1794,31 @@ static void handle_get_adapter_prop_cmd(const void *buf, uint16_t len)
switch (cmd->type) {
case HAL_PROP_ADAPTER_ADDR:
- status = get_address();
+ status = get_adapter_address();
break;
case HAL_PROP_ADAPTER_NAME:
- status = get_name();
+ status = get_adapter_name();
break;
case HAL_PROP_ADAPTER_UUIDS:
- status = get_uuids();
+ status = get_adapter_uuids();
break;
case HAL_PROP_ADAPTER_CLASS:
- status = get_class();
+ status = get_adapter_class();
break;
case HAL_PROP_ADAPTER_TYPE:
- status = get_type();
+ status = get_adapter_type();
break;
case HAL_PROP_ADAPTER_SERVICE_REC:
- status = get_service();
+ status = get_adapter_service_rec();
break;
case HAL_PROP_ADAPTER_SCAN_MODE:
- status = get_scan_mode();
+ status = get_adapter_scan_mode();
break;
case HAL_PROP_ADAPTER_BONDED_DEVICES:
- status = get_devices();
+ status = get_adapter_bonded_devices();
break;
case HAL_PROP_ADAPTER_DISC_TIMEOUT:
- status = get_discoverable_timeout();
+ status = get_adapter_discoverable_timeout();
break;
default:
status = HAL_STATUS_FAILED;
@@ -1828,17 +1828,17 @@ static void handle_get_adapter_prop_cmd(const void *buf, uint16_t len)
ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROP, status);
}
-static void get_properties(void)
+static void get_adapter_properties(void)
{
- get_address();
- get_name();
- get_uuids();
- get_class();
- get_type();
- get_service();
- get_scan_mode();
- get_devices();
- get_discoverable_timeout();
+ get_adapter_address();
+ get_adapter_name();
+ get_adapter_uuids();
+ get_adapter_class();
+ get_adapter_type();
+ get_adapter_service_rec();
+ get_adapter_scan_mode();
+ get_adapter_bonded_devices();
+ get_adapter_discoverable_timeout();
}
static bool start_discovery(void)
@@ -1881,7 +1881,7 @@ static bool stop_discovery(void)
return false;
}
-static uint8_t set_scan_mode(const void *buf, uint16_t len)
+static uint8_t set_adapter_scan_mode(const void *buf, uint16_t len)
{
const uint8_t *mode = buf;
bool conn, disc, cur_conn, cur_disc;
@@ -1958,13 +1958,13 @@ static void handle_set_adapter_prop_cmd(const void *buf, uint16_t len)
switch (cmd->type) {
case HAL_PROP_ADAPTER_SCAN_MODE:
- status = set_scan_mode(cmd->val, cmd->len);
+ status = set_adapter_scan_mode(cmd->val, cmd->len);
break;
case HAL_PROP_ADAPTER_NAME:
status = set_adapter_name(cmd->val, cmd->len);
break;
case HAL_PROP_ADAPTER_DISC_TIMEOUT:
- status = set_discoverable_timeout(cmd->val, cmd->len);
+ status = set_adapter_discoverable_timeout(cmd->val, cmd->len);
break;
default:
DBG("Unhandled property type 0x%x", cmd->type);
@@ -2227,7 +2227,7 @@ static void handle_enable_cmd(const void *buf, uint16_t len)
/* Framework expects all properties to be emitted while
* enabling adapter */
- get_properties();
+ get_adapter_properties();
if (adapter.current_settings & MGMT_SETTING_POWERED) {
status = HAL_STATUS_DONE;
@@ -2265,7 +2265,7 @@ failed:
static void handle_get_adapter_props_cmd(const void *buf, uint16_t len)
{
- get_properties();
+ get_adapter_properties();
ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROPS,
HAL_STATUS_SUCCESS);
--
1.8.3.2
^ permalink raw reply related
* [PATCH] bnep: Remove unneeded assignment
From: Andrei Emeltchenko @ 2013-12-09 14:17 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
profiles/network/bnep.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 0a719a2..912c0c2 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -88,7 +88,6 @@ static void free_bnep_connect(struct bnep_conn *bc)
}
g_free(bc);
- bc = NULL;
}
uint16_t bnep_service_id(const char *svc)
--
1.8.3.2
^ permalink raw reply related
* [PATCH] btmgmt: Remove unneeded code
From: Andrei Emeltchenko @ 2013-12-09 14:13 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
tools/btmgmt.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index 1d71d74..f31d8b1 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -555,7 +555,6 @@ static void user_confirm(uint16_t index, uint16_t len, const void *param,
rsp_len = strlen(rsp);
if (rsp[rsp_len - 1] == '\n') {
rsp[rsp_len - 1] = '\0';
- rsp_len--;
}
if (rsp[0] == 'y' || rsp[0] == 'Y')
--
1.8.3.2
^ permalink raw reply related
* [PATCH] android/socket: Use getsockopt to set buffer
From: Andrei Emeltchenko @ 2013-12-09 14:11 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Use buffer size similar to one returned by getsockopt for RFCOMM socket.
If getsockopt fails use default value 25400 which is half of the default
RFCOMM kernel buffer (50800) calculated in kernel as:
RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 10
---
android/socket.c | 43 +++++++++++++++++++++++++++++++++++++------
1 file changed, 37 insertions(+), 6 deletions(-)
diff --git a/android/socket.c b/android/socket.c
index 9020874..b5f7b1d 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -52,6 +52,8 @@
#define SVC_HINT_OBEX 0x10
+#define SOCKET_BUFFER 25400 /* Half of the kernel buffer */
+
static bdaddr_t adapter_addr;
/* Simple list of RFCOMM server sockets */
@@ -71,9 +73,33 @@ struct rfcomm_sock {
bdaddr_t dst;
uint32_t service_handle;
+ unsigned char *buf;
+ int buf_size;
+
const struct profile_info *profile;
};
+static void rfsock_set_buffer(struct rfcomm_sock *rfsock)
+{
+ socklen_t len = sizeof(int);
+ int size;
+
+ if (getsockopt(rfsock->real_sock, SOL_SOCKET, SO_RCVBUF, &size, &len)
+ < 0) {
+ warn("getsockopt(SO_RCVBUF) failed: %s", strerror(errno));
+ /* Use default buffer */
+ size = SOCKET_BUFFER;
+ } else {
+ /* Kernel doubles this */
+ size /= 2;
+ }
+
+ DBG("Set buffer size %d", size);
+
+ rfsock->buf = g_malloc(size);
+ rfsock->buf_size = size;
+}
+
static struct rfcomm_sock *create_rfsock(int sock, int *hal_fd)
{
int fds[2] = {-1, -1};
@@ -90,6 +116,9 @@ static struct rfcomm_sock *create_rfsock(int sock, int *hal_fd)
*hal_fd = fds[1];
rfsock->real_sock = sock;
+ if (sock >= 0)
+ rfsock_set_buffer(rfsock);
+
return rfsock;
}
@@ -121,6 +150,9 @@ static void cleanup_rfsock(gpointer data)
if (rfsock->service_handle)
bt_adapter_remove_record(rfsock->service_handle);
+ if (rfsock->buf)
+ g_free(rfsock->buf);
+
g_free(rfsock);
}
@@ -487,7 +519,6 @@ static gboolean sock_stack_event_cb(GIOChannel *io, GIOCondition cond,
gpointer data)
{
struct rfcomm_sock *rfsock = data;
- unsigned char buf[1024];
int len, sent;
if (cond & G_IO_HUP) {
@@ -501,14 +532,14 @@ static gboolean sock_stack_event_cb(GIOChannel *io, GIOCondition cond,
goto fail;
}
- len = read(rfsock->fd, buf, sizeof(buf));
+ len = read(rfsock->fd, rfsock->buf, rfsock->buf_size);
if (len <= 0) {
error("read(): %s", strerror(errno));
/* Read again */
return TRUE;
}
- sent = try_write_all(rfsock->real_sock, buf, len);
+ sent = try_write_all(rfsock->real_sock, rfsock->buf, len);
if (sent < 0) {
error("write(): %s", strerror(errno));
goto fail;
@@ -526,7 +557,6 @@ static gboolean sock_rfcomm_event_cb(GIOChannel *io, GIOCondition cond,
gpointer data)
{
struct rfcomm_sock *rfsock = data;
- unsigned char buf[1024];
int len, sent;
if (cond & G_IO_HUP) {
@@ -540,14 +570,14 @@ static gboolean sock_rfcomm_event_cb(GIOChannel *io, GIOCondition cond,
goto fail;
}
- len = read(rfsock->real_sock, buf, sizeof(buf));
+ len = read(rfsock->real_sock, rfsock->buf, rfsock->buf_size);
if (len <= 0) {
error("read(): %s", strerror(errno));
/* Read again */
return TRUE;
}
- sent = try_write_all(rfsock->fd, buf, len);
+ sent = try_write_all(rfsock->fd, rfsock->buf, len);
if (sent < 0) {
error("write(): %s", strerror(errno));
goto fail;
@@ -866,6 +896,7 @@ static void sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
}
rfsock->real_sock = g_io_channel_unix_get_fd(io);
+ rfsock_set_buffer(rfsock);
rfsock->channel = chan;
connections = g_list_append(connections, rfsock);
--
1.8.3.2
^ permalink raw reply related
* Crasher when cancelling pairing
From: Bastien Nocera @ 2013-12-09 13:16 UTC (permalink / raw)
To: linux-bluetooth
Heya,
When a remote pairing is cancelled, bluetoothd will go in a loop, or
crash.
1. Start pairing from a non-SSP remote device (such as my old phone)
2. Enter the PIN on the phone
3. When the RequestPinCode callback is called on the computer, kill the
agent (simple-agent for example).
4. bluetoothd goes in a loop or crashes as it does in:
https://bugzilla.redhat.com/show_bug.cgi?id=1027365
Applying this patch gives more reasonable backtraces:
diff --git a/src/agent.c b/src/agent.c
index bcba969..b292881 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -203,6 +203,8 @@ void agent_unref(struct agent *agent)
if (agent->ref > 0)
return;
+ g_assert (agent->ref == 0);
+
if (agent->request) {
DBusError err;
agent_pincode_cb pincode_cb;
And asserts nicely before looping forever:
bluetoothd[28090]: src/agent.c:agent_unref() 0x6c5f90: ref=-1
**
ERROR:src/agent.c:206:agent_unref: assertion failed: (agent->ref == 0)
The backtrace:
#0 0x00000033f2835c59 in raise () from /lib64/libc.so.6
#1 0x00000033f2837368 in abort () from /lib64/libc.so.6
#2 0x00007ffff7d000ed in _g_log_abort () from /lib64/libglib-2.0.so.0
#3 0x00007ffff7d1dc97 in g_assertion_message () from /lib64/libglib-2.0.so.0
#4 0x00007ffff7d1dcfa in g_assertion_message_expr () from /lib64/libglib-2.0.so.0
#5 0x00000000004529f4 in agent_unref (agent=0x6c5f90) at src/agent.c:206
#6 0x00000000004621d7 in pincode_cb (agent=<optimized out>, err=<optimized out>, pin=0x0, data=<optimized out>) at src/device.c:3979
#7 0x000000000045297d in agent_unref (agent=0x6c5f90) at src/agent.c:221
#8 0x00000000004621d7 in pincode_cb (agent=<optimized out>, err=<optimized out>, pin=0x0, data=<optimized out>) at src/device.c:3979
#9 0x0000000000452236 in pincode_reply (call=<optimized out>, user_data=0x6f2790) at src/agent.c:445
#10 0x00000033f780c782 in complete_pending_call_and_unlock (connection=connection@entry=0x6c6320, pending=0x6eb100, message=message@entry=0x6ce680) at dbus-connection.c:2314
#11 0x00000033f780f9b1 in dbus_connection_dispatch (connection=connection@entry=0x6c6320) at dbus-connection.c:4580
#12 0x0000000000474ea8 in message_dispatch (data=0x6c6320) at gdbus/mainloop.c:76
#13 0x00007ffff7cf9e43 in g_timeout_dispatch () from /lib64/libglib-2.0.so.0
#14 0x00007ffff7cf92a6 in g_main_context_dispatch () from /lib64/libglib-2.0.so.0
#15 0x00007ffff7cf9628 in g_main_context_iterate.isra.24 () from /lib64/libglib-2.0.so.0
#16 0x00007ffff7cf9a3a in g_main_loop_run () from /lib64/libglib-2.0.so.0
#17 0x000000000040a530 in main (argc=1, argv=0x7fffffffe518) at src/main.c:587
Cheers
^ permalink raw reply related
* [PATCH] adapter: Remove not needed struct adapter_keys
From: Szymon Janc @ 2013-12-09 10:11 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This is a leftover from using old storage format.
---
src/adapter.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 41f7bd6..8ec9e92 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2196,11 +2196,6 @@ static const GDBusPropertyTable adapter_properties[] = {
{ }
};
-struct adapter_keys {
- struct btd_adapter *adapter;
- GSList *keys;
-};
-
static int str2buf(const char *str, uint8_t *buf, size_t blen)
{
int i, dlen;
@@ -2479,8 +2474,8 @@ static void load_devices(struct btd_adapter *adapter)
{
char filename[PATH_MAX + 1];
char srcaddr[18];
- struct adapter_keys keys = { adapter, NULL };
- struct adapter_keys ltks = { adapter, NULL };
+ GSList *keys = NULL;
+ GSList *ltks = NULL;
DIR *dir;
struct dirent *entry;
@@ -2514,11 +2509,11 @@ static void load_devices(struct btd_adapter *adapter)
key_info = get_key_info(key_file, entry->d_name);
if (key_info)
- keys.keys = g_slist_append(keys.keys, key_info);
+ keys = g_slist_append(keys, key_info);
ltk_info = get_ltk_info(key_file, entry->d_name);
if (ltk_info)
- ltks.keys = g_slist_append(ltks.keys, ltk_info);
+ ltks = g_slist_append(ltks, ltk_info);
list = g_slist_find_custom(adapter->devices, entry->d_name,
device_address_cmp);
@@ -2553,11 +2548,11 @@ free:
closedir(dir);
- load_link_keys(adapter, keys.keys, main_opts.debug_keys);
- g_slist_free_full(keys.keys, g_free);
+ load_link_keys(adapter, keys, main_opts.debug_keys);
+ g_slist_free_full(keys, g_free);
- load_ltks(adapter, ltks.keys);
- g_slist_free_full(ltks.keys, g_free);
+ load_ltks(adapter, ltks);
+ g_slist_free_full(ltks, g_free);
}
int btd_adapter_block_address(struct btd_adapter *adapter,
--
1.8.3.2
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox