* [PATCH v2 2/7] android/tester: Add pre-setup and post-teardown routines
From: Marcin Kraglak @ 2013-12-10 10:45 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386672344-13438-1-git-send-email-marcin.kraglak@tieto.com>
This will add hciemu initialization and cleanup. These functions
will be called to create hci emulator and cleanup it.
---
android/Makefile.am | 10 ++-
android/android-tester.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 179 insertions(+), 2 deletions(-)
diff --git a/android/Makefile.am b/android/Makefile.am
index 0768985..5364c2e 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -85,7 +85,15 @@ android_haltest_LDFLAGS = -pthread
noinst_PROGRAMS += android/android-tester
-android_android_tester_SOURCES = android/android-tester.c
+android_android_tester_SOURCES = emulator/btdev.h emulator/btdev.c \
+ emulator/bthost.h emulator/bthost.c \
+ src/shared/util.h src/shared/util.c \
+ src/shared/mgmt.h src/shared/mgmt.c \
+ src/shared/hciemu.h src/shared/hciemu.c \
+ src/shared/tester.h src/shared/tester.c \
+ android/android-tester.c
+
+android_android_tester_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
endif
diff --git a/android/android-tester.c b/android/android-tester.c
index f5c42b0..48e408d 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -15,7 +15,176 @@
*
*/
+#include <unistd.h>
+
+#include <glib.h>
+
+#include "lib/bluetooth.h"
+#include "lib/mgmt.h"
+
+#include "src/shared/tester.h"
+#include "src/shared/mgmt.h"
+#include "src/shared/hciemu.h"
+
+struct test_data {
+ struct mgmt *mgmt;
+ uint16_t mgmt_index;
+ struct hciemu *hciemu;
+ enum hciemu_type hciemu_type;
+ void *test_data;
+};
+
+static void read_info_callback(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ struct test_data *data = tester_get_data();
+ const struct mgmt_rp_read_info *rp = param;
+ char addr[18];
+ uint16_t manufacturer;
+ uint32_t supported_settings, current_settings;
+
+ tester_print("Read Info callback");
+ tester_print(" Status: 0x%02x", status);
+
+ if (status || !param) {
+ tester_pre_setup_failed();
+ return;
+ }
+
+ ba2str(&rp->bdaddr, addr);
+ manufacturer = btohs(rp->manufacturer);
+ supported_settings = btohl(rp->supported_settings);
+ current_settings = btohl(rp->current_settings);
+
+ tester_print(" Address: %s", addr);
+ tester_print(" Version: 0x%02x", rp->version);
+ tester_print(" Manufacturer: 0x%04x", manufacturer);
+ tester_print(" Supported settings: 0x%08x", supported_settings);
+ tester_print(" Current settings: 0x%08x", current_settings);
+ tester_print(" Class: 0x%02x%02x%02x",
+ rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]);
+ tester_print(" Name: %s", rp->name);
+ tester_print(" Short name: %s", rp->short_name);
+
+ if (strcmp(hciemu_get_address(data->hciemu), addr)) {
+ tester_pre_setup_failed();
+ return;
+ }
+
+ tester_pre_setup_complete();
+}
+
+static void index_added_callback(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ struct test_data *data = tester_get_data();
+
+ tester_print("Index Added callback");
+ tester_print(" Index: 0x%04x", index);
+
+ data->mgmt_index = index;
+
+ mgmt_send(data->mgmt, MGMT_OP_READ_INFO, data->mgmt_index, 0, NULL,
+ read_info_callback, NULL, NULL);
+}
+
+static void index_removed_callback(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ struct test_data *data = tester_get_data();
+
+ tester_print("Index Removed callback");
+ tester_print(" Index: 0x%04x", index);
+
+ if (index != data->mgmt_index)
+ return;
+
+ mgmt_unregister_index(data->mgmt, data->mgmt_index);
+
+ mgmt_unref(data->mgmt);
+ data->mgmt = NULL;
+
+ tester_post_teardown_complete();
+}
+
+static void read_index_list_callback(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ struct test_data *data = tester_get_data();
+
+ tester_print("Read Index List callback");
+ tester_print(" Status: 0x%02x", status);
+
+ if (status || !param) {
+ tester_pre_setup_failed();
+ return;
+ }
+
+ mgmt_register(data->mgmt, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
+ index_added_callback, NULL, NULL);
+
+ mgmt_register(data->mgmt, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
+ index_removed_callback, NULL, NULL);
+
+ data->hciemu = hciemu_new(data->hciemu_type);
+ if (!data->hciemu) {
+ tester_warn("Failed to setup HCI emulation");
+ tester_pre_setup_failed();
+ return;
+ }
+
+ tester_print("New hciemu instance created");
+}
+
+static void test_pre_setup(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+
+ if (!tester_use_debug())
+ fclose(stderr);
+
+ data->mgmt = mgmt_new_default();
+ if (!data->mgmt) {
+ tester_warn("Failed to setup management interface");
+ tester_pre_setup_failed();
+ return;
+ }
+
+ mgmt_send(data->mgmt, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0,
+ NULL, read_index_list_callback, NULL, NULL);
+}
+
+static void test_post_teardown(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+
+ hciemu_unref(data->hciemu);
+ data->hciemu = NULL;
+}
+
+static void pass_test(const void *test_data)
+{
+ tester_test_passed();
+}
+
+#define test_bredrle(name, data, test_setup, test, test_teardown) \
+ do { \
+ struct test_data *user; \
+ user = g_malloc0(sizeof(struct test_data)); \
+ if (!user) \
+ break; \
+ user->hciemu_type = HCIEMU_TYPE_BREDRLE; \
+ user->test_data = data; \
+ tester_add_full(name, data, test_pre_setup, test_setup, \
+ test, test_teardown, test_post_teardown, \
+ 3, user, g_free); \
+ } while (0)
+
int main(int argc, char *argv[])
{
- return 0;
+ tester_init(&argc, &argv);
+
+ test_bredrle("test", NULL, NULL, pass_test, NULL);
+
+ return tester_run();
}
--
1.8.3.1
^ permalink raw reply related
* [PATCH v2 1/7] android/tester: Add android-tester
From: Marcin Kraglak @ 2013-12-10 10:45 UTC (permalink / raw)
To: linux-bluetooth
This commit add android-tester.c to tree and Makefile.am.
This will contain set of unit tests for testing android daemon.
---
.gitignore | 1 +
android/Makefile.am | 4 ++++
android/android-tester.c | 21 +++++++++++++++++++++
3 files changed, 26 insertions(+)
create mode 100644 android/android-tester.c
diff --git a/.gitignore b/.gitignore
index 2d3435a..c570728 100644
--- a/.gitignore
+++ b/.gitignore
@@ -107,3 +107,4 @@ unit/test-*.trs
android/system-emulator
android/bluetoothd
android/haltest
+android/android-tester
diff --git a/android/Makefile.am b/android/Makefile.am
index df04762..0768985 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -83,6 +83,10 @@ android_haltest_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/android \
android_haltest_LDFLAGS = -pthread
+noinst_PROGRAMS += android/android-tester
+
+android_android_tester_SOURCES = android/android-tester.c
+
endif
EXTRA_DIST += android/Android.mk android/hal-ipc-api.txt android/README \
diff --git a/android/android-tester.c b/android/android-tester.c
new file mode 100644
index 0000000..f5c42b0
--- /dev/null
+++ b/android/android-tester.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+int main(int argc, char *argv[])
+{
+ return 0;
+}
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH BlueZ 1/2] core: Fix not replying to DisconnectProfile
From: Johan Hedberg @ 2013-12-10 9:32 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1386664877-10137-1-git-send-email-luiz.dentz@gmail.com>
Hi Luiz,
On Tue, Dec 10, 2013, Luiz Augusto von Dentz wrote:
> 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(-)
Both patches have been applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH] Bluetooth: Fix handling of L2CAP Command Reject over LE
From: Marcel Holtmann @ 2013-12-10 9:17 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org development
In-Reply-To: <1386665568-7801-1-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
> If we receive an L2CAP command reject message over LE we should take
> appropriate action on the corresponding channel. This is particularly
> important when trying to interact with a remote pre-4.1 system using LE
> CoC signaling messages. If we don't react to the command reject the
> corresponding socket would not be notified until a connection timeout
> occurs.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/l2cap_core.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
patch has been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH 2/2] input: Fix crash when SDP record isn't available
From: Johan Hedberg @ 2013-12-10 9:08 UTC (permalink / raw)
To: Bastien Nocera; +Cc: linux-bluetooth
In-Reply-To: <1386452701.32408.25.camel@nuvo>
Hi Bastien,
On Sat, Dec 07, 2013, Bastien Nocera wrote:
> On Sat, 2013-12-07 at 21:52 +0400, Johan Hedberg wrote:
> > Hi Bastien,
> >
> > On Sat, Dec 07, 2013, Bastien Nocera wrote:
> > > On startup, if the SDP cache has been removed but the pairing
> > > information is still present, we'd crash trying to access inside a
> > > NULL record struct.
> > > ---
> > > profiles/input/device.c | 3 +++
> > > 1 file changed, 3 insertions(+)
> > >
> > > diff --git a/profiles/input/device.c b/profiles/input/device.c
> > > index 521aca8..62f6dbb 100644
> > > --- a/profiles/input/device.c
> > > +++ b/profiles/input/device.c
> > > @@ -811,6 +811,9 @@ static struct input_device *input_device_new(struct btd_service *service)
> > > struct input_device *idev;
> > > char name[HCI_MAX_NAME_LENGTH + 1];
> > >
> > > + if (!rec)
> > > + return NULL;
> > > +
> > > idev = g_new0(struct input_device, 1);
> > > bacpy(&idev->src, btd_adapter_get_address(adapter));
> > > bacpy(&idev->dst, device_get_address(device));
> >
> > I've applied your first patch, but I'd like to understand a bit better
> > how you'd end up in this situation. Is this accomplishable through BlueZ
> > APIs or only if one goes and messes with the storage directly? Either
> > way, is this the best approach or should we consider still creating the
> > input device but just ignore the bits that depend on the SDP record?
>
> I rm'ed the file in the cache/ directory. I'm not too fussed about what
> the end result actually is, it just shouldn't crash. The same patch with
> a warning that you shouldn't fiddle with the cache directory would be
> fine as well ;)
Fair enough. I've applied the patch now. Thanks.
Johan
^ permalink raw reply
* [PATCH] Bluetooth: Fix handling of L2CAP Command Reject over LE
From: johan.hedberg @ 2013-12-10 8:52 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
If we receive an L2CAP command reject message over LE we should take
appropriate action on the corresponding channel. This is particularly
important when trying to interact with a remote pre-4.1 system using LE
CoC signaling messages. If we don't react to the command reject the
corresponding socket would not be notified until a connection timeout
occurs.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index ae0054ccee5b..b6bca64b320d 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5736,6 +5736,31 @@ static inline int l2cap_le_credits(struct l2cap_conn *conn,
return 0;
}
+static inline int l2cap_le_command_rej(struct l2cap_conn *conn,
+ struct l2cap_cmd_hdr *cmd, u16 cmd_len,
+ u8 *data)
+{
+ struct l2cap_cmd_rej_unk *rej = (struct l2cap_cmd_rej_unk *) data;
+ struct l2cap_chan *chan;
+
+ if (cmd_len < sizeof(*rej))
+ return -EPROTO;
+
+ mutex_lock(&conn->chan_lock);
+
+ chan = __l2cap_get_chan_by_ident(conn, cmd->ident);
+ if (!chan)
+ goto done;
+
+ l2cap_chan_lock(chan);
+ l2cap_chan_del(chan, ECONNREFUSED);
+ l2cap_chan_unlock(chan);
+
+done:
+ mutex_unlock(&conn->chan_lock);
+ return 0;
+}
+
static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
struct l2cap_cmd_hdr *cmd, u16 cmd_len,
u8 *data)
@@ -5755,6 +5780,7 @@ static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
switch (cmd->code) {
case L2CAP_COMMAND_REJ:
+ l2cap_le_command_rej(conn, cmd, cmd_len, data);
break;
case L2CAP_CONN_PARAM_UPDATE_REQ:
--
1.8.4.2
^ permalink raw reply related
* [PATCH BlueZ 2/2] core: Fix leaking disconnect message
From: Luiz Augusto von Dentz @ 2013-12-10 8:41 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386664877-10137-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If a disconnect message is pending return an error since currently the
code cannot process it in parallel.
---
src/device.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/device.c b/src/device.c
index 953a338..18543ee 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1434,6 +1434,9 @@ static DBusMessage *disconnect_profile(DBusConnection *conn, DBusMessage *msg,
if (!service)
return btd_error_invalid_args(msg);
+ if (dev->disconnect)
+ return btd_error_in_progress(msg);
+
dev->disconnect = dbus_message_ref(msg);
err = btd_service_disconnect(service);
--
1.8.3.1
^ permalink raw reply related
* [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
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