* [PATCH 01/18] Add initial neard plugin implementation
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 02/18] eir: Add support for parsing SSP hash and randomizer Szymon Janc
` (16 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Initial implementation. Only register and unregister support.
---
Makefile.am | 11 ++-
acinclude.m4 | 19 +++--
bootstrap-configure | 3 +-
plugins/neard.c | 226 +++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 249 insertions(+), 10 deletions(-)
create mode 100644 plugins/neard.c
diff --git a/Makefile.am b/Makefile.am
index 372111a..1d6b235 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -259,9 +259,14 @@ builtin_modules += wiimote
builtin_sources += plugins/wiimote.c
endif
-if DBUSOOBPLUGIN
-builtin_modules += dbusoob
-builtin_sources += plugins/dbusoob.c
+if OOB
+builtin_modules += @OOB_PLUGIN@
+builtin_sources += plugins/@OOB_PLUGIN@.c
+
+noinst_LIBRARIES += plugins/liboob.a
+
+plugins_liboob_a_SOURCES = plugins/dbusoob.c plugins/neard.c
+
endif
if MAINTAINER_MODE
diff --git a/acinclude.m4 b/acinclude.m4
index 39b0a18..69ab88f 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -185,9 +185,10 @@ AC_DEFUN([AC_ARG_BLUEZ], [
datafiles_enable=yes
telephony_driver=dummy
sap_driver=dummy
- dbusoob_enable=no
wiimote_enable=no
gatt_enable=no
+ oob_enable=no
+ oob=dbusoob
AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization], [disable code optimization]), [
optimization_enable=${enableval}
@@ -280,10 +281,6 @@ AC_DEFUN([AC_ARG_BLUEZ], [
AC_SUBST([TELEPHONY_DRIVER], [telephony-${telephony_driver}.c])
- AC_ARG_ENABLE(dbusoob, AC_HELP_STRING([--enable-dbusoob], [compile with D-Bus OOB plugin]), [
- dbusoob_enable=${enableval}
- ])
-
AC_ARG_ENABLE(wiimote, AC_HELP_STRING([--enable-wiimote], [compile with Wii Remote plugin]), [
wiimote_enable=${enableval}
])
@@ -292,6 +289,16 @@ AC_DEFUN([AC_ARG_BLUEZ], [
gatt_enable=${enableval}
])
+ AC_ARG_ENABLE(oob, AC_HELP_STRING([--enable-oob], [enable OOB plugin]), [
+ oob_enable=${enableval}
+ ])
+
+ AC_ARG_WITH(oob, AC_HELP_STRING([--with-oob=PLUGIN], [select OOB plugin (dbusoob, neard)]), [
+ oob=${withval}
+ ])
+
+ AC_SUBST([OOB_PLUGIN], [${oob}])
+
misc_cflags=""
misc_ldflags=""
@@ -339,7 +346,7 @@ AC_DEFUN([AC_ARG_BLUEZ], [
AM_CONDITIONAL(HID2HCI, test "${hid2hci_enable}" = "yes" && test "${usb_found}" = "yes" && test "${udev_found}" = "yes")
AM_CONDITIONAL(DFUTOOL, test "${dfutool_enable}" = "yes" && test "${usb_found}" = "yes")
AM_CONDITIONAL(DATAFILES, test "${datafiles_enable}" = "yes")
- AM_CONDITIONAL(DBUSOOBPLUGIN, test "${dbusoob_enable}" = "yes")
+ AM_CONDITIONAL(OOB, test "${oob_enable}" = "yes")
AM_CONDITIONAL(WIIMOTEPLUGIN, test "${wiimote_enable}" = "yes")
AM_CONDITIONAL(GATTMODULES, test "${gatt_enable}" = "yes")
AM_CONDITIONAL(HOGPLUGIN, test "${gatt_enable}" = "yes" && test "${input_enable}" = "yes")
diff --git a/bootstrap-configure b/bootstrap-configure
index 7177c65..37f1a7d 100755
--- a/bootstrap-configure
+++ b/bootstrap-configure
@@ -23,7 +23,8 @@ fi
--enable-hid2hci \
--enable-test \
--enable-cups \
- --enable-dbusoob \
+ --enable-oob \
+ --with-oob=neard\
--enable-sap \
--enable-wiimote \
--disable-pcmcia \
diff --git a/plugins/neard.c b/plugins/neard.c
new file mode 100644
index 0000000..5f467b3
--- /dev/null
+++ b/plugins/neard.c
@@ -0,0 +1,226 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2012 Tieto Poland
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <gdbus.h>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/sdp.h>
+
+#include "plugin.h"
+#include "log.h"
+#include "dbus-common.h"
+#include "adapter.h"
+
+#define NEARD_NAME "org.neard"
+#define NEARD_PATH "/"
+#define NEARD_MANAGER_INTERFACE "org.neard.Manager"
+#define AGENT_INTERFACE "org.neard.HandoverAgent"
+#define AGENT_PATH "/org/bluez/neard_handover_agent"
+#define ERROR_INTERFACE "org.neard.HandoverAgent.Error"
+
+static DBusConnection *conn = NULL;
+static DBusPendingCall *pending = NULL;
+
+static guint watcher_id = 0;
+static gboolean agent_registered = FALSE;
+
+static DBusMessage *error_failed(DBusMessage *msg, int error)
+{
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ "%s", strerror(error));
+}
+
+static void register_agent_cb(DBusPendingCall *call, void *user_data)
+{
+ DBusMessage *message;
+ DBusError err;
+
+ message = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&err);
+ if (dbus_set_error_from_message(&err, message)) {
+ error("neard manager replied with an error: %s, %s",
+ err.name, err.message);
+ dbus_error_free(&err);
+ dbus_message_unref(message);
+
+ g_dbus_unregister_interface(conn, AGENT_PATH, AGENT_INTERFACE);
+ return;
+ }
+
+ dbus_message_unref(message);
+ dbus_pending_call_cancel(pending);
+ pending = NULL;
+ agent_registered = TRUE;
+}
+
+static void register_agent(void)
+{
+ DBusMessage *message;
+ const gchar *path = AGENT_PATH;
+
+ message = dbus_message_new_method_call(NEARD_NAME, NEARD_PATH,
+ NEARD_MANAGER_INTERFACE, "RegisterHandoverAgent");
+ if (!message) {
+ error("Couldn't allocate D-Bus message");
+ return;
+ }
+
+ dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+
+ if (!dbus_connection_send_with_reply(conn, message, &pending, -1)) {
+ error("D-Bus send failed");
+ return;
+ }
+
+ dbus_pending_call_set_notify(pending, register_agent_cb, NULL, NULL);
+}
+
+static void unregister_agent(void)
+{
+ DBusMessage *message;
+ const gchar *path = AGENT_PATH;
+
+ agent_registered = FALSE;
+
+ message = dbus_message_new_method_call(NEARD_NAME, NEARD_PATH,
+ NEARD_MANAGER_INTERFACE, "UnregisterHandoverAgent");
+
+ if (!message) {
+ error("Couldn't allocate D-Bus message");
+ goto unregister;
+ }
+
+ dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+
+ if (!g_dbus_send_message(conn, message))
+ error("D-Bus send failed");
+
+unregister:
+ g_dbus_unregister_interface(conn, AGENT_PATH, AGENT_INTERFACE);
+}
+
+static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg,
+ void *user_data)
+{
+ DBG("");
+
+ return error_failed(msg, ENOTSUP);
+}
+
+static DBusMessage *request_oob(DBusConnection *conn, DBusMessage *msg,
+ void *data)
+{
+ DBG("");
+
+ return error_failed(msg, ENOTSUP);
+}
+
+static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,
+ void *user_data)
+{
+ DBG("");
+
+ agent_registered = FALSE;
+
+ g_dbus_unregister_interface(conn, AGENT_PATH, AGENT_INTERFACE);
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static const GDBusMethodTable neard_methods[] = {
+ { GDBUS_ASYNC_METHOD("RequestOOB",
+ GDBUS_ARGS({ "data", "a{sv}" }),
+ GDBUS_ARGS({ "data", "a{sv}" }), request_oob) },
+ { GDBUS_ASYNC_METHOD("PushOOB",
+ GDBUS_ARGS({ "data", "a{sv}"}), NULL, push_oob) },
+ { GDBUS_METHOD("Release", NULL, NULL, release) },
+ { }
+};
+
+static void neard_appeared(DBusConnection *conn, void *user_data)
+{
+ DBG("");
+
+ if (!g_dbus_register_interface(conn, AGENT_PATH, AGENT_INTERFACE,
+ neard_methods,
+ NULL, NULL, NULL, NULL)) {
+ error("neard interface init failed on path " AGENT_PATH);
+ return;
+ }
+
+ register_agent();
+}
+
+static void neard_vanished(DBusConnection *conn, void *user_data)
+{
+ DBG("");
+
+ if (pending) {
+ dbus_pending_call_cancel(pending);
+ pending = NULL;
+ }
+
+ /* neard existed without unregistering agent */
+ if (agent_registered) {
+ g_dbus_unregister_interface(conn, AGENT_PATH, AGENT_INTERFACE);
+ agent_registered = FALSE;
+ }
+}
+
+static int neard_init(void)
+{
+ DBG("Setup neard plugin");
+
+ conn = get_dbus_connection();
+
+ watcher_id = g_dbus_add_service_watch(conn, NEARD_NAME, neard_appeared,
+ neard_vanished,
+ NULL, NULL);
+ if (watcher_id == 0)
+ return -ENOMEM;
+
+ return 0;
+}
+
+static void neard_exit(void)
+{
+ DBG("Cleanup neard plugin");
+
+ g_dbus_remove_watch(conn, watcher_id);
+ watcher_id = 0;
+
+ if (agent_registered)
+ unregister_agent();
+}
+
+BLUETOOTH_PLUGIN_DEFINE(neard, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
+ neard_init, neard_exit)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 02/18] eir: Add support for parsing SSP hash and randomizer
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
2012-09-21 10:02 ` [PATCH 01/18] Add initial neard plugin implementation Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 03/18] eir: Store class in struct eir_data as uint32_t Szymon Janc
` (15 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This will be used over OOB mechanism.
---
src/eir.c | 18 ++++++++++++++++++
src/eir.h | 4 ++++
2 files changed, 22 insertions(+)
diff --git a/src/eir.c b/src/eir.c
index 50912a0..c29be40 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -44,6 +44,10 @@ void eir_data_free(struct eir_data *eir)
eir->services = NULL;
g_free(eir->name);
eir->name = NULL;
+ g_free(eir->hash);
+ eir->hash = NULL;
+ g_free(eir->randomizer);
+ eir->randomizer = NULL;
}
static void eir_parse_uuid16(struct eir_data *eir, void *data, uint8_t len)
@@ -170,6 +174,20 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len)
break;
eir->appearance = bt_get_le16(data);
break;
+
+ case EIR_SSP_HASH:
+ if (data_len < 16)
+ break;
+ eir->hash = g_malloc(16);
+ memcpy(eir->hash, data, 16);
+ break;
+
+ case EIR_SSP_RANDOMIZER:
+ if (data_len < 16)
+ break;
+ eir->randomizer = g_malloc(16);
+ memcpy(eir->randomizer, data, 16);
+ break;
}
eir_data += field_len + 1;
diff --git a/src/eir.h b/src/eir.h
index 3c81024..e6e870a 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -33,6 +33,8 @@
#define EIR_NAME_COMPLETE 0x09 /* complete local name */
#define EIR_TX_POWER 0x0A /* transmit power level */
#define EIR_CLASS_OF_DEV 0x0D /* Class of Device */
+#define EIR_SSP_HASH 0x0E /* SSP Hash */
+#define EIR_SSP_RANDOMIZER 0x0F /* SSP Randomizer */
#define EIR_DEVICE_ID 0x10 /* device ID */
#define EIR_GAP_APPEARANCE 0x19 /* GAP appearance */
@@ -48,6 +50,8 @@ struct eir_data {
uint8_t dev_class[3];
uint16_t appearance;
gboolean name_complete;
+ uint8_t *hash;
+ uint8_t *randomizer;
};
void eir_data_free(struct eir_data *eir);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 03/18] eir: Store class in struct eir_data as uint32_t
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
2012-09-21 10:02 ` [PATCH 01/18] Add initial neard plugin implementation Szymon Janc
2012-09-21 10:02 ` [PATCH 02/18] eir: Add support for parsing SSP hash and randomizer Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 04/18] eir: Add eir_parse_oob function Szymon Janc
` (14 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This simplify code as class is stored on storage as uint32_t and
had to be converted to it in few places.
---
src/adapter.c | 11 ++++-------
src/eir.c | 3 ++-
src/eir.h | 2 +-
src/event.c | 11 +++--------
src/event.h | 2 +-
src/mgmt.c | 2 +-
6 files changed, 12 insertions(+), 19 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 06ba78c..d34e966 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2929,7 +2929,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
struct eir_data eir_data;
char *alias, *name;
gboolean legacy, name_known;
- uint32_t dev_class;
int err;
GSList *l;
@@ -2940,10 +2939,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
return;
}
- dev_class = eir_data.dev_class[0] | (eir_data.dev_class[1] << 8) |
- (eir_data.dev_class[2] << 16);
- if (dev_class != 0)
- write_remote_class(&adapter->bdaddr, bdaddr, dev_class);
+ if (eir_data.class != 0)
+ write_remote_class(&adapter->bdaddr, bdaddr, eir_data.class);
if (eir_data.appearance != 0)
write_remote_appearance(&adapter->bdaddr, bdaddr, bdaddr_type,
@@ -2999,8 +2996,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
alias = read_stored_data(&adapter->bdaddr, bdaddr, bdaddr_type,
"aliases");
- dev = found_device_new(bdaddr, bdaddr_type, name, alias, dev_class,
- legacy, eir_data.flags);
+ dev = found_device_new(bdaddr, bdaddr_type, name, alias,
+ eir_data.class, legacy, eir_data.flags);
free(name);
free(alias);
diff --git a/src/eir.c b/src/eir.c
index c29be40..4b054ea 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -166,7 +166,8 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len)
case EIR_CLASS_OF_DEV:
if (data_len < 3)
break;
- memcpy(eir->dev_class, data, 3);
+ eir->class = data[0] | (data[1] << 8) |
+ (data[2] << 16);
break;
case EIR_GAP_APPEARANCE:
diff --git a/src/eir.h b/src/eir.h
index e6e870a..3a52563 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -47,7 +47,7 @@ struct eir_data {
GSList *services;
int flags;
char *name;
- uint8_t dev_class[3];
+ uint32_t class;
uint16_t appearance;
gboolean name_complete;
uint8_t *hash;
diff --git a/src/event.c b/src/event.c
index 3b85961..670b79a 100644
--- a/src/event.c
+++ b/src/event.c
@@ -453,7 +453,7 @@ int btd_event_ltk_notify(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
}
void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
- char *name, uint8_t *dev_class)
+ char *name, uint32_t class)
{
struct btd_adapter *adapter;
struct btd_device *device;
@@ -463,13 +463,8 @@ void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_typ
update_lastused(local, peer, bdaddr_type);
- if (dev_class != NULL) {
- uint32_t class = dev_class[0] | (dev_class[1] << 8) |
- (dev_class[2] << 16);
-
- if (class != 0)
- write_remote_class(local, peer, class);
- }
+ if (class != 0)
+ write_remote_class(local, peer, class);
device_set_addr_type(device, bdaddr_type);
diff --git a/src/event.h b/src/event.h
index 7031cc9..6d001dd 100644
--- a/src/event.h
+++ b/src/event.h
@@ -30,7 +30,7 @@ void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer, gboolean lega
void btd_event_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class);
void btd_event_remote_name(bdaddr_t *local, bdaddr_t *peer, char *name);
void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
- char *name, uint8_t *dev_class);
+ char *name, uint32_t class);
void btd_event_conn_failed(bdaddr_t *local, bdaddr_t *peer, uint8_t status);
void btd_event_disconn_complete(bdaddr_t *local, bdaddr_t *peer);
void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t status);
diff --git a/src/mgmt.c b/src/mgmt.c
index 3f83fdf..ee4cbbe 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -503,7 +503,7 @@ static void mgmt_device_connected(int sk, uint16_t index, void *buf, size_t len)
btd_event_conn_complete(&info->bdaddr, &ev->addr.bdaddr,
ev->addr.type,
eir_data.name,
- eir_data.dev_class);
+ eir_data.class);
eir_data_free(&eir_data);
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 04/18] eir: Add eir_parse_oob function
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (2 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 03/18] eir: Store class in struct eir_data as uint32_t Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 05/18] oob: Allow to register pairing complete callback Szymon Janc
` (13 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This will parse EIR received over OOB. Such EIR contains mandatory
and optional part.
---
src/eir.c | 25 +++++++++++++++++++++++++
src/eir.h | 2 ++
2 files changed, 27 insertions(+)
diff --git a/src/eir.c b/src/eir.c
index 4b054ea..144f65c 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -38,6 +38,8 @@
#include "glib-helper.h"
#include "eir.h"
+#define EIR_OOB_MIN (2 + 6)
+
void eir_data_free(struct eir_data *eir)
{
g_slist_free_full(eir->services, g_free);
@@ -197,6 +199,29 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len)
return 0;
}
+int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len)
+{
+
+ if (eir_len < EIR_OOB_MIN)
+ return -1;
+
+ if (eir_len != bt_get_le16(eir_data))
+ return -1;
+
+ eir_data += sizeof(uint16_t);
+ eir_len -= sizeof(uint16_t);
+
+ memcpy(&eir->addr, eir_data, sizeof(bdaddr_t));
+ eir_data += sizeof(bdaddr_t);
+ eir_len -= sizeof(bdaddr_t);
+
+ /* optional OOB EIR data */
+ if (eir_len > 0)
+ return eir_parse(eir, eir_data, eir_len);
+
+ return 0;
+}
+
#define SIZEOF_UUID128 16
static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
diff --git a/src/eir.h b/src/eir.h
index 3a52563..d2d6dc7 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -52,10 +52,12 @@ struct eir_data {
gboolean name_complete;
uint8_t *hash;
uint8_t *randomizer;
+ bdaddr_t addr;
};
void eir_data_free(struct eir_data *eir);
int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len);
+int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len);
void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
uint16_t did_product, uint16_t did_version,
uint16_t did_source, GSList *uuids, uint8_t *data);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 05/18] oob: Allow to register pairing complete callback
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (3 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 04/18] eir: Add eir_parse_oob function Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 06/18] adapter: Handle missing randomizer in btd_adapter_add_remote_oob_data Szymon Janc
` (12 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This will allow to register callback to be called when pairing is
finished.
---
plugins/dbusoob.c | 7 ++++++-
src/mgmt.c | 1 +
src/oob.c | 22 +++++++++++++++++-----
src/oob.h | 15 ++++++++++++---
4 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/plugins/dbusoob.c b/plugins/dbusoob.c
index a7259ba..a66c21d 100644
--- a/plugins/dbusoob.c
+++ b/plugins/dbusoob.c
@@ -354,13 +354,18 @@ static struct btd_adapter_driver oob_driver = {
.remove = oob_remove,
};
+static struct oob_handler dbusoob_handler = {
+ .read_local_cb = read_local_data_complete,
+ .pairing_cb = NULL,
+};
+
static int dbusoob_init(void)
{
DBG("Setup dbusoob plugin");
connection = get_dbus_connection();
- oob_register_cb(read_local_data_complete);
+ oob_register_cb(&dbusoob_handler);
return btd_register_adapter_driver(&oob_driver);
}
diff --git a/src/mgmt.c b/src/mgmt.c
index ee4cbbe..1dec839 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -1181,6 +1181,7 @@ static void pair_device_complete(int sk, uint16_t index, uint8_t status,
info = &controllers[index];
bonding_complete(info, &rp->addr.bdaddr, status);
+ oob_pairing_complete(&info->bdaddr, &rp->addr.bdaddr, status);
}
static void get_connections_complete(int sk, uint16_t index, void *buf,
diff --git a/src/oob.c b/src/oob.c
index 75798fb..73a15db 100644
--- a/src/oob.c
+++ b/src/oob.c
@@ -24,18 +24,30 @@
*/
#include "adapter.h"
+#include "manager.h"
#include "oob.h"
-static oob_read_cb_t local_oob_read_cb = NULL;
+static struct oob_handler *oob_handler = NULL;
-void oob_register_cb(oob_read_cb_t cb)
+
+void oob_register_cb(struct oob_handler *handler)
{
- local_oob_read_cb = cb;
+ oob_handler = handler;
}
void oob_read_local_data_complete(struct btd_adapter *adapter, uint8_t *hash,
uint8_t *randomizer)
{
- if (local_oob_read_cb)
- local_oob_read_cb(adapter, hash, randomizer);
+ if (oob_handler && oob_handler->read_local_cb)
+ oob_handler->read_local_cb(adapter, hash, randomizer);
+}
+
+void oob_pairing_complete(bdaddr_t *local, bdaddr_t *remote, uint8_t status)
+{
+ struct btd_adapter *adapter;
+
+ adapter = manager_find_adapter(local);
+
+ if (adapter && oob_handler && oob_handler->pairing_cb)
+ oob_handler->pairing_cb(adapter, remote, status);
}
diff --git a/src/oob.h b/src/oob.h
index 5805082..843ffdf 100644
--- a/src/oob.h
+++ b/src/oob.h
@@ -23,10 +23,19 @@
*
*/
-typedef void (*oob_read_cb_t) (struct btd_adapter *adapter, uint8_t *hash,
- uint8_t *randomizer);
+typedef void (*oob_read_local_cb_t) (struct btd_adapter *adapter,
+ uint8_t *hash, uint8_t *randomizer);
+typedef void (*oob_pairing_cb_t) (struct btd_adapter *adapter,
+ bdaddr_t *bdaddr, uint8_t status);
+
+struct oob_handler {
+ oob_read_local_cb_t read_local_cb;
+ oob_pairing_cb_t pairing_cb;
+};
-void oob_register_cb(oob_read_cb_t cb);
+void oob_register_cb(struct oob_handler *handler);
void oob_read_local_data_complete(struct btd_adapter *adapter, uint8_t *hash,
uint8_t *randomizer);
+
+void oob_pairing_complete(bdaddr_t *local, bdaddr_t *remote, uint8_t status);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 06/18] adapter: Handle missing randomizer in btd_adapter_add_remote_oob_data
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (4 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 05/18] oob: Allow to register pairing complete callback Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:17 ` Johan Hedberg
2012-09-21 10:46 ` [PATCH v2 06/18] Handle missing randomizer in mgmt_add_remote_oob_data Szymon Janc
2012-09-21 10:02 ` [PATCH 07/18] neard: Implement PushOOB function Szymon Janc
` (11 subsequent siblings)
17 siblings, 2 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Randomizer is optional. Handling missing randomizer in
btd_adapter_add_remote_oob_data is easy and will simplify caller code.
---
plugins/dbusoob.c | 7 -------
src/adapter.c | 7 +++++++
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/plugins/dbusoob.c b/plugins/dbusoob.c
index a66c21d..ce9e5d4 100644
--- a/plugins/dbusoob.c
+++ b/plugins/dbusoob.c
@@ -233,13 +233,6 @@ static gboolean store_data(struct btd_adapter *adapter, struct oob_data *data)
adapter_get_address(adapter, &local);
if (data->hash) {
- uint8_t empty_randomizer[16];
-
- if (!data->randomizer) {
- memset(empty_randomizer, 0, sizeof(empty_randomizer));
- data->randomizer = empty_randomizer;
- }
-
if (btd_adapter_add_remote_oob_data(adapter, &bdaddr,
data->hash, data->randomizer) < 0)
return FALSE;
diff --git a/src/adapter.c b/src/adapter.c
index d34e966..a00522a 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3574,6 +3574,13 @@ int btd_adapter_read_local_oob_data(struct btd_adapter *adapter)
int btd_adapter_add_remote_oob_data(struct btd_adapter *adapter,
bdaddr_t *bdaddr, uint8_t *hash, uint8_t *randomizer)
{
+ uint8_t empty_randomizer[16];
+
+ if (!randomizer) {
+ memset(empty_randomizer, 0, sizeof(empty_randomizer));
+ randomizer = empty_randomizer;
+ }
+
return mgmt_add_remote_oob_data(adapter->dev_id, bdaddr, hash,
randomizer);
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 06/18] adapter: Handle missing randomizer in btd_adapter_add_remote_oob_data
2012-09-21 10:02 ` [PATCH 06/18] adapter: Handle missing randomizer in btd_adapter_add_remote_oob_data Szymon Janc
@ 2012-09-21 10:17 ` Johan Hedberg
2012-09-21 10:42 ` Szymon Janc
2012-09-21 10:46 ` [PATCH v2 06/18] Handle missing randomizer in mgmt_add_remote_oob_data Szymon Janc
1 sibling, 1 reply; 22+ messages in thread
From: Johan Hedberg @ 2012-09-21 10:17 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Fri, Sep 21, 2012, Szymon Janc wrote:
> Randomizer is optional. Handling missing randomizer in
> btd_adapter_add_remote_oob_data is easy and will simplify caller code.
>
> ---
> plugins/dbusoob.c | 7 -------
> src/adapter.c | 7 +++++++
> 2 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/plugins/dbusoob.c b/plugins/dbusoob.c
> index a66c21d..ce9e5d4 100644
> --- a/plugins/dbusoob.c
> +++ b/plugins/dbusoob.c
> @@ -233,13 +233,6 @@ static gboolean store_data(struct btd_adapter *adapter, struct oob_data *data)
> adapter_get_address(adapter, &local);
>
> if (data->hash) {
> - uint8_t empty_randomizer[16];
> -
> - if (!data->randomizer) {
> - memset(empty_randomizer, 0, sizeof(empty_randomizer));
> - data->randomizer = empty_randomizer;
> - }
> -
> if (btd_adapter_add_remote_oob_data(adapter, &bdaddr,
> data->hash, data->randomizer) < 0)
> return FALSE;
> diff --git a/src/adapter.c b/src/adapter.c
> index d34e966..a00522a 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -3574,6 +3574,13 @@ int btd_adapter_read_local_oob_data(struct btd_adapter *adapter)
> int btd_adapter_add_remote_oob_data(struct btd_adapter *adapter,
> bdaddr_t *bdaddr, uint8_t *hash, uint8_t *randomizer)
> {
> + uint8_t empty_randomizer[16];
> +
> + if (!randomizer) {
> + memset(empty_randomizer, 0, sizeof(empty_randomizer));
> + randomizer = empty_randomizer;
> + }
> +
> return mgmt_add_remote_oob_data(adapter->dev_id, bdaddr, hash,
> randomizer);
I'd rather have mgmt_add_remote_oob_data accept a NULL pointer and have
the randomizer memcpy behind a NULL test (the code is anyway already
initializing the send buffer to zeros).
Johan
^ permalink raw reply [flat|nested] 22+ messages in thread* [PATCH v2 06/18] Handle missing randomizer in mgmt_add_remote_oob_data
2012-09-21 10:02 ` [PATCH 06/18] adapter: Handle missing randomizer in btd_adapter_add_remote_oob_data Szymon Janc
2012-09-21 10:17 ` Johan Hedberg
@ 2012-09-21 10:46 ` Szymon Janc
1 sibling, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:46 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Randomizer is optional. Handling missing randomizer in
mgmt_add_remote_oob_data is easy and will simplify caller code.
Change-Id: I049db8b417843f16cb77fc150def01b4ac922ef0
---
plugins/dbusoob.c | 7 -------
src/mgmt.c | 4 +++-
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/plugins/dbusoob.c b/plugins/dbusoob.c
index a66c21d..ce9e5d4 100644
--- a/plugins/dbusoob.c
+++ b/plugins/dbusoob.c
@@ -233,13 +233,6 @@ static gboolean store_data(struct btd_adapter *adapter, struct oob_data *data)
adapter_get_address(adapter, &local);
if (data->hash) {
- uint8_t empty_randomizer[16];
-
- if (!data->randomizer) {
- memset(empty_randomizer, 0, sizeof(empty_randomizer));
- data->randomizer = empty_randomizer;
- }
-
if (btd_adapter_add_remote_oob_data(adapter, &bdaddr,
data->hash, data->randomizer) < 0)
return FALSE;
diff --git a/src/mgmt.c b/src/mgmt.c
index 1dec839..7364360 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -2413,7 +2413,9 @@ int mgmt_add_remote_oob_data(int index, bdaddr_t *bdaddr,
bacpy(&cp->addr.bdaddr, bdaddr);
memcpy(cp->hash, hash, 16);
- memcpy(cp->randomizer, randomizer, 16);
+
+ if (randomizer)
+ memcpy(cp->randomizer, randomizer, 16);
if (write(mgmt_sock, &buf, sizeof(buf)) < 0)
return -errno;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 07/18] neard: Implement PushOOB function
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (5 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 06/18] adapter: Handle missing randomizer in btd_adapter_add_remote_oob_data Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 08/18] eir: Add support creating EIR with hash and randomizer fields Szymon Janc
` (10 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This implements PushOOB function which allows neard to pass data used
for discovery and pairing. Only EIR data type is supported.
---
plugins/neard.c | 241 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 235 insertions(+), 6 deletions(-)
diff --git a/plugins/neard.c b/plugins/neard.c
index 5f467b3..630a79b 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -36,6 +36,12 @@
#include "log.h"
#include "dbus-common.h"
#include "adapter.h"
+#include "manager.h"
+#include "device.h"
+#include "eir.h"
+#include "storage.h"
+#include "agent.h"
+#include "oob.h"
#define NEARD_NAME "org.neard"
#define NEARD_PATH "/"
@@ -50,10 +56,32 @@ static DBusPendingCall *pending = NULL;
static guint watcher_id = 0;
static gboolean agent_registered = FALSE;
-static DBusMessage *error_failed(DBusMessage *msg, int error)
+static struct btd_adapter *pending_adapter = NULL;
+static DBusMessage *pending_msg = NULL;
+
+static DBusMessage *error_reply(DBusMessage *msg, int error)
{
- return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ switch (error) {
+ case ENOTSUP:
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".NotSupported",
+ "Operation is not supported");
+
+ case ENOENT:
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".NoSuchDevice",
+ "No such device");
+
+ case EINPROGRESS:
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".InProgress",
+ "Operation already in progress");
+
+ case ENONET:
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Disabled",
+ "Device disabled");
+
+ default:
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
"%s", strerror(error));
+ }
}
static void register_agent_cb(DBusPendingCall *call, void *user_data)
@@ -128,12 +156,199 @@ unregister:
g_dbus_unregister_interface(conn, AGENT_PATH, AGENT_INTERFACE);
}
-static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg,
- void *user_data)
+static void pairing_complete(struct btd_adapter *adapter, bdaddr_t *bdaddr,
+ uint8_t status)
+{
+ DBusMessage *reply;
+ char address[18];
+
+ ba2str(bdaddr, address);
+ DBG("hci%u remote:%s", adapter_get_dev_id(adapter), address);
+
+ if (!pending_adapter || pending_adapter != adapter)
+ return;
+
+ if (status)
+ reply = error_reply(pending_msg, EIO);
+ else
+ reply = g_dbus_create_reply(pending_msg, DBUS_TYPE_INVALID);
+
+ dbus_message_unref(pending_msg);
+ pending_msg = NULL;
+ pending_adapter = NULL;
+
+ if (!g_dbus_send_message(conn, reply))
+ error("D-Bus send failed");
+}
+
+static int process_eir(struct btd_adapter *adapter, uint8_t *eir, size_t size,
+ gboolean pair)
+{
+ struct btd_device *device;
+ struct agent *agent;
+ struct eir_data eir_data;
+ bdaddr_t local;
+ char remote_address[18];
+
+ DBG("size %zu", size);
+
+ memset(&eir_data, 0, sizeof(eir_data));
+
+ if (eir_parse_oob(&eir_data, eir, size) < 0)
+ return -EINVAL;
+
+ ba2str(&eir_data.addr, remote_address);
+
+ DBG("hci%u remote:%s", adapter_get_dev_id(adapter), remote_address);
+
+ device = adapter_find_device(adapter, remote_address);
+
+ /* If already paired do nothing */
+ if (device && device_is_paired(device)) {
+ DBG("already paired");
+ eir_data_free(&eir_data);
+ return 1;
+ }
+
+ /* Pairing in progress... */
+ if (device && device_is_bonding(device, NULL)) {
+ DBG("pairing in progress");
+ eir_data_free(&eir_data);
+ return -EINPROGRESS;
+ }
+
+ /* If we have unpaired device hanging around, purge it */
+ if (device)
+ adapter_remove_device(conn, adapter, device, TRUE);
+
+ adapter_get_address(adapter, &local);
+
+ /* store OOB data */
+ if (eir_data.class != 0)
+ write_remote_class(&local, &eir_data.addr, eir_data.class);
+
+ /* TODO handle incomplete name? */
+ if (eir_data.name)
+ write_device_name(&local, &eir_data.addr, BDADDR_BREDR,
+ eir_data.name);
+
+ if (eir_data.hash)
+ btd_adapter_add_remote_oob_data(adapter, &eir_data.addr,
+ eir_data.hash, eir_data.randomizer);
+
+ /* TODO handle UUIDs? */
+
+ eir_data_free(&eir_data);
+
+ if (!pair)
+ return 1;
+
+ agent = adapter_get_agent(adapter);
+
+ return adapter_create_bonding(adapter, &eir_data.addr, BDADDR_BREDR,
+ agent_get_io_capability(agent));
+}
+
+static int process_params(DBusMessageIter *iter, struct btd_adapter *adapter,
+ gboolean pair)
{
+ DBusMessageIter dict;
+ DBusMessageIter value;
+ DBusMessageIter entry;
+ const char *key;
+ int type;
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+ return -EINVAL;
+
+ dbus_message_iter_recurse(iter, &dict);
+
+ type = dbus_message_iter_get_arg_type(&dict);
+ if (type != DBUS_TYPE_DICT_ENTRY) {
+ if (!pair && type == DBUS_TYPE_INVALID)
+ return 1;
+
+ return -EINVAL;
+ }
+
+ dbus_message_iter_recurse(&dict, &entry);
+
+ if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+ return -EINVAL;
+
+ dbus_message_iter_get_basic(&entry, &key);
+ dbus_message_iter_next(&entry);
+
+ dbus_message_iter_recurse(&entry, &value);
+
+ /* All keys have byte array type values */
+ if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_ARRAY)
+ return -EINVAL;
+
+ if (strcasecmp(key, "EIR") == 0) {
+ DBusMessageIter array;
+ uint8_t *eir;
+ int size;
+
+ dbus_message_iter_recurse(&value, &array);
+ dbus_message_iter_get_fixed_array(&array, &eir, &size);
+
+ return process_eir(adapter, eir, size, TRUE);
+ } else if (strcasecmp(key, "nokia.com:bt") == 0) {
+ /* TODO add support for Nokia BT 2.0 proprietary stuff */
+ return -ENOTSUP;
+ }
+
+ return -EINVAL;
+}
+
+static int check_adapter(struct btd_adapter *adapter)
+{
+ gboolean pairable;
+
+ if (pending_adapter)
+ return -EINPROGRESS;
+
+ if (!adapter)
+ return -ENOENT;
+
+ btd_adapter_get_mode(adapter, NULL, NULL, NULL, &pairable);
+
+ if (!pairable || !adapter_get_agent(adapter))
+ return -ENOENT;
+
+ if (!btd_adapter_ssp_enabled(adapter))
+ return -ENOTSUP;
+
+ return 0;
+}
+
+static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+ struct btd_adapter *adapter;
+ DBusMessageIter iter;
+ int ret;
+
DBG("");
- return error_failed(msg, ENOTSUP);
+ adapter = manager_get_default_adapter();
+ ret = check_adapter(adapter);
+ if (ret < 0)
+ return error_reply(msg, -ret);
+
+ dbus_message_iter_init(msg, &iter);
+
+ ret = process_params(&iter, adapter, TRUE);
+ if (ret < 0)
+ return error_reply(msg, -ret);
+
+ /* already paired, reply immediately */
+ if (ret > 0)
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+
+ pending_adapter = adapter;
+ pending_msg = dbus_message_ref(msg);
+ return NULL;
}
static DBusMessage *request_oob(DBusConnection *conn, DBusMessage *msg,
@@ -141,7 +356,7 @@ static DBusMessage *request_oob(DBusConnection *conn, DBusMessage *msg,
{
DBG("");
- return error_failed(msg, ENOTSUP);
+ return error_reply(msg, ENOTSUP);
}
static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,
@@ -194,8 +409,20 @@ static void neard_vanished(DBusConnection *conn, void *user_data)
g_dbus_unregister_interface(conn, AGENT_PATH, AGENT_INTERFACE);
agent_registered = FALSE;
}
+
+ if (pending_msg) {
+ dbus_message_unref(pending_msg);
+ pending_msg = NULL;
+ }
+
+ pending_adapter = NULL;
}
+static struct oob_handler neard_handler = {
+ .read_local_cb = NULL,
+ .pairing_cb = pairing_complete,
+};
+
static int neard_init(void)
{
DBG("Setup neard plugin");
@@ -208,6 +435,8 @@ static int neard_init(void)
if (watcher_id == 0)
return -ENOMEM;
+ oob_register_cb(&neard_handler);
+
return 0;
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 08/18] eir: Add support creating EIR with hash and randomizer fields
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (6 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 07/18] neard: Implement PushOOB function Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 09/18] eir: Add support for creating EIR with CoD field Szymon Janc
` (9 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This will be used to create EIR to be send over OOB channel.
---
src/eir.c | 28 +++++++++++++++++++++++++---
src/eir.h | 8 +++++---
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/src/eir.c b/src/eir.c
index 144f65c..0ef18e2 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -280,9 +280,11 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
}
}
-void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
- uint16_t did_product, uint16_t did_version,
- uint16_t did_source, GSList *uuids, uint8_t *data)
+void eir_create(const char *name, int8_t tx_power,
+ uint8_t *hash, uint8_t *randomizer,
+ uint16_t did_vendor, uint16_t did_product,
+ uint16_t did_version, uint16_t did_source,
+ GSList *uuids, uint8_t *data)
{
GSList *l;
uint8_t *ptr = data;
@@ -292,6 +294,26 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
gboolean truncated = FALSE;
size_t name_len;
+ if (hash) {
+ *ptr++ = 17;
+ *ptr++ = EIR_SSP_HASH;
+
+ memcpy(ptr, hash, 16);
+ ptr += 16;
+
+ eir_len += 16 + 2;
+ }
+
+ if (randomizer) {
+ *ptr++ = 17;
+ *ptr++ = EIR_SSP_RANDOMIZER;
+
+ memcpy(ptr, randomizer, 16);
+ ptr += 16;
+
+ eir_len += 16 + 2;
+ }
+
name_len = strlen(name);
if (name_len > 0) {
diff --git a/src/eir.h b/src/eir.h
index d2d6dc7..844c162 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -58,9 +58,11 @@ struct eir_data {
void eir_data_free(struct eir_data *eir);
int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len);
int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len);
-void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
- uint16_t did_product, uint16_t did_version,
- uint16_t did_source, GSList *uuids, uint8_t *data);
+void eir_create(const char *name, int8_t tx_power,
+ uint8_t *hash, uint8_t *randomizer,
+ uint16_t did_vendor, uint16_t did_product,
+ uint16_t did_version, uint16_t did_source,
+ GSList *uuids, uint8_t *data);
gboolean eir_has_data_type(uint8_t *data, size_t len, uint8_t type);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 09/18] eir: Add support for creating EIR with CoD field
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (7 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 08/18] eir: Add support creating EIR with hash and randomizer fields Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 10/18] eir: Rename eir_create to eir_create_oob Szymon Janc
` (8 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This will be used to create EIR to be send over OOB channel.
---
src/eir.c | 18 +++++++++++++++++-
src/eir.h | 2 +-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/eir.c b/src/eir.c
index 0ef18e2..46dde5a 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -280,7 +280,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
}
}
-void eir_create(const char *name, int8_t tx_power,
+void eir_create(const char *name, int8_t tx_power, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
@@ -294,6 +294,22 @@ void eir_create(const char *name, int8_t tx_power,
gboolean truncated = FALSE;
size_t name_len;
+ if (cod > 0) {
+ uint8_t class[3];
+
+ class[0] = (uint8_t) cod;
+ class[1] = (uint8_t) (cod >> 8);
+ class[2] = (uint8_t) (cod >> 16);
+
+ *ptr++ = 4;
+ *ptr++ = EIR_CLASS_OF_DEV;
+
+ memcpy(ptr, class, sizeof(class));
+ ptr += sizeof(class);
+
+ eir_len += sizeof(class) + 2;
+ }
+
if (hash) {
*ptr++ = 17;
*ptr++ = EIR_SSP_HASH;
diff --git a/src/eir.h b/src/eir.h
index 844c162..1c7a603 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -58,7 +58,7 @@ struct eir_data {
void eir_data_free(struct eir_data *eir);
int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len);
int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len);
-void eir_create(const char *name, int8_t tx_power,
+void eir_create(const char *name, int8_t tx_power, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 10/18] eir: Rename eir_create to eir_create_oob
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (8 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 09/18] eir: Add support for creating EIR with CoD field Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 11/18] eir: Remove support for creating EIR with tx_power fields Szymon Janc
` (7 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
With mgmt interface EIR is created by kernel. Renaming this function
makes it clear what is a purpose of it in userspace. It also contains
support for EIR data types that shall be transmitted only over OOB
channel.
---
src/eir.c | 2 +-
src/eir.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/eir.c b/src/eir.c
index 46dde5a..a3c99e8 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -280,7 +280,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
}
}
-void eir_create(const char *name, int8_t tx_power, uint32_t cod,
+void eir_create_oob(const char *name, int8_t tx_power, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
diff --git a/src/eir.h b/src/eir.h
index 1c7a603..55289f9 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -58,7 +58,7 @@ struct eir_data {
void eir_data_free(struct eir_data *eir);
int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len);
int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len);
-void eir_create(const char *name, int8_t tx_power, uint32_t cod,
+void eir_create_oob(const char *name, int8_t tx_power, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 11/18] eir: Remove support for creating EIR with tx_power fields
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (9 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 10/18] eir: Rename eir_create to eir_create_oob Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 12/18] eir: Return number of bytes written by eir_create_oob Szymon Janc
` (6 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This field is not used for OOB EIR.
---
src/eir.c | 9 +--------
src/eir.h | 2 +-
2 files changed, 2 insertions(+), 9 deletions(-)
diff --git a/src/eir.c b/src/eir.c
index a3c99e8..c67cf6f 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -280,7 +280,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
}
}
-void eir_create_oob(const char *name, int8_t tx_power, uint32_t cod,
+void eir_create_oob(const char *name, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
@@ -349,13 +349,6 @@ void eir_create_oob(const char *name, int8_t tx_power, uint32_t cod,
ptr += (name_len + 2);
}
- if (tx_power != 0) {
- *ptr++ = 2;
- *ptr++ = EIR_TX_POWER;
- *ptr++ = (uint8_t) tx_power;
- eir_len += 3;
- }
-
if (did_vendor != 0x0000) {
*ptr++ = 9;
*ptr++ = EIR_DEVICE_ID;
diff --git a/src/eir.h b/src/eir.h
index 55289f9..d5c4afc 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -58,7 +58,7 @@ struct eir_data {
void eir_data_free(struct eir_data *eir);
int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len);
int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len);
-void eir_create_oob(const char *name, int8_t tx_power, uint32_t cod,
+void eir_create_oob(const char *name, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 12/18] eir: Return number of bytes written by eir_create_oob
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (10 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 11/18] eir: Remove support for creating EIR with tx_power fields Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 13/18] eir: Remove struct uuid_info Szymon Janc
` (5 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In OOB EIR is not zero padded.
---
src/eir.c | 4 +++-
src/eir.h | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/eir.c b/src/eir.c
index c67cf6f..598c0e4 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -280,7 +280,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
}
}
-void eir_create_oob(const char *name, uint32_t cod,
+int eir_create_oob(const char *name, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
@@ -412,6 +412,8 @@ void eir_create_oob(const char *name, uint32_t cod,
/* Group all UUID128 types */
if (eir_len <= HCI_MAX_EIR_LENGTH - 2)
eir_generate_uuid128(uuids, ptr, &eir_len);
+
+ return eir_len;
}
gboolean eir_has_data_type(uint8_t *data, size_t len, uint8_t type)
diff --git a/src/eir.h b/src/eir.h
index d5c4afc..036172e 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -58,7 +58,7 @@ struct eir_data {
void eir_data_free(struct eir_data *eir);
int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len);
int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len);
-void eir_create_oob(const char *name, uint32_t cod,
+int eir_create_oob(const char *name, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 13/18] eir: Remove struct uuid_info
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (11 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 12/18] eir: Return number of bytes written by eir_create_oob Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 14/18] eir: Add support for creating proper OOB EIR Szymon Janc
` (4 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Remove struct uuid_info and convert functions to use sdp_record_t
list instead. This will allow to easily use services list from
struct btd_adapter to create EIR.
---
src/eir.c | 29 ++++++++++++++++-------------
src/eir.h | 7 +------
2 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/src/eir.c b/src/eir.c
index 598c0e4..78ae070 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -224,7 +224,8 @@ int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len)
#define SIZEOF_UUID128 16
-static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
+static void eir_generate_uuid128(sdp_list_t *list, uint8_t *ptr,
+ uint16_t *eir_len)
{
int i, k, uuid_count = 0;
uint16_t len = *eir_len;
@@ -235,10 +236,11 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
uuid128 = ptr + 2;
for (; list; list = list->next) {
- struct uuid_info *uuid = list->data;
- uint8_t *uuid128_data = uuid->uuid.value.uuid128.data;
+ sdp_record_t *rec = list->data;
+ uuid_t *uuid = &rec->svclass;
+ uint8_t *uuid128_data = uuid->value.uuid128.data;
- if (uuid->uuid.type != SDP_UUID128)
+ if (uuid->type != SDP_UUID128)
continue;
/* Stop if not enough space to put next UUID128 */
@@ -284,9 +286,9 @@ int eir_create_oob(const char *name, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
- GSList *uuids, uint8_t *data)
+ sdp_list_t *uuids, uint8_t *data)
{
- GSList *l;
+ sdp_list_t *l;
uint8_t *ptr = data;
uint16_t eir_len = 0;
uint16_t uuid16[HCI_MAX_EIR_LENGTH / 2];
@@ -364,16 +366,17 @@ int eir_create_oob(const char *name, uint32_t cod,
}
/* Group all UUID16 types */
- for (l = uuids; l != NULL; l = g_slist_next(l)) {
- struct uuid_info *uuid = l->data;
+ for (l = uuids; l != NULL; l = l->next) {
+ sdp_record_t *rec = l->data;
+ uuid_t *uuid = &rec->svclass;
- if (uuid->uuid.type != SDP_UUID16)
+ if (uuid->type != SDP_UUID16)
continue;
- if (uuid->uuid.value.uuid16 < 0x1100)
+ if (uuid->value.uuid16 < 0x1100)
continue;
- if (uuid->uuid.value.uuid16 == PNP_INFO_SVCLASS_ID)
+ if (uuid->value.uuid16 == PNP_INFO_SVCLASS_ID)
continue;
/* Stop if not enough space to put next UUID16 */
@@ -384,13 +387,13 @@ int eir_create_oob(const char *name, uint32_t cod,
/* Check for duplicates */
for (i = 0; i < uuid_count; i++)
- if (uuid16[i] == uuid->uuid.value.uuid16)
+ if (uuid16[i] == uuid->value.uuid16)
break;
if (i < uuid_count)
continue;
- uuid16[uuid_count++] = uuid->uuid.value.uuid16;
+ uuid16[uuid_count++] = uuid->value.uuid16;
eir_len += sizeof(uint16_t);
}
diff --git a/src/eir.h b/src/eir.h
index 036172e..0755da5 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -38,11 +38,6 @@
#define EIR_DEVICE_ID 0x10 /* device ID */
#define EIR_GAP_APPEARANCE 0x19 /* GAP appearance */
-struct uuid_info {
- uuid_t uuid;
- uint8_t svc_hint;
-};
-
struct eir_data {
GSList *services;
int flags;
@@ -62,7 +57,7 @@ int eir_create_oob(const char *name, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
- GSList *uuids, uint8_t *data);
+ sdp_list_t *uuids, uint8_t *data);
gboolean eir_has_data_type(uint8_t *data, size_t len, uint8_t type);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 14/18] eir: Add support for creating proper OOB EIR
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (12 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 13/18] eir: Remove struct uuid_info Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 15/18] adapter: Add btd_adapter_get_services function Szymon Janc
` (3 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Address and total length field are mandatory part of OOB EIR.
---
src/eir.c | 39 ++++++++++++++++++++++++++-------------
src/eir.h | 2 +-
2 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/src/eir.c b/src/eir.c
index 78ae070..05b3723 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -282,7 +282,7 @@ static void eir_generate_uuid128(sdp_list_t *list, uint8_t *ptr,
}
}
-int eir_create_oob(const char *name, uint32_t cod,
+int eir_create_oob(bdaddr_t *addr, const char *name, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
@@ -290,12 +290,19 @@ int eir_create_oob(const char *name, uint32_t cod,
{
sdp_list_t *l;
uint8_t *ptr = data;
- uint16_t eir_len = 0;
+ uint16_t eir_optional_len = 0;
+ uint16_t eir_total_len;
uint16_t uuid16[HCI_MAX_EIR_LENGTH / 2];
int i, uuid_count = 0;
gboolean truncated = FALSE;
size_t name_len;
+ eir_total_len = sizeof(uint16_t) + sizeof(bdaddr_t);
+ ptr += sizeof(uint16_t);
+
+ memcpy(ptr, addr, sizeof(bdaddr_t));
+ ptr += sizeof(bdaddr_t);
+
if (cod > 0) {
uint8_t class[3];
@@ -309,7 +316,7 @@ int eir_create_oob(const char *name, uint32_t cod,
memcpy(ptr, class, sizeof(class));
ptr += sizeof(class);
- eir_len += sizeof(class) + 2;
+ eir_optional_len += sizeof(class) + 2;
}
if (hash) {
@@ -319,7 +326,7 @@ int eir_create_oob(const char *name, uint32_t cod,
memcpy(ptr, hash, 16);
ptr += 16;
- eir_len += 16 + 2;
+ eir_optional_len += 16 + 2;
}
if (randomizer) {
@@ -329,7 +336,7 @@ int eir_create_oob(const char *name, uint32_t cod,
memcpy(ptr, randomizer, 16);
ptr += 16;
- eir_len += 16 + 2;
+ eir_optional_len += 16 + 2;
}
name_len = strlen(name);
@@ -347,7 +354,7 @@ int eir_create_oob(const char *name, uint32_t cod,
memcpy(ptr + 2, name, name_len);
- eir_len += (name_len + 2);
+ eir_optional_len += (name_len + 2);
ptr += (name_len + 2);
}
@@ -362,7 +369,7 @@ int eir_create_oob(const char *name, uint32_t cod,
*ptr++ = (did_product & 0xff00) >> 8;
*ptr++ = (did_version & 0x00ff);
*ptr++ = (did_version & 0xff00) >> 8;
- eir_len += 10;
+ eir_optional_len += 10;
}
/* Group all UUID16 types */
@@ -380,7 +387,8 @@ int eir_create_oob(const char *name, uint32_t cod,
continue;
/* Stop if not enough space to put next UUID16 */
- if ((eir_len + 2 + sizeof(uint16_t)) > HCI_MAX_EIR_LENGTH) {
+ if ((eir_optional_len + 2 + sizeof(uint16_t)) >
+ HCI_MAX_EIR_LENGTH) {
truncated = TRUE;
break;
}
@@ -394,7 +402,7 @@ int eir_create_oob(const char *name, uint32_t cod,
continue;
uuid16[uuid_count++] = uuid->value.uuid16;
- eir_len += sizeof(uint16_t);
+ eir_optional_len += sizeof(uint16_t);
}
if (uuid_count > 0) {
@@ -404,7 +412,7 @@ int eir_create_oob(const char *name, uint32_t cod,
ptr[1] = truncated ? EIR_UUID16_SOME : EIR_UUID16_ALL;
ptr += 2;
- eir_len += 2;
+ eir_optional_len += 2;
for (i = 0; i < uuid_count; i++) {
*ptr++ = (uuid16[i] & 0x00ff);
@@ -413,10 +421,15 @@ int eir_create_oob(const char *name, uint32_t cod,
}
/* Group all UUID128 types */
- if (eir_len <= HCI_MAX_EIR_LENGTH - 2)
- eir_generate_uuid128(uuids, ptr, &eir_len);
+ if (eir_optional_len <= HCI_MAX_EIR_LENGTH - 2)
+ eir_generate_uuid128(uuids, ptr, &eir_optional_len);
- return eir_len;
+ eir_total_len += eir_optional_len;
+
+ /* store total length */
+ bt_put_le16(eir_total_len, data);
+
+ return eir_total_len;
}
gboolean eir_has_data_type(uint8_t *data, size_t len, uint8_t type)
diff --git a/src/eir.h b/src/eir.h
index 0755da5..d8c5e32 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -53,7 +53,7 @@ struct eir_data {
void eir_data_free(struct eir_data *eir);
int eir_parse(struct eir_data *eir, 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 char *name, uint32_t cod,
+int eir_create_oob(bdaddr_t *addr, const char *name, uint32_t cod,
uint8_t *hash, uint8_t *randomizer,
uint16_t did_vendor, uint16_t did_product,
uint16_t did_version, uint16_t did_source,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 15/18] adapter: Add btd_adapter_get_services function
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (13 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 14/18] eir: Add support for creating proper OOB EIR Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 16/18] adapter: Rename btd_adapter_get_class to btd_adapter_read_class Szymon Janc
` (2 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Services will be used to create EIR to be send over OOB.
---
src/adapter.c | 5 +++++
src/adapter.h | 1 +
2 files changed, 6 insertions(+)
diff --git a/src/adapter.c b/src/adapter.c
index a00522a..f744456 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1003,6 +1003,11 @@ struct btd_device *adapter_get_device(DBusConnection *conn,
BDADDR_BREDR);
}
+sdp_list_t *btd_adapter_get_services(struct btd_adapter *adapter)
+{
+ return adapter->services;
+}
+
static gboolean discovery_cb(gpointer user_data)
{
struct btd_adapter *adapter = user_data;
diff --git a/src/adapter.h b/src/adapter.h
index cd37b15..2f10659 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -89,6 +89,7 @@ void btd_adapter_get_class(struct btd_adapter *adapter, uint8_t *major,
const char *btd_adapter_get_name(struct btd_adapter *adapter);
struct btd_device *adapter_get_device(DBusConnection *conn,
struct btd_adapter *adapter, const char *address);
+sdp_list_t *btd_adapter_get_services(struct btd_adapter *adapter);
struct btd_device *adapter_find_device(struct btd_adapter *adapter, const char *dest);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 16/18] adapter: Rename btd_adapter_get_class to btd_adapter_read_class
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (14 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 15/18] adapter: Add btd_adapter_get_services function Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 17/18] adapter: Add btd_adapter_get_class function Szymon Janc
2012-09-21 10:02 ` [PATCH 18/18] neard: Implement RequestOOB function Szymon Janc
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
It better suits what this function really does.
---
src/adapter.c | 2 +-
src/adapter.h | 2 +-
src/mgmt.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index f744456..23ecca5 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2186,7 +2186,7 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
*pairable = adapter->pairable;
}
-void btd_adapter_get_class(struct btd_adapter *adapter, uint8_t *major,
+void btd_adapter_read_class(struct btd_adapter *adapter, uint8_t *major,
uint8_t *minor)
{
uint8_t cls[3];
diff --git a/src/adapter.h b/src/adapter.h
index 2f10659..b9142a0 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -84,7 +84,7 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
uint16_t *discoverable_timeout,
gboolean *pairable);
-void btd_adapter_get_class(struct btd_adapter *adapter, uint8_t *major,
+void btd_adapter_read_class(struct btd_adapter *adapter, uint8_t *major,
uint8_t *minor);
const char *btd_adapter_get_name(struct btd_adapter *adapter);
struct btd_device *adapter_get_device(DBusConnection *conn,
diff --git a/src/mgmt.c b/src/mgmt.c
index 1dec839..b2d39ad 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -1104,7 +1104,7 @@ static void read_info_complete(int sk, uint16_t index, void *buf, size_t len)
else
adapter_name_changed(adapter, (char *) rp->name);
- btd_adapter_get_class(adapter, &major, &minor);
+ btd_adapter_read_class(adapter, &major, &minor);
mgmt_set_dev_class(index, major, minor);
btd_adapter_get_mode(adapter, &mode, NULL, NULL, NULL);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 17/18] adapter: Add btd_adapter_get_class function
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (15 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 16/18] adapter: Rename btd_adapter_get_class to btd_adapter_read_class Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
2012-09-21 10:02 ` [PATCH 18/18] neard: Implement RequestOOB function Szymon Janc
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This is a simple getter to get current Class Of Device of adapter.
---
src/adapter.c | 5 +++++
src/adapter.h | 2 ++
2 files changed, 7 insertions(+)
diff --git a/src/adapter.c b/src/adapter.c
index 23ecca5..d0e9e53 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2200,6 +2200,11 @@ void btd_adapter_read_class(struct btd_adapter *adapter, uint8_t *major,
*minor = cls[0];
}
+uint32_t btd_adapter_get_class(struct btd_adapter *adapter)
+{
+ return adapter->dev_class;
+}
+
const char *btd_adapter_get_name(struct btd_adapter *adapter)
{
return adapter->name;
diff --git a/src/adapter.h b/src/adapter.h
index b9142a0..2afdd31 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -86,6 +86,8 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
void btd_adapter_read_class(struct btd_adapter *adapter, uint8_t *major,
uint8_t *minor);
+
+uint32_t btd_adapter_get_class(struct btd_adapter *adapter);
const char *btd_adapter_get_name(struct btd_adapter *adapter);
struct btd_device *adapter_get_device(DBusConnection *conn,
struct btd_adapter *adapter, const char *address);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 18/18] neard: Implement RequestOOB function
2012-09-21 10:02 [PATCH 00/18] neard plugin Szymon Janc
` (16 preceding siblings ...)
2012-09-21 10:02 ` [PATCH 17/18] adapter: Add btd_adapter_get_class function Szymon Janc
@ 2012-09-21 10:02 ` Szymon Janc
17 siblings, 0 replies; 22+ messages in thread
From: Szymon Janc @ 2012-09-21 10:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This function is used by neard to request data to be transmitted over
OOB channel. It also allows neard to provide data to be used in OOB
pairing without initializing pairing it self.
---
plugins/neard.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 82 insertions(+), 3 deletions(-)
diff --git a/plugins/neard.c b/plugins/neard.c
index 630a79b..1b0e029 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -42,6 +42,7 @@
#include "storage.h"
#include "agent.h"
#include "oob.h"
+#include "hcid.h"
#define NEARD_NAME "org.neard"
#define NEARD_PATH "/"
@@ -59,6 +60,9 @@ static gboolean agent_registered = FALSE;
static struct btd_adapter *pending_adapter = NULL;
static DBusMessage *pending_msg = NULL;
+/* For NFC mimetype limits max OOB EIR size */
+#define NFC_OOB_EIR_MAX UINT8_MAX
+
static DBusMessage *error_reply(DBusMessage *msg, int error)
{
switch (error) {
@@ -156,6 +160,60 @@ unregister:
g_dbus_unregister_interface(conn, AGENT_PATH, AGENT_INTERFACE);
}
+static void read_local_complete(struct btd_adapter *adapter, uint8_t *hash,
+ uint8_t *randomizer)
+{
+ DBusMessage *reply;
+
+ DBG("hci%u", adapter_get_dev_id(adapter));
+
+ if (pending_adapter != adapter)
+ return;
+
+ if (hash && randomizer) {
+ int len;
+ uint8_t eir[NFC_OOB_EIR_MAX];
+ uint8_t *peir = eir;
+ bdaddr_t addr;
+ DBusMessageIter iter;
+ DBusMessageIter dict;
+
+ adapter_get_address(adapter, &addr);
+
+ len = eir_create_oob(&addr, btd_adapter_get_name(adapter),
+ btd_adapter_get_class(adapter), hash,
+ randomizer, main_opts.did_vendor,
+ main_opts.did_product, main_opts.did_version,
+ main_opts.did_source,
+ btd_adapter_get_services(adapter), eir);
+
+ reply = dbus_message_new_method_return(pending_msg);
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+ DBUS_TYPE_STRING_AS_STRING
+ DBUS_TYPE_VARIANT_AS_STRING
+ DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+ &dict);
+
+ dict_append_array(&dict, "EIR", DBUS_TYPE_BYTE, &peir, len);
+
+ dbus_message_iter_close_container(&iter, &dict);
+
+ } else {
+ reply = error_reply(pending_msg, EIO);
+ }
+
+ dbus_message_unref(pending_msg);
+ pending_msg = NULL;
+ pending_adapter = NULL;
+
+ if (!g_dbus_send_message(conn, reply))
+ error("D-Bus send failed");
+}
+
static void pairing_complete(struct btd_adapter *adapter, bdaddr_t *bdaddr,
uint8_t status)
{
@@ -293,7 +351,7 @@ static int process_params(DBusMessageIter *iter, struct btd_adapter *adapter,
dbus_message_iter_recurse(&value, &array);
dbus_message_iter_get_fixed_array(&array, &eir, &size);
- return process_eir(adapter, eir, size, TRUE);
+ return process_eir(adapter, eir, size, pair);
} else if (strcasecmp(key, "nokia.com:bt") == 0) {
/* TODO add support for Nokia BT 2.0 proprietary stuff */
return -ENOTSUP;
@@ -354,9 +412,30 @@ static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg, void *data)
static DBusMessage *request_oob(DBusConnection *conn, DBusMessage *msg,
void *data)
{
+ struct btd_adapter *adapter;
+ DBusMessageIter iter;
+ int ret;
+
DBG("");
- return error_reply(msg, ENOTSUP);
+ adapter = manager_get_default_adapter();
+ ret = check_adapter(adapter);
+ if (ret < 0)
+ return error_reply(msg, -ret);
+
+ dbus_message_iter_init(msg, &iter);
+
+ ret = process_params(&iter, adapter, FALSE);
+ if (ret < 0)
+ return error_reply(msg, -ret);
+
+ ret = btd_adapter_read_local_oob_data(adapter);
+ if (ret < 0)
+ return error_reply(msg, -ret);
+
+ pending_adapter = adapter;
+ pending_msg = dbus_message_ref(msg);
+ return NULL;
}
static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,
@@ -419,7 +498,7 @@ static void neard_vanished(DBusConnection *conn, void *user_data)
}
static struct oob_handler neard_handler = {
- .read_local_cb = NULL,
+ .read_local_cb = read_local_complete,
.pairing_cb = pairing_complete,
};
--
1.7.9.5
^ permalink raw reply related [flat|nested] 22+ messages in thread