* [PATCH v3 00/18] neard plugin
@ 2012-09-21 12:36 Szymon Janc
2012-09-21 12:36 ` [PATCH v3 01/18] Add initial neard plugin implementation Szymon Janc
` (17 more replies)
0 siblings, 18 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Changes since previous version:
- handle empty randomizer in mgmt_add_remote_oob_data as suggested by Johan
- rebased against latest changes related to D-Bus connection
- remove not needed static pending call pointer
Szymon Janc (18):
Add initial neard plugin implementation
eir: Add support for parsing SSP hash and randomizer
eir: Store class in struct eir_data as uint32_t
eir: Add eir_parse_oob function
oob: Allow to register pairing complete callback
Handle missing randomizer in mgmt_add_remote_oob_data
neard: Implement PushOOB function
eir: Add support creating EIR with hash and randomizer fields
eir: Add support for creating EIR with CoD field
eir: Rename eir_create to eir_create_oob
eir: Remove support for creating EIR with tx_power fields
eir: Return number of bytes written by eir_create_oob
eir: Remove struct uuid_info
eir: Add support for creating proper OOB EIR
adapter: Add btd_adapter_get_services function
adapter: Rename btd_adapter_get_class to btd_adapter_read_class
adapter: Add btd_adapter_get_class function
neard: Implement RequestOOB function
Makefile.am | 11 +-
acinclude.m4 | 19 +-
bootstrap-configure | 3 +-
plugins/dbusoob.c | 14 +-
plugins/neard.c | 527 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/adapter.c | 23 ++-
src/adapter.h | 5 +-
src/eir.c | 155 ++++++++++++---
src/eir.h | 21 +-
src/event.c | 11 +-
src/event.h | 2 +-
src/mgmt.c | 9 +-
src/oob.c | 22 ++-
src/oob.h | 15 +-
14 files changed, 750 insertions(+), 87 deletions(-)
create mode 100644 plugins/neard.c
--
1.7.9.5
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v3 01/18] Add initial neard plugin implementation
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 02/18] eir: Add support for parsing SSP hash and randomizer Szymon Janc
` (16 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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 | 219 +++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 242 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..3f8d054
--- /dev/null
+++ b/plugins/neard.c
@@ -0,0 +1,219 @@
+/*
+ *
+ * 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 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 *reply;
+ DBusError err;
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&err);
+ if (dbus_set_error_from_message(&err, reply)) {
+ error("neard manager replied with an error: %s, %s",
+ err.name, err.message);
+ dbus_error_free(&err);
+ dbus_message_unref(reply);
+
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ AGENT_PATH, AGENT_INTERFACE);
+ return;
+ }
+
+ dbus_message_unref(reply);
+ agent_registered = TRUE;
+}
+
+static void register_agent(void)
+{
+ DBusMessage *message;
+ DBusPendingCall *call;
+ 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(btd_get_dbus_connection(),
+ message, &call, -1)) {
+ error("D-Bus send failed");
+ return;
+ }
+
+ dbus_pending_call_set_notify(call, register_agent_cb, NULL, NULL);
+ dbus_pending_call_unref(call);
+}
+
+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(btd_get_dbus_connection(), message))
+ error("D-Bus send failed");
+
+unregister:
+ g_dbus_unregister_interface(btd_get_dbus_connection(), 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("");
+
+ /* 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");
+
+ watcher_id = g_dbus_add_service_watch(btd_get_dbus_connection(),
+ 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(btd_get_dbus_connection(), 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] 25+ messages in thread
* [PATCH v3 02/18] eir: Add support for parsing SSP hash and randomizer
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
2012-09-21 12:36 ` [PATCH v3 01/18] Add initial neard plugin implementation Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-24 8:08 ` Johan Hedberg
2012-09-21 12:36 ` [PATCH v3 03/18] eir: Store class in struct eir_data as uint32_t Szymon Janc
` (15 subsequent siblings)
17 siblings, 1 reply; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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] 25+ messages in thread
* [PATCH v3 03/18] eir: Store class in struct eir_data as uint32_t
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
2012-09-21 12:36 ` [PATCH v3 01/18] Add initial neard plugin implementation Szymon Janc
2012-09-21 12:36 ` [PATCH v3 02/18] eir: Add support for parsing SSP hash and randomizer Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 04/18] eir: Add eir_parse_oob function Szymon Janc
` (14 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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 f9acbd5..6d2ca69 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2914,7 +2914,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;
@@ -2925,10 +2924,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,
@@ -2984,8 +2981,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 1db73be..9626053 100644
--- a/src/event.c
+++ b/src/event.c
@@ -452,7 +452,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;
@@ -462,13 +462,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 dbd9786..9d78ce1 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -515,7 +515,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] 25+ messages in thread
* [PATCH v3 04/18] eir: Add eir_parse_oob function
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (2 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 03/18] eir: Store class in struct eir_data as uint32_t Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 05/18] oob: Allow to register pairing complete callback Szymon Janc
` (13 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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] 25+ messages in thread
* [PATCH v3 05/18] oob: Allow to register pairing complete callback
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (3 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 04/18] eir: Add eir_parse_oob function Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-24 9:06 ` Johan Hedberg
2012-09-21 12:36 ` [PATCH v3 06/18] Handle missing randomizer in mgmt_add_remote_oob_data Szymon Janc
` (12 subsequent siblings)
17 siblings, 1 reply; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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 543b272..b49e68d 100644
--- a/plugins/dbusoob.c
+++ b/plugins/dbusoob.c
@@ -355,11 +355,16 @@ 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");
- 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 9d78ce1..2accf24 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -1193,6 +1193,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] 25+ messages in thread
* [PATCH v3 06/18] Handle missing randomizer in mgmt_add_remote_oob_data
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (4 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 05/18] oob: Allow to register pairing complete callback Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 07/18] neard: Implement PushOOB function Szymon Janc
` (11 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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.
---
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 b49e68d..ba04830 100644
--- a/plugins/dbusoob.c
+++ b/plugins/dbusoob.c
@@ -232,13 +232,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 2accf24..a3f31dd 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -2425,7 +2425,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] 25+ messages in thread
* [PATCH v3 07/18] neard: Implement PushOOB function
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (5 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 06/18] Handle missing randomizer in mgmt_add_remote_oob_data Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-24 9:09 ` Johan Hedberg
2012-09-21 12:36 ` [PATCH v3 08/18] eir: Add support creating EIR with hash and randomizer fields Szymon Janc
` (10 subsequent siblings)
17 siblings, 1 reply; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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 3f8d054..dd6a422 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 "/"
@@ -47,10 +53,32 @@
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:
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(btd_get_dbus_connection(), 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(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,
@@ -189,8 +404,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");
@@ -201,6 +428,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] 25+ messages in thread
* [PATCH v3 08/18] eir: Add support creating EIR with hash and randomizer fields
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (6 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 07/18] neard: Implement PushOOB function Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 09/18] eir: Add support for creating EIR with CoD field Szymon Janc
` (9 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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] 25+ messages in thread
* [PATCH v3 09/18] eir: Add support for creating EIR with CoD field
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (7 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 08/18] eir: Add support creating EIR with hash and randomizer fields Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 10/18] eir: Rename eir_create to eir_create_oob Szymon Janc
` (8 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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] 25+ messages in thread
* [PATCH v3 10/18] eir: Rename eir_create to eir_create_oob
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (8 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 09/18] eir: Add support for creating EIR with CoD field Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 11/18] eir: Remove support for creating EIR with tx_power fields Szymon Janc
` (7 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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] 25+ messages in thread
* [PATCH v3 11/18] eir: Remove support for creating EIR with tx_power fields
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (9 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 10/18] eir: Rename eir_create to eir_create_oob Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 12/18] eir: Return number of bytes written by eir_create_oob Szymon Janc
` (6 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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] 25+ messages in thread
* [PATCH v3 12/18] eir: Return number of bytes written by eir_create_oob
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (10 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 11/18] eir: Remove support for creating EIR with tx_power fields Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 13/18] eir: Remove struct uuid_info Szymon Janc
` (5 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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] 25+ messages in thread
* [PATCH v3 13/18] eir: Remove struct uuid_info
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (11 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 12/18] eir: Return number of bytes written by eir_create_oob Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 14/18] eir: Add support for creating proper OOB EIR Szymon Janc
` (4 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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] 25+ messages in thread
* [PATCH v3 14/18] eir: Add support for creating proper OOB EIR
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (12 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 13/18] eir: Remove struct uuid_info Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 15/18] adapter: Add btd_adapter_get_services function Szymon Janc
` (3 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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] 25+ messages in thread
* [PATCH v3 15/18] adapter: Add btd_adapter_get_services function
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (13 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 14/18] eir: Add support for creating proper OOB EIR Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 16/18] adapter: Rename btd_adapter_get_class to btd_adapter_read_class Szymon Janc
` (2 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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 6d2ca69..a938c24 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -990,6 +990,11 @@ struct btd_device *adapter_get_device(struct btd_adapter *adapter,
return adapter_create_device(adapter, address, 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 eece6f5..4afe40f 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(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] 25+ messages in thread
* [PATCH v3 16/18] adapter: Rename btd_adapter_get_class to btd_adapter_read_class
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (14 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 15/18] adapter: Add btd_adapter_get_services function Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 17/18] adapter: Add btd_adapter_get_class function Szymon Janc
2012-09-21 12:36 ` [PATCH v3 18/18] neard: Implement RequestOOB function Szymon Janc
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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 a938c24..ae61f6d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2171,7 +2171,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 4afe40f..f7c4237 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(struct btd_adapter *adapter,
diff --git a/src/mgmt.c b/src/mgmt.c
index a3f31dd..8902836 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -1116,7 +1116,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] 25+ messages in thread
* [PATCH v3 17/18] adapter: Add btd_adapter_get_class function
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (15 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 16/18] adapter: Rename btd_adapter_get_class to btd_adapter_read_class Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 18/18] neard: Implement RequestOOB function Szymon Janc
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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 ae61f6d..43df465 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2185,6 +2185,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 f7c4237..4f2f39f 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(struct btd_adapter *adapter,
const char *address);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v3 18/18] neard: Implement RequestOOB function
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
` (16 preceding siblings ...)
2012-09-21 12:36 ` [PATCH v3 17/18] adapter: Add btd_adapter_get_class function Szymon Janc
@ 2012-09-21 12:36 ` Szymon Janc
17 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-21 12:36 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 dd6a422..288a47e 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 "/"
@@ -56,6 +57,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:
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(btd_get_dbus_connection(), 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,
@@ -414,7 +493,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] 25+ messages in thread
* Re: [PATCH v3 02/18] eir: Add support for parsing SSP hash and randomizer
2012-09-21 12:36 ` [PATCH v3 02/18] eir: Add support for parsing SSP hash and randomizer Szymon Janc
@ 2012-09-24 8:08 ` Johan Hedberg
2012-09-24 10:20 ` Szymon Janc
0 siblings, 1 reply; 25+ messages in thread
From: Johan Hedberg @ 2012-09-24 8:08 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Fri, Sep 21, 2012, Szymon Janc wrote:
> + 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;
I suppose using g_memdup would be simpler than g_malloc + memcpy.
Johan
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v3 05/18] oob: Allow to register pairing complete callback
2012-09-21 12:36 ` [PATCH v3 05/18] oob: Allow to register pairing complete callback Szymon Janc
@ 2012-09-24 9:06 ` Johan Hedberg
2012-09-24 11:28 ` Szymon Janc
0 siblings, 1 reply; 25+ messages in thread
From: Johan Hedberg @ 2012-09-24 9:06 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Fri, Sep 21, 2012, Szymon Janc wrote:
> --- a/src/mgmt.c
> +++ b/src/mgmt.c
> @@ -1193,6 +1193,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);
> }
Can't we be a bit smarter than always notifying the oob code. Don't we
e.g. have the possibility to look at the IO capabilities used in the
pairing process or some other means from which we can conclude that this
was an OOB-based pairing that completed?
Johan
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v3 07/18] neard: Implement PushOOB function
2012-09-21 12:36 ` [PATCH v3 07/18] neard: Implement PushOOB function Szymon Janc
@ 2012-09-24 9:09 ` Johan Hedberg
2012-09-24 14:38 ` Szymon Janc
0 siblings, 1 reply; 25+ messages in thread
From: Johan Hedberg @ 2012-09-24 9:09 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Fri, Sep 21, 2012, Szymon Janc wrote:
> +static struct btd_adapter *pending_adapter = NULL;
> +static DBusMessage *pending_msg = NULL;
I'm not really a fan of these global variables. Any chance of moving
them to a non-global temporary context that gets passed around. In
general I find it hard to get the big picture on the life-time of these
variables as it seems you don't actually explicitly initiate the pairing
process from your code but are relying on some external entity to do
that? Or did I miss something? The whole thing just looks quite brittle
right now.
Johan
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v3 02/18] eir: Add support for parsing SSP hash and randomizer
2012-09-24 8:08 ` Johan Hedberg
@ 2012-09-24 10:20 ` Szymon Janc
0 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-24 10:20 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org
On Monday 24 of September 2012 11:08:45 Johan Hedberg wrote:
> Hi Szymon,
Hi Johan,
> On Fri, Sep 21, 2012, Szymon Janc wrote:
> > + 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;
>
> I suppose using g_memdup would be simpler than g_malloc + memcpy.
Yeap that looks simpler, will use g_memdup in next version.
--
BR
Szymon Janc
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v3 05/18] oob: Allow to register pairing complete callback
2012-09-24 9:06 ` Johan Hedberg
@ 2012-09-24 11:28 ` Szymon Janc
0 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-24 11:28 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org
On Monday 24 of September 2012 12:06:26 Johan Hedberg wrote:
> Hi Szymon,
Hi Johan,
> On Fri, Sep 21, 2012, Szymon Janc wrote:
> > --- a/src/mgmt.c
> > +++ b/src/mgmt.c
> > @@ -1193,6 +1193,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);
> > }
>
> Can't we be a bit smarter than always notifying the oob code. Don't we
> e.g. have the possibility to look at the IO capabilities used in the
> pairing process or some other means from which we can conclude that this
> was an OOB-based pairing that completed?
Hash and randomizer are optional tags (only address is mandatory) so there
might be only OOB discovery and in-band pairing (OOB data present flag not
set in iocapa).
I could try to make OOB callbacks registering mechanism a bit more runtime
aware (register/unregister on-demand basis) or bit-more compile time aware
(hide after a macro and enable only if one of oob plugin is build).
Not sure if this would not over-complicate that code to much... opinions?
>
> Johan
--
BR
Szymon Janc
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v3 07/18] neard: Implement PushOOB function
2012-09-24 9:09 ` Johan Hedberg
@ 2012-09-24 14:38 ` Szymon Janc
0 siblings, 0 replies; 25+ messages in thread
From: Szymon Janc @ 2012-09-24 14:38 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org
On Monday 24 of September 2012 12:09:41 Johan Hedberg wrote:
> Hi Szymon,
Hi Johan,
> On Fri, Sep 21, 2012, Szymon Janc wrote:
> > +static struct btd_adapter *pending_adapter = NULL;
> > +static DBusMessage *pending_msg = NULL;
>
> I'm not really a fan of these global variables. Any chance of moving
> them to a non-global temporary context that gets passed around.
The idea is to keep this plugin simple so only one request at time is to be
supported. mgmt code doesn't allow to pass any 'key-like' data to identify
command<->event so this would require some general (?) solution.
I don't think this is needed.
Actually, pending_adapter might not be needed if it is guaranteed that default
adapter will not change before callback is called (I guess it is).
> In
> general I find it hard to get the big picture on the life-time of these
> variables as it seems you don't actually explicitly initiate the pairing
> process from your code but are relying on some external entity to do
> that? Or did I miss something? The whole thing just looks quite brittle
> right now.
pending_* pointers are used to store data until read local or pairing callback
is called. Pairing is initiate in PushOOB method (adapter_create_bonding is
called from process_eir).
But yeah, I guess I should have been more descriptive in cover letter. So here
is few words of overview.
Currently handover agent API consists of 2 methods RequestOOB and PushOOB.
PushOOB is used to provide data and start pairing if needed to prepare
alternative carrier (BT). From NFC side this corresponds to receiving Handover
Select frame.
RequestOOB is used to request local data from BT to pass them to remote. This
method also allows to pass remote oob data without triggering pairing (to be
used when remote starts it) - this will minimize number of D-Bus calls
needed. From NFC side this corresponds to receiving (pass remote data and
request local data) or sending (only request local data) Handover Request
frame.
Basically there are 3 possible scenarios:
- neard received Handover Select message (aka static handover):
neard calls PushOOB(data)
bluez pairs if needed and reply
- neard received Handover Request and needs to reply with Handover Select:
neard calls RequestOOB(data) and pass remote oob data received
bluez stores received data, reads local OOB data and reply to neard
neard sends HS frame based on bluez reply
[in that case remote is responsible to initialize pairing if needed]
- neard sends Handover Request and later receives Handover Select from remote:
neard calls RequestOOB(NULL)
bluez reads local OOB data and reply to neard
neard sends Handover Request base on bluez reply
neard receives Handover Select frame
neard calls PushOOB(data)
bluez pairs if needed and reply
Hope this clarify things a bit:)
> Johan
--
BR
Szymon Janc
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2012-09-24 14:38 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-21 12:36 [PATCH v3 00/18] neard plugin Szymon Janc
2012-09-21 12:36 ` [PATCH v3 01/18] Add initial neard plugin implementation Szymon Janc
2012-09-21 12:36 ` [PATCH v3 02/18] eir: Add support for parsing SSP hash and randomizer Szymon Janc
2012-09-24 8:08 ` Johan Hedberg
2012-09-24 10:20 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 03/18] eir: Store class in struct eir_data as uint32_t Szymon Janc
2012-09-21 12:36 ` [PATCH v3 04/18] eir: Add eir_parse_oob function Szymon Janc
2012-09-21 12:36 ` [PATCH v3 05/18] oob: Allow to register pairing complete callback Szymon Janc
2012-09-24 9:06 ` Johan Hedberg
2012-09-24 11:28 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 06/18] Handle missing randomizer in mgmt_add_remote_oob_data Szymon Janc
2012-09-21 12:36 ` [PATCH v3 07/18] neard: Implement PushOOB function Szymon Janc
2012-09-24 9:09 ` Johan Hedberg
2012-09-24 14:38 ` Szymon Janc
2012-09-21 12:36 ` [PATCH v3 08/18] eir: Add support creating EIR with hash and randomizer fields Szymon Janc
2012-09-21 12:36 ` [PATCH v3 09/18] eir: Add support for creating EIR with CoD field Szymon Janc
2012-09-21 12:36 ` [PATCH v3 10/18] eir: Rename eir_create to eir_create_oob Szymon Janc
2012-09-21 12:36 ` [PATCH v3 11/18] eir: Remove support for creating EIR with tx_power fields Szymon Janc
2012-09-21 12:36 ` [PATCH v3 12/18] eir: Return number of bytes written by eir_create_oob Szymon Janc
2012-09-21 12:36 ` [PATCH v3 13/18] eir: Remove struct uuid_info Szymon Janc
2012-09-21 12:36 ` [PATCH v3 14/18] eir: Add support for creating proper OOB EIR Szymon Janc
2012-09-21 12:36 ` [PATCH v3 15/18] adapter: Add btd_adapter_get_services function Szymon Janc
2012-09-21 12:36 ` [PATCH v3 16/18] adapter: Rename btd_adapter_get_class to btd_adapter_read_class Szymon Janc
2012-09-21 12:36 ` [PATCH v3 17/18] adapter: Add btd_adapter_get_class function Szymon Janc
2012-09-21 12:36 ` [PATCH v3 18/18] neard: Implement RequestOOB function Szymon Janc
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).