Included values should be string type instead of address of pointer to
string.
---
tools/btpclient.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/btpclient.c b/tools/btpclient.c
index 61bde820e..d37232f07 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -888,19 +888,19 @@ static bool ad_includes_getter(struct l_dbus *dbus,
if (ad.tx_power) {
const char *str = "tx-power";
- l_dbus_message_builder_append_basic(builder, 's', &str);
+ l_dbus_message_builder_append_basic(builder, 's', str);
}
if (ad.name) {
const char *str = "local-name";
- l_dbus_message_builder_append_basic(builder, 's', &str);
+ l_dbus_message_builder_append_basic(builder, 's', str);
}
if (ad.appearance) {
const char *str = "appearance";
- l_dbus_message_builder_append_basic(builder, 's', &str);
+ l_dbus_message_builder_append_basic(builder, 's', str);
}
l_dbus_message_builder_leave_array(builder);
--
2.13.6
Device may be connected while device found event is generated thus thus
btp should generate additional device connected event also.
---
tools/btpclient.c | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/tools/btpclient.c b/tools/btpclient.c
index 92fa742ce..006d8acbe 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -2396,24 +2396,30 @@ failed:
static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
{
+ struct btp_device *device = find_device_by_proxy(proxy);
+ struct btp_adapter *adapter = find_adapter_by_device(device);
struct btp_device_found_ev ev;
- const char *str;
+ struct btp_gap_device_connected_ev ev_conn;
+ const char *str, *addr_str;
int16_t rssi;
+ uint8_t address_type;
+ bool connected;
- if (!l_dbus_proxy_get_property(proxy, "Address", "s", &str) ||
- str2ba(str, &ev.address) < 0)
+ if (!l_dbus_proxy_get_property(proxy, "Address", "s", &addr_str) ||
+ str2ba(addr_str, &ev.address) < 0)
return;
if (!l_dbus_proxy_get_property(proxy, "AddressType", "s", &str))
return;
- ev.address_type = strcmp(str, "public") ? BTP_GAP_ADDR_RANDOM :
+ address_type = strcmp(str, "public") ? BTP_GAP_ADDR_RANDOM :
BTP_GAP_ADDR_PUBLIC;
+ ev.address_type = address_type;
if (!l_dbus_proxy_get_property(proxy, "RSSI", "n", &rssi))
- return;
-
- ev.rssi = rssi;
+ ev.rssi = 0x81;
+ else
+ ev.rssi = rssi;
/* TODO Temporary set all flags */
ev.flags = (BTP_EV_GAP_DEVICE_FOUND_FLAG_RSSI |
@@ -2423,9 +2429,17 @@ static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
/* TODO Add eir to device found event */
ev.eir_len = 0;
- btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_FOUND,
- BTP_INDEX_NON_CONTROLLER,
+ btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_FOUND, adapter->index,
sizeof(ev) + ev.eir_len, &ev);
+
+ if (l_dbus_proxy_get_property(proxy, "Connected", "b", &connected) &&
+ connected) {
+ ev_conn.address_type = address_type;
+ str2ba(addr_str, &ev_conn.address);
+
+ btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_CONNECTED,
+ adapter->index, sizeof(ev_conn), &ev_conn);
+ }
}
static void btp_gap_device_connection_ev(struct l_dbus_proxy *proxy,
--
2.13.6
This patch adds support to get/set solicit uuid16 service list in
advertising data.
---
tools/btpclient.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/tools/btpclient.c b/tools/btpclient.c
index 006d8acbe..3b53b8fc8 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -45,6 +45,7 @@
#define AD_TYPE_INCOMPLETE_UUID16_SERVICE_LIST 0x02
#define AD_TYPE_SHORT_NAME 0x08
#define AD_TYPE_TX_POWER 0x0a
+#define AD_TYPE_SOLICIT_UUID16_SERVICE_LIST 0x14
#define AD_TYPE_SERVICE_DATA_UUID16 0x16
#define AD_TYPE_APPEARANCE 0x19
#define AD_TYPE_MANUFACTURER_DATA 0xff
@@ -98,6 +99,7 @@ static struct ad {
struct l_queue *uuids;
struct l_queue *services;
struct l_queue *manufacturers;
+ struct l_queue *solicits;
bool tx_power;
bool name;
bool appearance;
@@ -443,6 +445,7 @@ static void ad_cleanup(void)
l_queue_destroy(ad.uuids, l_free);
l_queue_destroy(ad.services, ad_cleanup_service);
l_queue_destroy(ad.manufacturers, l_free);
+ l_queue_destroy(ad.solicits, l_free);
memset(&ad, 0, sizeof(ad));
}
@@ -756,6 +759,7 @@ static void ad_init(void)
ad.uuids = l_queue_new();
ad.services = l_queue_new();
ad.manufacturers = l_queue_new();
+ ad.solicits = l_queue_new();
ad.local_appearance = UINT16_MAX;
}
@@ -876,6 +880,27 @@ static bool ad_manufacturerdata_getter(struct l_dbus *dbus,
return true;
}
+static bool ad_solicituuids_getter(struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ struct l_dbus_message_builder *builder,
+ void *user_data)
+{
+ const struct l_queue_entry *entry;
+
+ if (l_queue_isempty(ad.solicits))
+ return false;
+
+ l_dbus_message_builder_enter_array(builder, "s");
+
+ for (entry = l_queue_get_entries(ad.solicits); entry;
+ entry = entry->next)
+ l_dbus_message_builder_append_basic(builder, 's', entry->data);
+
+ l_dbus_message_builder_leave_array(builder);
+
+ return true;
+}
+
static bool ad_includes_getter(struct l_dbus *dbus,
struct l_dbus_message *message,
struct l_dbus_message_builder *builder,
@@ -975,6 +1000,8 @@ static void setup_ad_interface(struct l_dbus_interface *interface)
l_dbus_interface_property(interface, "ManufacturerData", 0,
"a{qv}", ad_manufacturerdata_getter,
NULL);
+ l_dbus_interface_property(interface, "SolicitUUIDs", 0, "as",
+ ad_solicituuids_getter, NULL);
l_dbus_interface_property(interface, "Includes", 0, "as",
ad_includes_getter, NULL);
l_dbus_interface_property(interface, "LocalName", 0, "s",
@@ -1089,6 +1116,14 @@ static void create_advertising_data(uint8_t adv_data_len, const uint8_t *data)
break;
}
+ case AD_TYPE_SOLICIT_UUID16_SERVICE_LIST:
+ {
+ char *uuid = dupuuid2str(ad_data, 16);
+
+ l_queue_push_tail(ad.solicits, uuid);
+
+ break;
+ }
default:
l_info("Unsupported advertising data type");
--
2.13.6
This patch adds support for connect device command.
---
tools/btpclient.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
diff --git a/tools/btpclient.c b/tools/btpclient.c
index d1d64d068..5bf2d922f 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -1550,12 +1550,81 @@ static void connect_reply(struct l_dbus_proxy *proxy,
NULL);
}
+struct connect_device_data {
+ bdaddr_t addr;
+ uint8_t addr_type;
+};
+
+static void connect_device_destroy(void *connect_device_data)
+{
+ l_free(connect_device_data);
+}
+
+static void connect_device_reply(struct l_dbus_proxy *proxy,
+ struct l_dbus_message *result,
+ void *user_data)
+{
+ struct btp_adapter *adapter = find_adapter_by_proxy(proxy);
+
+ if (!adapter) {
+ btp_send_error(btp, BTP_GAP_SERVICE, BTP_INDEX_NON_CONTROLLER,
+ BTP_ERROR_FAIL);
+ return;
+ }
+
+ if (l_dbus_message_is_error(result)) {
+ const char *name, *desc;
+
+ l_dbus_message_get_error(result, &name, &desc);
+ l_error("Failed to connect device (%s), %s", name, desc);
+
+ return;
+ }
+}
+
+static void connect_device_setup(struct l_dbus_message *message,
+ void *user_data)
+{
+ struct connect_device_data *cdd = user_data;
+ struct l_dbus_message_builder *builder;
+ char str_addr[18];
+
+ ba2str(&cdd->addr, str_addr);
+
+ builder = l_dbus_message_builder_new(message);
+
+ l_dbus_message_builder_enter_array(builder, "{sv}");
+
+ l_dbus_message_builder_enter_dict(builder, "sv");
+ l_dbus_message_builder_append_basic(builder, 's', "Address");
+ l_dbus_message_builder_enter_variant(builder, "s");
+ l_dbus_message_builder_append_basic(builder, 's', str_addr);
+ l_dbus_message_builder_leave_variant(builder);
+ l_dbus_message_builder_leave_dict(builder);
+
+ l_dbus_message_builder_enter_dict(builder, "sv");
+ l_dbus_message_builder_append_basic(builder, 's', "AddressType");
+ l_dbus_message_builder_enter_variant(builder, "s");
+ if (cdd->addr_type == BTP_GAP_ADDR_RANDOM)
+ l_dbus_message_builder_append_basic(builder, 's', "random");
+ else
+ l_dbus_message_builder_append_basic(builder, 's', "public");
+ l_dbus_message_builder_leave_variant(builder);
+ l_dbus_message_builder_leave_dict(builder);
+
+ l_dbus_message_builder_leave_array(builder);
+
+ l_dbus_message_builder_finalize(builder);
+ l_dbus_message_builder_destroy(builder);
+}
+
static void btp_gap_connect(uint8_t index, const void *param, uint16_t length,
void *user_data)
{
struct btp_adapter *adapter = find_adapter_by_index(index);
const struct btp_gap_connect_cp *cp = param;
struct btp_device *device;
+ struct connect_device_data *cdd;
bool prop;
uint8_t status = BTP_ERROR_FAIL;
@@ -1572,6 +1641,22 @@ static void btp_gap_connect(uint8_t index, const void *param, uint16_t length,
device = find_device_by_address(adapter, &cp->address,
cp->address_type);
+ if (!device) {
+ cdd = l_new(struct connect_device_data, 1);
+ memcpy(&cdd->addr, &cp->address, sizeof(cdd->addr));
+ cdd->addr_type = cp->address_type;
+
+ l_dbus_proxy_method_call(adapter->proxy, "ConnectDevice",
+ connect_device_setup,
+ connect_device_reply,
+ cdd,
+ connect_device_destroy);
+
+ btp_send(btp, BTP_GAP_SERVICE, BTP_OP_GAP_CONNECT,
+ adapter->index, 0, NULL);
+ return;
+ }
+
if (!device)
goto failed;
--
2.13.6
This patch adds identity resolve event handler.
---
tools/btpclient.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)
diff --git a/tools/btpclient.c b/tools/btpclient.c
index 3b53b8fc8..d1d64d068 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -66,6 +66,8 @@ struct btp_adapter {
struct btp_device {
struct l_dbus_proxy *proxy;
+ uint8_t address_type;
+ bdaddr_t address;
};
static struct l_queue *adapters;
@@ -2520,6 +2522,34 @@ static void btp_gap_device_connection_ev(struct l_dbus_proxy *proxy,
}
}
+static void btp_identity_resolved_ev(struct l_dbus_proxy *proxy)
+{
+ struct btp_device *dev = find_device_by_proxy(proxy);
+ struct btp_adapter *adapter = find_adapter_by_device(dev);
+ struct btp_gap_identity_resolved_ev ev;
+ char *str_addr, *str_addr_type;
+ uint8_t identity_address_type;
+
+ if (!l_dbus_proxy_get_property(proxy, "Address", "s", &str_addr))
+ return;
+
+ if (!l_dbus_proxy_get_property(proxy, "AddressType", "s",
+ &str_addr_type))
+ return;
+
+ identity_address_type = strcmp(str_addr_type, "public") ?
+ BTP_GAP_ADDR_RANDOM : BTP_GAP_ADDR_PUBLIC;
+
+ str2ba(str_addr, &ev.identity_address);
+ ev.identity_address_type = identity_address_type;
+
+ memcpy(&ev.address, &dev->address, sizeof(ev.address));
+ ev.address_type = dev->address_type;
+
+ btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_IDENTITY_RESOLVED,
+ adapter->index, sizeof(ev), &ev);
+}
+
static void register_gap_service(void)
{
btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_READ_SUPPORTED_COMMANDS,
@@ -2809,7 +2839,7 @@ static void proxy_added(struct l_dbus_proxy *proxy, void *user_data)
if (!strcmp(interface, "org.bluez.Device1")) {
struct btp_adapter *adapter;
struct btp_device *device;
- char *str;
+ char *str, *str_addr, *str_addr_type;
if (!l_dbus_proxy_get_property(proxy, "Adapter", "o", &str))
return;
@@ -2825,6 +2855,20 @@ static void proxy_added(struct l_dbus_proxy *proxy, void *user_data)
btp_gap_device_found_ev(proxy);
+ if (!l_dbus_proxy_get_property(proxy, "Address", "s",
+ &str_addr))
+ return;
+
+ if (!l_dbus_proxy_get_property(proxy, "AddressType", "s",
+ &str_addr_type))
+ return;
+
+ device->address_type = strcmp(str_addr_type, "public") ?
+ BTP_GAP_ADDR_RANDOM :
+ BTP_GAP_ADDR_PUBLIC;
+ if (!str2ba(str_addr, &device->address))
+ return;
+
return;
}
@@ -2956,6 +3000,11 @@ static void property_changed(struct l_dbus_proxy *proxy, const char *name,
return;
btp_gap_device_connection_ev(proxy, prop);
+ } else if (!strcmp(name, "AddressType")) {
+ /* Addres property change came first along with address
+ * type.
+ */
+ btp_identity_resolved_ev(proxy);
}
}
}
--
2.13.6
This patch adds btp disconnect handler to btp client.
---
tools/btpclient.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/btpclient.c b/tools/btpclient.c
index 3d9e449ce..4097c05d0 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -2892,6 +2892,12 @@ static void client_disconnected(struct l_dbus *dbus, void *user_data)
l_main_quit();
}
+static void btp_disconnect_handler(struct btp *btp, void *user_data)
+{
+ l_info("btp disconnected");
+ l_main_quit();
+}
+
static void client_ready(struct l_dbus_client *client, void *user_data)
{
l_info("D-Bus client ready, connecting BTP");
@@ -2903,6 +2909,8 @@ static void client_ready(struct l_dbus_client *client, void *user_data)
return;
}
+ btp_set_disconnect_handler(btp, btp_disconnect_handler, NULL, NULL);
+
register_core_service();
btp_send(btp, BTP_CORE_SERVICE, BTP_EV_CORE_READY,
--
2.13.6
This patch adds passkey confirm command handler and passkey confirm
event.
---
tools/btpclient.c | 38 ++++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/tools/btpclient.c b/tools/btpclient.c
index 4097c05d0..92fa742ce 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -1707,12 +1707,42 @@ static struct l_dbus_message *ag_request_confirmation_call(struct l_dbus *dbus,
struct l_dbus_message *message,
void *user_data)
{
- struct l_dbus_message *reply;
+ struct btp_gap_passkey_confirm_ev ev;
+ struct btp_device *device;
+ struct btp_adapter *adapter;
+ const char *path, *str_addr, *str_addr_type;
+ uint32_t passkey;
- reply = l_dbus_message_new_method_return(message);
- l_dbus_message_set_arguments(reply, "");
+ l_dbus_message_get_arguments(message, "ou", &path, &passkey);
- return reply;
+ device = find_device_by_path(path);
+
+ if (!l_dbus_proxy_get_property(device->proxy, "Address", "s", &str_addr)
+ || !l_dbus_proxy_get_property(device->proxy, "AddressType", "s",
+ &str_addr_type)) {
+ l_info("Cannot get device properties");
+
+ return NULL;
+ }
+
+ ev.passkey = L_CPU_TO_LE32(passkey);
+ ev.address_type = strcmp(str_addr_type, "public") ?
+ BTP_GAP_ADDR_RANDOM :
+ BTP_GAP_ADDR_PUBLIC;
+ if (str2ba(str_addr, &ev.address) < 0) {
+ l_info("Incorrect device address");
+
+ return NULL;
+ }
+
+ adapter = find_adapter_by_device(device);
+
+ ag.pending_req = l_dbus_message_ref(message);
+
+ btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_PASSKEY_CONFIRM,
+ adapter->index, sizeof(ev), &ev);
+
+ return NULL;
}
static struct l_dbus_message *ag_request_authorization_call(struct l_dbus *dbus,
--
2.13.6
BTP don't support authorization request event.
---
tools/btpclient.c | 38 ++++----------------------------------
1 file changed, 4 insertions(+), 34 deletions(-)
diff --git a/tools/btpclient.c b/tools/btpclient.c
index 9703915dd..3d9e449ce 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -1719,42 +1719,12 @@ static struct l_dbus_message *ag_request_authorization_call(struct l_dbus *dbus,
struct l_dbus_message *message,
void *user_data)
{
- struct btp_gap_passkey_confirm_ev ev;
- struct btp_device *device;
- struct btp_adapter *adapter;
- const char *path, *str_addr, *str_addr_type;
- uint32_t passkey;
-
- l_dbus_message_get_arguments(message, "ou", &path, &passkey);
-
- device = find_device_by_path(path);
-
- if (!l_dbus_proxy_get_property(device->proxy, "Address", "s", &str_addr)
- || !l_dbus_proxy_get_property(device->proxy, "AddressType", "s",
- &str_addr_type)) {
- l_info("Cannot get device properties");
-
- return NULL;
- }
-
- ev.passkey = L_CPU_TO_LE32(passkey);
- ev.address_type = strcmp(str_addr_type, "public") ?
- BTP_GAP_ADDR_RANDOM :
- BTP_GAP_ADDR_PUBLIC;
- if (str2ba(str_addr, &ev.address) < 0) {
- l_info("Incorrect device address");
-
- return NULL;
- }
-
- adapter = find_adapter_by_device(device);
-
- ag.pending_req = l_dbus_message_ref(message);
+ struct l_dbus_message *reply;
- btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_PASSKEY_CONFIRM,
- adapter->index, sizeof(ev), &ev);
+ reply = l_dbus_message_new_method_return(message);
+ l_dbus_message_set_arguments(reply, "");
- return NULL;
+ return reply;
}
static struct l_dbus_message *ag_authorize_service_call(struct l_dbus *dbus,
--
2.13.6
This patch allows to set tx-power in advertising data.
---
tools/btpclient.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tools/btpclient.c b/tools/btpclient.c
index d37232f07..9703915dd 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -44,6 +44,7 @@
#define AD_TYPE_FLAGS 0x01
#define AD_TYPE_INCOMPLETE_UUID16_SERVICE_LIST 0x02
#define AD_TYPE_SHORT_NAME 0x08
+#define AD_TYPE_TX_POWER 0x0a
#define AD_TYPE_SERVICE_DATA_UUID16 0x16
#define AD_TYPE_APPEARANCE 0x19
#define AD_TYPE_MANUFACTURER_DATA 0xff
@@ -1048,6 +1049,12 @@ static void create_advertising_data(uint8_t adv_data_len, const uint8_t *data)
ad.local_name[ad_len] = '\0';
break;
+ case AD_TYPE_TX_POWER:
+ ad.tx_power = true;
+
+ /* XXX Value is ommited cause, stack fills it */
+
+ break;
case AD_TYPE_SERVICE_DATA_UUID16:
{
struct service_data *sd;
--
2.13.6
Hi Grzegorz,
On Wednesday, 28 February 2018 13:41:21 CET Grzegorz Kolodziejczyk wrote:
> Included values should be string type instead of address of pointer to
> string.
> ---
> tools/btpclient.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/btpclient.c b/tools/btpclient.c
> index 61bde820e..d37232f07 100644
> --- a/tools/btpclient.c
> +++ b/tools/btpclient.c
> @@ -888,19 +888,19 @@ static bool ad_includes_getter(struct l_dbus *dbus,
> if (ad.tx_power) {
> const char *str = "tx-power";
>
> - l_dbus_message_builder_append_basic(builder, 's', &str);
> + l_dbus_message_builder_append_basic(builder, 's', str);
> }
>
> if (ad.name) {
> const char *str = "local-name";
>
> - l_dbus_message_builder_append_basic(builder, 's', &str);
> + l_dbus_message_builder_append_basic(builder, 's', str);
> }
>
> if (ad.appearance) {
> const char *str = "appearance";
>
> - l_dbus_message_builder_append_basic(builder, 's', &str);
> + l_dbus_message_builder_append_basic(builder, 's', str);
> }
>
> l_dbus_message_builder_leave_array(builder);
All patches applied (after fixing commit message in patch 5 and dead code in
last patch). Thanks.
--
pozdrawiam
Szymon Janc