| From: Antonio Ospite <ospite-aNJ+ML1ZbiP93QAQaVx+gl6hYfS7NtTn@public.gmane.org> |
| Subject: [PATCH BlueZ v2 2/3] device: add a btd_device_set_trusted() call |
| Date: Wed, 18 Apr 2012 11:38:10 +0200 |
| |
| Add a new btd_* call to set a device as trusted, meant to be used by |
| _external_ plugins, this avoid making public these symbols: |
| |
| record_from_string |
| store_record |
| sdp_record_free |
| str2ba |
| str2ba |
| store_device_id |
| write_trust |
| dbus_bus_get |
| manager_find_adapter |
| adapter_get_device |
| dbus_connection_unref |
| --- |
| |
| If BlueZ can pull the required parameters itself from trusted devices this can |
| be simplified, if not then the name should be fixed to make clearer what the |
| function does. |
| |
| src/device.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| src/device.h | 9 +++++++ |
| 2 files changed, 83 insertions(+) |
| |
| diff --git a/src/device.c b/src/device.c |
| index ea6fec2..6e434c1 100644 |
| --- a/src/device.c |
| +++ b/src/device.c |
| @@ -49,6 +49,7 @@ |
| #include "att.h" |
| #include "hcid.h" |
| #include "adapter.h" |
| +#include "manager.h" |
| #include "gattrib.h" |
| #include "attio.h" |
| #include "device.h" |
| @@ -2948,6 +2949,80 @@ GSList *btd_device_get_primaries(struct btd_device *device) |
| return device->primaries; |
| } |
| |
| +int btd_device_set_trusted(const char *adapter_address, |
| + const char *device_address, |
| + char *name, |
| + uint16_t vendor_id_source, |
| + uint16_t vendor_id, |
| + uint16_t product_id, |
| + uint16_t version_id, |
| + const char *uuid, |
| + const char *sdp_record) |
| +{ |
| + struct btd_adapter *adapter; |
| + struct btd_device *device; |
| + DBusConnection *conn; |
| + bdaddr_t src; |
| + bdaddr_t dst; |
| + sdp_record_t *record; |
| + int ret = 0; |
| + |
| + record = record_from_string(sdp_record); |
| + if (record == NULL) { |
| + ret = -ENODEV; |
| + goto out; |
| + } |
| + ret = store_record(adapter_address, device_address, record); |
| + sdp_record_free(record); |
| + if (ret < 0) |
| + goto out; |
| + |
| + str2ba(adapter_address, &src); |
| + str2ba(device_address, &dst); |
| + |
| + /* Set the device id */ |
| + store_device_id(adapter_address, device_address, vendor_id_source, vendor_id, |
| + product_id, version_id); |
| + /* Don't write a profile here, |
| + * it will be updated when the device connects */ |
| + |
| + write_trust(adapter_address, device_address, "[all]", TRUE); |
| + |
| + conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); |
| + if (conn == NULL) { |
| + DBG("Failed to get on the bus"); |
| + ret = -EPERM; |
| + goto out; |
| + } |
| + |
| + adapter = manager_find_adapter(&src); |
| + if (adapter == NULL) { |
| + DBG("Failed to get the adapter"); |
| + ret = -EPERM; |
| + goto out_dbus_unref; |
| + } |
| + |
| + /* This is needed: adapter_find_device() wouldn't need a Dbus |
| + * connection but it would not be enough as it only searches for |
| + * already existing devices, while adapter_get_device() will create a |
| + * new device if necessary. |
| + */ |
| + device = adapter_get_device(conn, adapter, device_address); |
| + if (device == NULL) { |
| + DBG("Failed to get the device"); |
| + ret = -ENODEV; |
| + goto out_dbus_unref; |
| + } |
| + |
| + device_set_temporary(device, FALSE); |
| + btd_device_add_uuid(device, uuid); |
| + |
| +out_dbus_unref: |
| + dbus_connection_unref(conn); |
| +out: |
| + return ret; |
| +} |
| + |
| void btd_device_add_uuid(struct btd_device *device, const char *uuid) |
| { |
| GSList *uuid_list; |
| diff --git a/src/device.h b/src/device.h |
| index 690c64d..1011e3e 100644 |
| --- a/src/device.h |
| +++ b/src/device.h |
| @@ -57,6 +57,15 @@ void device_register_services(DBusConnection *conn, struct btd_device *device, |
| GSList *prim_list, int psm); |
| GSList *device_services_from_record(struct btd_device *device, |
| GSList *profiles); |
| +int btd_device_set_trusted(const char *adapter_address, |
| + const char *device_address, |
| + char *name, |
| + uint16_t vendor_id_source, |
| + uint16_t vendor_id, |
| + uint16_t product_id, |
| + uint16_t version_id, |
| + const char *uuid, |
| + const char *sdp_record); |
| void btd_device_add_uuid(struct btd_device *device, const char *uuid); |
| struct btd_adapter *device_get_adapter(struct btd_device *device); |
| void device_get_address(struct btd_device *device, bdaddr_t *bdaddr, |
| -- |
| 1.7.10 |
| |