* [PATCH BlueZ v2 12/14] android/hal-avrcp: Add .register_notification_rsp implementation
From: Luiz Augusto von Dentz @ 2014-02-19 16:58 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1392829138-10346-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
android/hal-avrcp.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 141 insertions(+)
diff --git a/android/hal-avrcp.c b/android/hal-avrcp.c
index d9069c0..bf3e3dc 100644
--- a/android/hal-avrcp.c
+++ b/android/hal-avrcp.c
@@ -313,6 +313,146 @@ static bt_status_t set_player_app_value_rsp(btrc_status_t rsp_status)
sizeof(cmd), &cmd, 0, NULL, NULL);
}
+static bt_status_t play_status_changed_rsp(btrc_notification_type_t type,
+ btrc_play_status_t *play_status)
+{
+ char buf[BLUEZ_HAL_MTU];
+ struct hal_cmd_avrcp_register_notification *cmd = (void *) buf;
+ size_t len;
+
+ cmd->event = BTRC_EVT_PLAY_STATUS_CHANGED;
+ cmd->type = type;
+ cmd->len = 1;
+ memcpy(cmd->data, play_status, cmd->len);
+
+ len = sizeof(*cmd) + cmd->len;
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_REGISTER_NOTIFICATION,
+ len, cmd, 0, NULL, NULL);
+}
+
+static bt_status_t track_change_rsp(btrc_notification_type_t type,
+ btrc_uid_t *track)
+{
+ char buf[BLUEZ_HAL_MTU];
+ struct hal_cmd_avrcp_register_notification *cmd = (void *) buf;
+ size_t len;
+
+ cmd->event = BTRC_EVT_TRACK_CHANGE;
+ cmd->type = type;
+ cmd->len = sizeof(*track);
+ memcpy(cmd->data, track, cmd->len);
+
+ len = sizeof(*cmd) + cmd->len;
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_REGISTER_NOTIFICATION,
+ len, cmd, 0, NULL, NULL);
+}
+
+static bt_status_t track_reached_end_rsp(btrc_notification_type_t type)
+{
+ struct hal_cmd_avrcp_register_notification cmd;
+
+ cmd.event = BTRC_EVT_TRACK_REACHED_END;
+ cmd.type = type;
+ cmd.len = 0;
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_REGISTER_NOTIFICATION,
+ sizeof(cmd), &cmd, 0, NULL, NULL);
+}
+
+static bt_status_t track_reached_start_rsp(btrc_notification_type_t type)
+{
+ struct hal_cmd_avrcp_register_notification cmd;
+
+ cmd.event = BTRC_EVT_TRACK_REACHED_START;
+ cmd.type = type;
+ cmd.len = 0;
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_REGISTER_NOTIFICATION,
+ sizeof(cmd), &cmd, 0, NULL, NULL);
+}
+
+static bt_status_t play_pos_changed_rsp(btrc_notification_type_t type,
+ uint32_t *song_pos)
+{
+ char buf[BLUEZ_HAL_MTU];
+ struct hal_cmd_avrcp_register_notification *cmd = (void *) buf;
+ size_t len;
+
+ cmd->event = BTRC_EVT_PLAY_POS_CHANGED;
+ cmd->type = type;
+ cmd->len = sizeof(*song_pos);
+ memcpy(cmd->data, song_pos, cmd->len);
+
+ len = sizeof(*cmd) + cmd->len;
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_REGISTER_NOTIFICATION,
+ len, cmd, 0, NULL, NULL);
+}
+
+static bt_status_t settings_changed_rsp(btrc_notification_type_t type,
+ btrc_player_settings_t *player_setting)
+{
+ char buf[BLUEZ_HAL_MTU];
+ struct hal_cmd_avrcp_register_notification *cmd = (void *) buf;
+ struct hal_avrcp_player_attr_value *attrs;
+ size_t len, param_len;
+ int i;
+
+ param_len = player_setting->num_attr * sizeof(*attrs);
+ len = sizeof(*cmd) + param_len;
+
+ if (len > BLUEZ_HAL_MTU)
+ return BT_STATUS_PARM_INVALID;
+
+ cmd->event = BTRC_EVT_APP_SETTINGS_CHANGED;
+ cmd->type = type;
+ cmd->len = param_len;
+
+ attrs = (struct hal_avrcp_player_attr_value *) &cmd->data[0];
+ for (i = 0; i < player_setting->num_attr; i++) {
+ attrs[i].attr = player_setting->attr_ids[i];
+ attrs[i].value = player_setting->attr_values[i];
+ }
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_REGISTER_NOTIFICATION,
+ len, cmd, 0, NULL, NULL);
+}
+
+static bt_status_t register_notification_rsp(btrc_event_id_t event_id,
+ btrc_notification_type_t type,
+ btrc_register_notification_t *p_param)
+{
+ DBG("");
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ switch (event_id) {
+ case BTRC_EVT_PLAY_STATUS_CHANGED:
+ return play_status_changed_rsp(type, &p_param->play_status);
+ case BTRC_EVT_TRACK_CHANGE:
+ return track_change_rsp(type, &p_param->track);
+ case BTRC_EVT_TRACK_REACHED_END:
+ return track_reached_end_rsp(type);
+ case BTRC_EVT_TRACK_REACHED_START:
+ return track_reached_start_rsp(type);
+ case BTRC_EVT_PLAY_POS_CHANGED:
+ return play_pos_changed_rsp(type, &p_param->song_pos);
+ case BTRC_EVT_APP_SETTINGS_CHANGED:
+ return settings_changed_rsp(type, &p_param->player_setting);
+ default:
+ return BT_STATUS_PARM_INVALID;
+ }
+}
+
static void cleanup()
{
struct hal_cmd_unregister_module cmd;
@@ -343,6 +483,7 @@ static btrc_interface_t iface = {
.get_player_app_value_text_rsp = get_player_app_value_text_rsp,
.get_element_attr_rsp = get_element_attr_rsp,
.set_player_app_value_rsp = set_player_app_value_rsp,
+ .register_notification_rsp = register_notification_rsp,
.cleanup = cleanup
};
--
1.8.5.3
^ permalink raw reply related
* [PATCH BlueZ v2 13/14] android/hal-avrcp: Add .set_volume implementation
From: Luiz Augusto von Dentz @ 2014-02-19 16:58 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1392829138-10346-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
android/hal-avrcp.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/android/hal-avrcp.c b/android/hal-avrcp.c
index bf3e3dc..f982f48 100644
--- a/android/hal-avrcp.c
+++ b/android/hal-avrcp.c
@@ -453,6 +453,21 @@ static bt_status_t register_notification_rsp(btrc_event_id_t event_id,
}
}
+static bt_status_t set_volume(uint8_t volume)
+{
+ struct hal_cmd_avrcp_set_volume cmd;
+
+ DBG("");
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ cmd.value = volume;
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_SET_VOLUME,
+ sizeof(cmd), &cmd, 0, NULL, NULL);
+}
+
static void cleanup()
{
struct hal_cmd_unregister_module cmd;
@@ -484,6 +499,7 @@ static btrc_interface_t iface = {
.get_element_attr_rsp = get_element_attr_rsp,
.set_player_app_value_rsp = set_player_app_value_rsp,
.register_notification_rsp = register_notification_rsp,
+ .set_volume = set_volume,
.cleanup = cleanup
};
--
1.8.5.3
^ permalink raw reply related
* [PATCH BlueZ v2 14/14] android/hal-avrcp: Add notification handlers
From: Luiz Augusto von Dentz @ 2014-02-19 16:58 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1392829138-10346-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
android/hal-avrcp.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 174 insertions(+)
diff --git a/android/hal-avrcp.c b/android/hal-avrcp.c
index f982f48..a11aaa3 100644
--- a/android/hal-avrcp.c
+++ b/android/hal-avrcp.c
@@ -32,6 +32,177 @@ static bool interface_ready(void)
return cbs != NULL;
}
+static void handle_remote_features(void *buf, uint16_t len)
+{
+ struct hal_ev_avrcp_remote_features *ev = buf;
+
+ if (cbs->remote_features_cb)
+ cbs->remote_features_cb((bt_bdaddr_t *) (ev->bdaddr),
+ ev->features);
+}
+
+static void handle_get_play_status(void *buf, uint16_t len)
+{
+ if (cbs->get_play_status_cb)
+ cbs->get_play_status_cb();
+}
+
+static void handle_list_player_attrs(void *buf, uint16_t len)
+{
+ if (cbs->list_player_app_attr_cb)
+ cbs->list_player_app_attr_cb();
+}
+
+static void handle_list_player_values(void *buf, uint16_t len)
+{
+ struct hal_ev_avrcp_list_player_values *ev = buf;
+
+ if (cbs->list_player_app_values_cb)
+ cbs->list_player_app_values_cb(ev->attr);
+}
+
+static void handle_get_player_values(void *buf, uint16_t len)
+{
+ struct hal_ev_avrcp_get_player_values *ev = buf;
+ btrc_player_attr_t attrs[4];
+ int i;
+
+ if (!cbs->get_player_app_value_cb)
+ return;
+
+ /* Convert uint8_t array to btrc_player_attr_t array */
+ for (i = 0; i < ev->number; i++)
+ attrs[i] = ev->attrs[i];
+
+ cbs->get_player_app_value_cb(ev->number, attrs);
+}
+
+static void handle_get_player_attrs_text(void *buf, uint16_t len)
+{
+ struct hal_ev_avrcp_get_player_attrs_text *ev = buf;
+ btrc_player_attr_t attrs[4];
+ int i;
+
+ if (!cbs->get_player_app_attrs_text_cb)
+ return;
+
+ /* Convert uint8_t array to btrc_player_attr_t array */
+ for (i = 0; i < ev->number; i++)
+ attrs[i] = ev->attrs[i];
+
+ cbs->get_player_app_attrs_text_cb(ev->number, attrs);
+}
+
+static void handle_get_player_values_text(void *buf, uint16_t len)
+{
+ struct hal_ev_avrcp_get_player_values_text *ev = buf;
+
+ if (cbs->get_player_app_values_text_cb)
+ cbs->get_player_app_values_text_cb(ev->attr, ev->number,
+ ev->values);
+}
+
+static void handle_set_player_value(void *buf, uint16_t len)
+{
+ struct hal_ev_avrcp_set_player_values *ev = buf;
+ struct hal_avrcp_player_attr_value *attrs;
+ btrc_player_settings_t values;
+ int i;
+
+ if (!cbs->set_player_app_value_cb)
+ return;
+
+ attrs = (struct hal_avrcp_player_attr_value *) ev->attrs;
+
+ /* Convert to btrc_player_settings_t */
+ values.num_attr = ev->number;
+ for (i = 0; i < ev->number; i++) {
+ values.attr_ids[i] = attrs[i].attr;
+ values.attr_values[i] = attrs[i].value;
+ }
+
+ cbs->set_player_app_value_cb(&values);
+}
+
+static void handle_get_element_attrs(void *buf, uint16_t len)
+{
+ struct hal_ev_avrcp_get_element_attrs *ev = buf;
+ btrc_media_attr_t attrs[BTRC_MAX_APP_SETTINGS];
+ int i;
+
+ if (!cbs->get_element_attr_cb)
+ return;
+
+ /* Convert uint8_t array to btrc_media_attr_t array */
+ for (i = 0; i < ev->number; i++)
+ attrs[i] = ev->attrs[i];
+
+ cbs->get_element_attr_cb(ev->number, attrs);
+}
+
+static void handle_register_notification(void *buf, uint16_t len)
+{
+ struct hal_ev_avrcp_register_notification *ev = buf;
+
+ if (cbs->register_notification_cb)
+ cbs->register_notification_cb(ev->event, ev->param);
+}
+
+static void handle_volume_changed(void *buf, uint16_t len)
+{
+ struct hal_ev_avrcp_volume_changed *ev = buf;
+
+ if (cbs->volume_change_cb)
+ cbs->volume_change_cb(ev->volume, ev->type);
+}
+
+static void handle_passthrough_cmd(void *buf, uint16_t len)
+{
+ struct hal_ev_avrcp_passthrough_cmd *ev = buf;
+
+ if (cbs->passthrough_cmd_cb)
+ cbs->passthrough_cmd_cb(ev->id, ev->state);
+}
+
+/* handlers will be called from notification thread context,
+ * index in table equals to 'opcode - HAL_MINIMUM_EVENT' */
+static const struct hal_ipc_handler ev_handlers[] = {
+ /* HAL_EV_AVRCP_REMOTE_FEATURES */
+ { handle_remote_features, false,
+ sizeof(struct hal_ev_avrcp_remote_features) },
+ /* HAL_EV_AVRCP_GET_PLAY_STATUS */
+ { handle_get_play_status, false, 0 },
+ /* HAL_EV_AVRCP_LIST_PLAYER_ATTRS */
+ { handle_list_player_attrs, false, 0 },
+ /* HAL_EV_AVRCP_LIST_PLAYER_VALUES */
+ { handle_list_player_values, false,
+ sizeof(struct hal_ev_avrcp_list_player_values) },
+ /* HAL_EV_AVRCP_GET_PLAYER_VALUES */
+ { handle_get_player_values, true,
+ sizeof(struct hal_ev_avrcp_get_player_values) },
+ /* HAL_EV_AVRCP_GET_PLAYER_ATTRS_TEXT */
+ { handle_get_player_attrs_text, true,
+ sizeof(struct hal_ev_avrcp_get_player_attrs_text) },
+ /* HAL_EV_AVRCP_GET_PLAYER_VALUES_TEXT */
+ { handle_get_player_values_text, true,
+ sizeof(struct hal_ev_avrcp_get_player_values_text) },
+ /* HAL_EV_AVRCP_SET_PLAYER_VALUES */
+ { handle_set_player_value, true,
+ sizeof(struct hal_ev_avrcp_set_player_values) },
+ /* HAL_EV_AVRCP_GET_ELEMENT_ATTRS */
+ { handle_get_element_attrs, true,
+ sizeof(struct hal_ev_avrcp_get_element_attrs) },
+ /* HAL_EV_AVRCP_REGISTER_NOTIFICATION */
+ { handle_register_notification, false,
+ sizeof(struct hal_ev_avrcp_register_notification) },
+ /* HAL_EV_AVRCP_VOLUME_CHANGED */
+ { handle_volume_changed, false,
+ sizeof(struct hal_ev_avrcp_volume_changed) },
+ /* HAL_EV_AVRCP_PASSTHROUGH_CMD */
+ { handle_passthrough_cmd, false,
+ sizeof(struct hal_ev_avrcp_passthrough_cmd) },
+};
+
static bt_status_t init(btrc_callbacks_t *callbacks)
{
struct hal_cmd_register_module cmd;
@@ -44,6 +215,9 @@ static bt_status_t init(btrc_callbacks_t *callbacks)
cbs = callbacks;
+ hal_ipc_register(HAL_SERVICE_ID_AVRCP, ev_handlers,
+ sizeof(ev_handlers) / sizeof(ev_handlers[0]));
+
cmd.service_id = HAL_SERVICE_ID_AVRCP;
ret = hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
--
1.8.5.3
^ permalink raw reply related
* Re: [PATCH BlueZ 8/8] doc/obex-api: Update documentation
From: Luiz Augusto von Dentz @ 2014-02-19 17:11 UTC (permalink / raw)
To: Patrick Ohly; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1392742461.6118.25.camel@pohly-mobl1.fritz.box>
Hi Patrick,
On Tue, Feb 18, 2014 at 6:54 PM, Patrick Ohly <patrick.ohly@intel.com> wrote:
> On Tue, 2014-02-18 at 11:30 +0200, Luiz Augusto von Dentz wrote:
>> Hi Patrick,
>>
>> On Tue, Feb 18, 2014 at 11:09 AM, Patrick Ohly <patrick.ohly@intel.com> wrote:
>> > On Fri, 2014-02-14 at 17:53 +0200, Luiz Augusto von Dentz wrote:
>> >> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>> >>
>> >> This adds Suspend and Resume methods and 'suspended' value as status in
>> >> the Transfer interface documentation.
>> >> ---
>> >> doc/obex-api.txt | 18 ++++++++++++++++--
>> >> 1 file changed, 16 insertions(+), 2 deletions(-)
>> >>
>> >> diff --git a/doc/obex-api.txt b/doc/obex-api.txt
>> >> index 1f22fea..0f57ce1 100644
>> >> --- a/doc/obex-api.txt
>> >> +++ b/doc/obex-api.txt
>> >> @@ -90,12 +90,26 @@ Methods void Cancel()
>> >> org.bluez.obex.Error.InProgress
>> >> org.bluez.obex.Error.Failed
>> >>
>> >> + void Suspend()
>> >> +
>> >> + Suspend transference.
>> >> +
>> >> + Possible errors: org.bluez.obex.Error.NotAuthorized
>> >> + org.bluez.obex.Error.NotInProgress
>> >> +
>> >> + void Resume()
>> >> +
>> >> + Resume transference.
>> >> +
>> >> + Possible errors: org.bluez.obex.Error.NotAuthorized
>> >> + org.bluez.obex.Error.NotInProgress
>> > ^^^^^^^^^^^^^
>> >
>> > Should this be a NotSuspended error? Or is it not an error to resume a
>> > transfer which is currently not suspended?
>>
>> Hmm, I would go for InProgress like in Cancel although now that you
>> mentioned we could perhaps ignore such errors if you don't see any
>> value on those.
>
> I think I would prefer to *not* get errors when Suspend() is called on
> an already suspended transfer or when Resume() is called on a running
> transfer. The rationale is that the caller will typically only care
> about the end result and not so much whether it was the one who
> triggered the change. If we remove NotInProgress resp. InProgress errors
> from the API, then such a caller can treat all errors as fatal problem,
> without having to check the exact error.
Actually the NotInProgress error is for transfer queued, I guess for
this case it makes sense to return an error since otherwise we would
have to queue commands to be send when the transfer becomes active I
believe this should probably be considered an error.
--
Luiz Augusto von Dentz
^ permalink raw reply
* Re: [PATCH 1/5] android/hidhost: Add idle time callback implementation
From: Szymon Janc @ 2014-02-19 18:00 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1392717924-7712-1-git-send-email-szymon.janc@tieto.com>
On Tuesday 18 February 2014 11:05:20 Szymon Janc wrote:
> Although this callback is for deprecated functionality and
> corresponding notification is never send by daemon it should be
> implemented for library and IPC completeness.
> ---
> android/hal-hidhost.c | 14 ++++++++++++++
> android/hal-ipc-api.txt | 10 ++++++++--
> android/hal-msg.h | 11 +++++++++--
> 3 files changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
> index fd3ad2d..dcaf996 100644
> --- a/android/hal-hidhost.c
> +++ b/android/hal-hidhost.c
> @@ -69,6 +69,15 @@ static void handle_proto_mode(void *buf, uint16_t len)
> ev->status, ev->mode);
> }
>
> +static void handle_idle_time(void *buf, uint16_t len)
> +{
> + struct hal_ev_hidhost_idle_time *ev = buf;
> +
> + if (cbacks->idle_time_cb)
> + cbacks->idle_time_cb((bt_bdaddr_t *) ev->bdaddr, ev->status,
> + ev->idle_rate);
> +}
> +
> static void handle_get_report(void *buf, uint16_t len)
> {
> struct hal_ev_hidhost_get_report *ev = buf;
> @@ -110,6 +119,11 @@ static const struct hal_ipc_handler ev_handlers[] = {
> .var_len = false,
> .data_len = sizeof(struct hal_ev_hidhost_proto_mode),
> },
> + { /* HAL_EV_HIDHOST_IDLE_TIME */
> + .handler = handle_idle_time,
> + .var_len = false,
> + .data_len = sizeof(struct hal_ev_hidhost_idle_time),
> + },
> { /* HAL_EV_HIDHOST_GET_REPORT */
> .handler = handle_get_report,
> .var_len = true,
> diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
> index ee3bd76..22dd50d 100644
> --- a/android/hal-ipc-api.txt
> +++ b/android/hal-ipc-api.txt
> @@ -614,14 +614,20 @@ Notifications:
> 0x01 = Boot
> 0xff = Unsupported
>
> - Opcode 0x84 - Get Report notification
> + Opcode 0x84 - Idle Time notification
> +
> + Notification parameters: Remote address (6 octets)
> + Status (1 octet)
> + Idle time (2 octets)
> +
> + Opcode 0x85 - Get Report notification
>
> Notification parameters: Remote address (6 octets)
> Status (1 octet)
> Report length (2 octets)
> Report data (variable)
>
> - Opcode 0x85 - Virtual Unplug notification
> + Opcode 0x86 - Virtual Unplug notification
>
> Notification parameters: Remote address (6 octets)
> Status (1 octet)
> diff --git a/android/hal-msg.h b/android/hal-msg.h
> index 6504408..15c7ebe 100644
> --- a/android/hal-msg.h
> +++ b/android/hal-msg.h
> @@ -648,7 +648,14 @@ struct hal_ev_hidhost_proto_mode {
> uint8_t mode;
> } __attribute__((packed));
>
> -#define HAL_EV_HIDHOST_GET_REPORT 0x84
> +#define HAL_EV_HIDHOST_IDLE_TIME 0x84
> +struct hal_ev_hidhost_idle_time {
> + uint8_t bdaddr[6];
> + uint8_t status;
> + uint32_t idle_rate;
> +} __attribute__((packed));
> +
> +#define HAL_EV_HIDHOST_GET_REPORT 0x85
> struct hal_ev_hidhost_get_report {
> uint8_t bdaddr[6];
> uint8_t status;
> @@ -656,7 +663,7 @@ struct hal_ev_hidhost_get_report {
> uint8_t data[0];
> } __attribute__((packed));
>
> -#define HAL_EV_HIDHOST_VIRTUAL_UNPLUG 0x85
> +#define HAL_EV_HIDHOST_VIRTUAL_UNPLUG 0x86
> struct hal_ev_hidhost_virtual_unplug {
> uint8_t bdaddr[6];
> uint8_t status;
All five patches are now upstream.
--
Szymon K. Janc
szymon.janc@gmail.com
^ permalink raw reply
* Re: [PATCH BlueZ v2 01/14] android/hal-ipc-api: Add Set Volume command
From: Szymon Janc @ 2014-02-19 18:20 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1392829138-10346-1-git-send-email-luiz.dentz@gmail.com>
Hi Luiz,
On Wednesday 19 February 2014 18:58:45 Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> ---
> v2: Use fixed buffers instead of allocating memory for ipc commands, also
> change to use variable length for text attributes to avoid having to define
> a huge MTU which in most cases would be filled with 0.
>
> android/hal-ipc-api.txt | 6 ++++++
> android/hal-msg.h | 5 +++++
> 2 files changed, 11 insertions(+)
>
> diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
> index ee3bd76..ea26d0d 100644
> --- a/android/hal-ipc-api.txt
> +++ b/android/hal-ipc-api.txt
> @@ -1300,6 +1300,12 @@ Android HAL name: "avrcp" (BT_PROFILE_AV_RC_ID)
> Valid type values : 0x00 = Interim
> 0x01 = Changed
>
> + Opcode 0x0a - Set Volume command/response
> +
> + Command parameters: Value (1 octet)
> +
> + In case of an error, the error response will be returned.
> +
> Opcode 0x81 - Remote Features notification
>
> Notification parameters: Remote address (6 octets)
> diff --git a/android/hal-msg.h b/android/hal-msg.h
> index 6504408..9d396a1 100644
> --- a/android/hal-msg.h
> +++ b/android/hal-msg.h
> @@ -882,6 +882,11 @@ struct hal_cmd_avrcp_register_notification {
> uint8_t data[0];
> } __attribute__((packed));
>
> +#define HAL_OP_AVRCP_SET_VOLUME 0x0a
> +struct hal_cmd_avrcp_set_volume {
> + uint8_t value;
> +};
> +
> #define HAL_EV_AVRCP_REMOTE_FEATURES 0x81
> struct hal_ev_avrcp_remote_features {
> uint8_t bdaddr[6];
All patches are now upstream, thanks.
--
Szymon K. Janc
szymon.janc@gmail.com
^ permalink raw reply
* [PATCH BlueZ v7 00/11] GATT API: External Services
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi
In-Reply-To: <1B88D85B-35F3-47BB-ACAD-872E6C4F0A79@holtmann.org>
This patchset implements the minimal support for adding local services
declarations.
Limitation: Remove services and multiple services exported by the same
remote will be implemented the next series. Created services are not
integrated in the attribute server. A new patchset will be sent later
allowing access the services through the LE, BR/EDR sockets.
Changes from PATCH v6 to v7:
* Rebase
* Remove testing interface (Unix socket)
Changes from PATCH v5 to v6:
* Rebase
* Fixed warning (gcc 4.6.3/32-bits): "ignoring return value of 'write'"
Changes from PATCH v4 to v5:
* Removed Release() method of GattService1 interface
Changes from PATCH v3 to v4:
* Rebase
* src/gatt.c: Replaced GIOChannel/GAttrib by "io".
Changes from PATCH v2 to v3:
* Rebase
* Interfaces renamed: s/GattServiceManager1/GattManager1,
s/Characteristic1/GattCharacteristic1, s/Descriptor/GattDescriptor1
* test/gatt-service.c: s/fprintf/printf
Changes from PATCH v1 to v2:
* Rebase
* Included patch "doc: Add GATT API"
* Interfaces renamed: s/Service1/GattService1, and
s/ServiceManager1/GattServiceManager1
* Removed patch "gatt: Implement UnregisterService" from this patchset
Changes from PATCH v0 to v1:
* Rebase
Changes from RFC v0 to PATCH v0:
* Changed copyright year : s/2013/2014
* Fixed coding style
* Added gatt-service binary to gitignore
* Added extra comment in the source code
Roughly upstreaming plan (steps):
* GATT Server: External Services -> pathset GATT API: External Services
* GATT Server: Export new database over BR/EDR and LE
* GATT Server: External Characteristics (Server)
* GATT Server: External Descriptors (Server)
* Replacement for GAttrib: use "io"
* Replace attribute server
* Remove ATTIO and automatic connection mechanism from userspace
* Fix all GATT internal plugins
* GATT Client: Remote Services
Alvaro Silva (4):
gatt: Add stub for gatt.{c, h} files
gatt: Register Manager D-Bus Interface
gatt: Add registering external service
gatt: Add external services tracking
Andre Guedes (1):
gatt: Add helper for creating GATT services
Claudio Takahasi (6):
doc: Add experimental GATT API
lib: Move GATT UUID to uuid.h
test: Add external service GATT skeleton
test: Add signal handling for gatt-service
test: Add registering external service
bluetooth.conf: Add ObjectManager interface
.gitignore | 1 +
Makefile.am | 2 +
Makefile.tools | 5 +
attrib/gatt.h | 25 -----
doc/gatt-api.txt | 142 +++++++++++++++++++++++++++
lib/uuid.h | 30 ++++++
src/bluetooth.conf | 1 +
src/gatt-dbus.c | 271 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gatt-dbus.h | 25 +++++
src/gatt.c | 106 ++++++++++++++++++++
src/gatt.h | 36 +++++++
src/main.c | 15 ++-
test/gatt-service.c | 267 +++++++++++++++++++++++++++++++++++++++++++++++++++
13 files changed, 896 insertions(+), 30 deletions(-)
create mode 100644 doc/gatt-api.txt
create mode 100644 src/gatt-dbus.c
create mode 100644 src/gatt-dbus.h
create mode 100644 src/gatt.c
create mode 100644 src/gatt.h
create mode 100644 test/gatt-service.c
--
1.8.3.1
^ permalink raw reply
* [PATCH BlueZ v7 01/11] doc: Add experimental GATT API
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi
In-Reply-To: <1392835893-6723-1-git-send-email-claudio.takahasi@openbossa.org>
This patch proposes an unified GATT API for local and remote services.
---
doc/gatt-api.txt | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 142 insertions(+)
create mode 100644 doc/gatt-api.txt
diff --git a/doc/gatt-api.txt b/doc/gatt-api.txt
new file mode 100644
index 0000000..0f6b084
--- /dev/null
+++ b/doc/gatt-api.txt
@@ -0,0 +1,142 @@
+BlueZ D-Bus GATT API description
+********************************
+
+GATT local and remote services share the same high-level D-Bus API. Local
+refers to GATT based service exported by a BlueZ plugin or an external
+application. Remote refers to GATT services exported by the peer.
+
+BlueZ acts as a proxy, translating ATT operations to D-Bus method calls and
+Properties (or the opposite). Support for D-Bus Object Manager is mandatory for
+external services to allow seamless GATT declarations (Service, Characteristic
+and Descriptors) discovery.
+
+Releasing a registered GATT service is not defined yet. Any API extension
+should avoid breaking the defined API, and if possible keep an unified GATT
+remote and local services representation.
+
+Service hierarchy
+=================
+
+GATT remote and local service representation. Object path for local services
+is freely definable.
+
+External applications implementing local services must register the services
+using GattManager1 registration method and must implement the methods and
+properties defined in GattService1 interface.
+
+Service org.bluez
+Interface org.bluez.GattService1 [Experimental]
+Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX
+
+Properties string UUID [read-only]
+
+ 128-bit service UUID.
+
+ array{object} Includes [read-only]: Not implemented
+
+ Array of object paths representing the included
+ services of this service.
+
+
+Characteristic hierarchy
+========================
+
+For local GATT defined services, the object paths need to follow the service
+path hierarchy and are freely definable.
+
+Service org.bluez
+Interface org.bluez.GattCharacteristic1 [Experimental]
+Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY
+
+Properties string UUID [read-only]
+
+ 128-bit characteristic UUID.
+
+ object Service [read-only]
+
+ Object path of the GATT service the characteristc
+ belongs to.
+
+ array{byte} Value [read-write]
+
+ Value read from the remote Bluetooth device or from
+ the external application implementing GATT services.
+
+ array{string} Flags [read-only, optional]
+
+ Defines how the characteristic value can be used. See
+ Core spec page 1898, "Table 3.5: Characteristic
+ Properties bit field" and page 1900, "Table 3.8:
+ Characteristic Extended Properties bit field". Allowed
+ values: "broadcast", "read", "write-without-response",
+ "write", "notify", "indicate",
+ "authenticated-signed-writes", "reliable-write", and
+ "writable-auxiliaries".
+
+
+Characteristic Descriptors hierarchy
+====================================
+
+Local or remote GATT characteristic descriptors hierarchy.
+
+Service org.bluez
+Interface org.bluez.GattDescriptor1 [Experimental]
+Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY/descriptorZZZ
+
+Properties string UUID [read-only]
+
+ 128-bit descriptor UUID.
+
+ object Characteristic [read-only]
+
+ Object path of the GATT characteristc the descriptor
+ belongs to.
+
+ array{byte} Value [read-write]
+
+ Raw characteristic descriptor value read from the
+ remote Bluetooth device or from the external
+ application implementing GATT services.
+
+ string Permissions [read-only]: To be defined
+
+ Defines read/write authentication and authorization
+ requirements.
+
+Service Manager hierarchy
+=============================
+
+Service Manager allows external applications to register GATT based
+services. Services must follow the API for Service and Characteristic
+described above.
+
+Local GATT services, characteristics and characteristic descriptors are
+discovered automatically using the D-Bus Object Manager interface.
+
+Service org.bluez
+Interface org.bluez.GattManager1 [Experimental]
+Object path /org/bluez
+
+Methods RegisterService(object service, dict options)
+
+ Registers remote application service exported under
+ interface GattService1. Characteristic objects must
+ be hierarchical to their service and must use the
+ interface GattCharacteristic1. D-Bus Object Manager
+ is used to fetch the exported objects.
+
+ "service" object path together with the D-Bus system
+ bus connection ID define the identification of the
+ application registering a GATT based service.
+
+ Possible errors: org.bluez.Error.InvalidArguments
+ org.bluez.Error.AlreadyExists
+
+ UnregisterService(object service)
+
+ This unregisters the service that has been
+ previously registered. The object path parameter
+ must match the same value that has been used
+ on registration.
+
+ Possible errors: org.bluez.Error.DoesNotExist
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ v7 02/11] gatt: Add stub for gatt.{c, h} files
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi, Alvaro Silva
In-Reply-To: <1392835893-6723-1-git-send-email-claudio.takahasi@openbossa.org>
From: Alvaro Silva <alvaro.silva@openbossa.org>
These files implement functions to handle ATT transactions, and expose
functions to allow other entities to manage GATT based services. It
is a replacement for src/attrib-server.c.
---
Makefile.am | 1 +
src/gatt.c | 38 ++++++++++++++++++++++++++++++++++++++
src/gatt.h | 26 ++++++++++++++++++++++++++
src/main.c | 15 ++++++++++-----
4 files changed, 75 insertions(+), 5 deletions(-)
create mode 100644 src/gatt.c
create mode 100644 src/gatt.h
diff --git a/Makefile.am b/Makefile.am
index 11f2aa1..6bbf63b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -146,6 +146,7 @@ src_bluetoothd_SOURCES = $(builtin_sources) \
src/adapter.h src/adapter.c \
src/profile.h src/profile.c \
src/service.h src/service.c \
+ src/gatt.h src/gatt.c \
src/device.h src/device.c src/attio.h \
src/dbus-common.c src/dbus-common.h \
src/eir.h src/eir.c \
diff --git a/src/gatt.c b/src/gatt.c
new file mode 100644
index 0000000..06619f0
--- /dev/null
+++ b/src/gatt.c
@@ -0,0 +1,38 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 Instituto Nokia de Tecnologia - INdT
+ *
+ *
+ * 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 "gatt.h"
+
+void gatt_init(void)
+{
+
+}
+
+void gatt_cleanup(void)
+{
+
+}
diff --git a/src/gatt.h b/src/gatt.h
new file mode 100644
index 0000000..3a320b4
--- /dev/null
+++ b/src/gatt.h
@@ -0,0 +1,26 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 Instituto Nokia de Tecnologia - INdT
+ *
+ *
+ * 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
+ *
+ */
+
+void gatt_init(void);
+
+void gatt_cleanup(void);
diff --git a/src/main.c b/src/main.c
index 91d90b4..b3136fc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -55,6 +55,7 @@
#include "dbus-common.h"
#include "agent.h"
#include "profile.h"
+#include "gatt.h"
#include "systemd.h"
#define BLUEZ_NAME "org.bluez"
@@ -531,6 +532,13 @@ int main(int argc, char *argv[])
exit(1);
}
+ if (option_experimental)
+ gdbus_flags = G_DBUS_FLAG_ENABLE_EXPERIMENTAL;
+
+ g_dbus_set_flags(gdbus_flags);
+
+ gatt_init();
+
if (adapter_init() < 0) {
error("Adapter handling initialization failed");
exit(1);
@@ -540,11 +548,6 @@ int main(int argc, char *argv[])
btd_agent_init();
btd_profile_init();
- if (option_experimental)
- gdbus_flags = G_DBUS_FLAG_ENABLE_EXPERIMENTAL;
-
- g_dbus_set_flags(gdbus_flags);
-
if (option_compat == TRUE)
sdp_flags |= SDP_SERVER_COMPAT;
@@ -598,6 +601,8 @@ int main(int argc, char *argv[])
adapter_cleanup();
+ gatt_cleanup();
+
rfkill_exit();
stop_sdp_server();
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ v7 03/11] gatt: Register Manager D-Bus Interface
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi, Alvaro Silva
In-Reply-To: <1392835893-6723-1-git-send-email-claudio.takahasi@openbossa.org>
From: Alvaro Silva <alvaro.silva@openbossa.org>
This patch registers GATT Service Manager D-Bus Interface. This
interface implements the methods to allow external application register
and unregister GATT Services.
---
Makefile.am | 1 +
src/gatt-dbus.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gatt-dbus.h | 25 +++++++++++++++++++
src/gatt.c | 9 +++++++
4 files changed, 110 insertions(+)
create mode 100644 src/gatt-dbus.c
create mode 100644 src/gatt-dbus.h
diff --git a/Makefile.am b/Makefile.am
index 6bbf63b..2862bc4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -146,6 +146,7 @@ src_bluetoothd_SOURCES = $(builtin_sources) \
src/adapter.h src/adapter.c \
src/profile.h src/profile.c \
src/service.h src/service.c \
+ src/gatt-dbus.h src/gatt-dbus.c \
src/gatt.h src/gatt.c \
src/device.h src/device.c src/attio.h \
src/dbus-common.c src/dbus-common.h \
diff --git a/src/gatt-dbus.c b/src/gatt-dbus.c
new file mode 100644
index 0000000..183c611
--- /dev/null
+++ b/src/gatt-dbus.c
@@ -0,0 +1,75 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 Instituto Nokia de Tecnologia - INdT
+ *
+ *
+ * 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 <stdint.h>
+
+#include <glib.h>
+#include <dbus/dbus.h>
+#include <gdbus/gdbus.h>
+
+#include "dbus-common.h"
+#include "log.h"
+
+#include "gatt-dbus.h"
+
+#define GATT_MGR_IFACE "org.bluez.GattManager1"
+
+static DBusMessage *register_service(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
+{
+ return dbus_message_new_method_return(msg);
+}
+
+static DBusMessage *unregister_service(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
+{
+ return dbus_message_new_method_return(msg);
+}
+
+static const GDBusMethodTable methods[] = {
+ { GDBUS_EXPERIMENTAL_METHOD("RegisterService",
+ GDBUS_ARGS({ "service", "o"},
+ { "options", "a{sv}"}),
+ NULL, register_service) },
+ { GDBUS_EXPERIMENTAL_METHOD("UnregisterService",
+ GDBUS_ARGS({"service", "o"}),
+ NULL, unregister_service) },
+ { }
+};
+
+gboolean gatt_dbus_manager_register(void)
+{
+ return g_dbus_register_interface(btd_get_dbus_connection(),
+ "/org/bluez", GATT_MGR_IFACE,
+ methods, NULL, NULL, NULL, NULL);
+}
+
+void gatt_dbus_manager_unregister(void)
+{
+ g_dbus_unregister_interface(btd_get_dbus_connection(), "/org/bluez",
+ GATT_MGR_IFACE);
+}
diff --git a/src/gatt-dbus.h b/src/gatt-dbus.h
new file mode 100644
index 0000000..310cfa9
--- /dev/null
+++ b/src/gatt-dbus.h
@@ -0,0 +1,25 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 Instituto Nokia de Tecnologia - INdT
+ *
+ *
+ * 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
+ *
+ */
+
+gboolean gatt_dbus_manager_register(void);
+void gatt_dbus_manager_unregister(void);
diff --git a/src/gatt.c b/src/gatt.c
index 06619f0..e8b691a 100644
--- a/src/gatt.c
+++ b/src/gatt.c
@@ -25,14 +25,23 @@
#include <config.h>
#endif
+#include <glib.h>
+
+#include "log.h"
+
+#include "gatt-dbus.h"
#include "gatt.h"
void gatt_init(void)
{
+ DBG("Starting GATT server");
+ gatt_dbus_manager_register();
}
void gatt_cleanup(void)
{
+ DBG("Stopping GATT server");
+ gatt_dbus_manager_unregister();
}
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ v7 04/11] gatt: Add registering external service
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi, Alvaro Silva
In-Reply-To: <1392835893-6723-1-git-send-email-claudio.takahasi@openbossa.org>
From: Alvaro Silva <alvaro.silva@openbossa.org>
This patch allows external applications register a given service on
Bluez. Applications must provide an object path and a dictionary of
options. Options dictionary will be used later to provide additional
service information.
---
src/gatt-dbus.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 88 insertions(+), 1 deletion(-)
diff --git a/src/gatt-dbus.c b/src/gatt-dbus.c
index 183c611..fd614f9 100644
--- a/src/gatt-dbus.c
+++ b/src/gatt-dbus.c
@@ -26,22 +26,109 @@
#endif
#include <stdint.h>
+#include <errno.h>
#include <glib.h>
#include <dbus/dbus.h>
#include <gdbus/gdbus.h>
+#include "adapter.h"
+#include "device.h"
+#include "lib/uuid.h"
#include "dbus-common.h"
#include "log.h"
+#include "error.h"
#include "gatt-dbus.h"
#define GATT_MGR_IFACE "org.bluez.GattManager1"
+struct external_app {
+ char *owner;
+ char *path;
+ GDBusClient *client;
+ unsigned int watch;
+};
+
+static GSList *external_apps;
+
+static int external_app_path_cmp(gconstpointer a, gconstpointer b)
+{
+ const struct external_app *eapp = a;
+ const char *path = b;
+
+ return g_strcmp0(eapp->path, path);
+}
+
+static void external_app_watch_destroy(gpointer user_data)
+{
+ struct external_app *eapp = user_data;
+
+ /* TODO: Remove from the database */
+
+ external_apps = g_slist_remove(external_apps, eapp);
+
+ g_dbus_client_unref(eapp->client);
+
+ g_free(eapp->owner);
+ g_free(eapp->path);
+ g_free(eapp);
+}
+
+static struct external_app *new_external_app(DBusConnection *conn,
+ const char *sender, const char *path)
+{
+ struct external_app *eapp;
+ GDBusClient *client;
+
+ client = g_dbus_client_new(conn, sender, "/");
+ if (client == NULL)
+ return NULL;
+
+ eapp = g_new0(struct external_app, 1);
+
+ eapp->watch = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
+ sender, NULL, eapp, external_app_watch_destroy);
+ if (eapp->watch == 0) {
+ g_dbus_client_unref(client);
+ g_free(eapp);
+ return NULL;
+ }
+
+ eapp->owner = g_strdup(sender);
+ eapp->client = client;
+ eapp->path = g_strdup(path);
+
+ return eapp;
+}
+
static DBusMessage *register_service(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
- return dbus_message_new_method_return(msg);
+ struct external_app *eapp;
+ DBusMessageIter iter;
+ const char *path;
+
+ if (!dbus_message_iter_init(msg, &iter))
+ return btd_error_invalid_args(msg);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+ return btd_error_invalid_args(msg);
+
+ dbus_message_iter_get_basic(&iter, &path);
+
+ if (g_slist_find_custom(external_apps, path, external_app_path_cmp))
+ return btd_error_already_exists(msg);
+
+ eapp = new_external_app(conn, dbus_message_get_sender(msg), path);
+ if (eapp == NULL)
+ return btd_error_failed(msg, "Not enough resources");
+
+ external_apps = g_slist_prepend(external_apps, eapp);
+
+ DBG("New app %p: %s", eapp, path);
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
static DBusMessage *unregister_service(DBusConnection *conn,
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ v7 05/11] lib: Move GATT UUID to uuid.h
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi
In-Reply-To: <1392835893-6723-1-git-send-email-claudio.takahasi@openbossa.org>
This patch moves GATT UUIDs definitions to a common header. uuid.h contains
helper functions to manipulate Bluetooth UUIDs and some common BR/EDR services
UUIDs.
---
attrib/gatt.h | 25 -------------------------
lib/uuid.h | 25 +++++++++++++++++++++++++
2 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/attrib/gatt.h b/attrib/gatt.h
index 0f113e7..4fea3eb 100644
--- a/attrib/gatt.h
+++ b/attrib/gatt.h
@@ -24,31 +24,6 @@
#include <bluetooth/sdp.h>
-/* GATT Profile Attribute types */
-#define GATT_PRIM_SVC_UUID 0x2800
-#define GATT_SND_SVC_UUID 0x2801
-#define GATT_INCLUDE_UUID 0x2802
-#define GATT_CHARAC_UUID 0x2803
-
-/* GATT Characteristic Types */
-#define GATT_CHARAC_DEVICE_NAME 0x2A00
-#define GATT_CHARAC_APPEARANCE 0x2A01
-#define GATT_CHARAC_PERIPHERAL_PRIV_FLAG 0x2A02
-#define GATT_CHARAC_RECONNECTION_ADDRESS 0x2A03
-#define GATT_CHARAC_PERIPHERAL_PREF_CONN 0x2A04
-#define GATT_CHARAC_SERVICE_CHANGED 0x2A05
-
-/* GATT Characteristic Descriptors */
-#define GATT_CHARAC_EXT_PROPER_UUID 0x2900
-#define GATT_CHARAC_USER_DESC_UUID 0x2901
-#define GATT_CLIENT_CHARAC_CFG_UUID 0x2902
-#define GATT_SERVER_CHARAC_CFG_UUID 0x2903
-#define GATT_CHARAC_FMT_UUID 0x2904
-#define GATT_CHARAC_AGREG_FMT_UUID 0x2905
-#define GATT_CHARAC_VALID_RANGE_UUID 0x2906
-#define GATT_EXTERNAL_REPORT_REFERENCE 0x2907
-#define GATT_REPORT_REFERENCE 0x2908
-
/* Client Characteristic Configuration bit field */
#define GATT_CLIENT_CHARAC_CFG_NOTIF_BIT 0x0001
#define GATT_CLIENT_CHARAC_CFG_IND_BIT 0x0002
diff --git a/lib/uuid.h b/lib/uuid.h
index 95e5a9a..c24cee5 100644
--- a/lib/uuid.h
+++ b/lib/uuid.h
@@ -105,6 +105,31 @@ extern "C" {
#define OBEX_MNS_UUID "00001133-0000-1000-8000-00805f9b34fb"
#define OBEX_MAP_UUID "00001134-0000-1000-8000-00805f9b34fb"
+/* GATT UUIDs section */
+#define GATT_PRIM_SVC_UUID 0x2800
+#define GATT_SND_SVC_UUID 0x2801
+#define GATT_INCLUDE_UUID 0x2802
+#define GATT_CHARAC_UUID 0x2803
+
+/* GATT Characteristic Types */
+#define GATT_CHARAC_DEVICE_NAME 0x2A00
+#define GATT_CHARAC_APPEARANCE 0x2A01
+#define GATT_CHARAC_PERIPHERAL_PRIV_FLAG 0x2A02
+#define GATT_CHARAC_RECONNECTION_ADDRESS 0x2A03
+#define GATT_CHARAC_PERIPHERAL_PREF_CONN 0x2A04
+#define GATT_CHARAC_SERVICE_CHANGED 0x2A05
+
+/* GATT Characteristic Descriptors */
+#define GATT_CHARAC_EXT_PROPER_UUID 0x2900
+#define GATT_CHARAC_USER_DESC_UUID 0x2901
+#define GATT_CLIENT_CHARAC_CFG_UUID 0x2902
+#define GATT_SERVER_CHARAC_CFG_UUID 0x2903
+#define GATT_CHARAC_FMT_UUID 0x2904
+#define GATT_CHARAC_AGREG_FMT_UUID 0x2905
+#define GATT_CHARAC_VALID_RANGE_UUID 0x2906
+#define GATT_EXTERNAL_REPORT_REFERENCE 0x2907
+#define GATT_REPORT_REFERENCE 0x2908
+
typedef struct {
enum {
BT_UUID_UNSPEC = 0,
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ v7 06/11] gatt: Add helper for creating GATT services
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi, Andre Guedes
In-Reply-To: <1392835893-6723-1-git-send-email-claudio.takahasi@openbossa.org>
From: Andre Guedes <andre.guedes@openbossa.org>
This patch adds the btd_gatt_add_service() helper which adds a
GATT Service declaration to the local attribute database.
---
lib/uuid.h | 5 +++++
src/gatt.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gatt.h | 10 ++++++++++
3 files changed, 74 insertions(+)
diff --git a/lib/uuid.h b/lib/uuid.h
index c24cee5..237145b 100644
--- a/lib/uuid.h
+++ b/lib/uuid.h
@@ -158,6 +158,11 @@ void bt_uuid_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst);
int bt_uuid_to_string(const bt_uuid_t *uuid, char *str, size_t n);
int bt_string_to_uuid(bt_uuid_t *uuid, const char *string);
+static inline int bt_uuid_len(const bt_uuid_t *uuid)
+{
+ return uuid->type / 8;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/src/gatt.c b/src/gatt.c
index e8b691a..f7b74d6 100644
--- a/src/gatt.c
+++ b/src/gatt.c
@@ -28,10 +28,69 @@
#include <glib.h>
#include "log.h"
+#include "lib/uuid.h"
+#include "attrib/att.h"
#include "gatt-dbus.h"
#include "gatt.h"
+/* Common GATT UUIDs */
+static const bt_uuid_t primary_uuid = { .type = BT_UUID16,
+ .value.u16 = GATT_PRIM_SVC_UUID };
+
+struct btd_attribute {
+ uint16_t handle;
+ bt_uuid_t type;
+ uint16_t value_len;
+ uint8_t value[0];
+};
+
+static GList *local_attribute_db;
+static uint16_t next_handle = 0x0001;
+
+static int local_database_add(uint16_t handle, struct btd_attribute *attr)
+{
+ attr->handle = handle;
+
+ local_attribute_db = g_list_append(local_attribute_db, attr);
+
+ return 0;
+}
+
+struct btd_attribute *btd_gatt_add_service(const bt_uuid_t *uuid)
+{
+ uint16_t len = bt_uuid_len(uuid);
+ struct btd_attribute *attr = g_malloc0(sizeof(struct btd_attribute) +
+ len);
+
+ /*
+ * Service DECLARATION
+ *
+ * TYPE ATTRIBUTE VALUE
+ * +-------+---------------------------------+
+ * |0x2800 | 0xYYYY... |
+ * | (1) | (2) |
+ * +------+----------------------------------+
+ * (1) - 2 octets: Primary/Secondary Service UUID
+ * (2) - 2 or 16 octets: Service UUID
+ */
+
+ attr->type = primary_uuid;
+
+ att_put_uuid(*uuid, attr->value);
+ attr->value_len = len;
+
+ if (local_database_add(next_handle, attr) < 0) {
+ g_free(attr);
+ return NULL;
+ }
+
+ /* TODO: missing overflow checking */
+ next_handle = next_handle + 1;
+
+ return attr;
+}
+
void gatt_init(void)
{
DBG("Starting GATT server");
diff --git a/src/gatt.h b/src/gatt.h
index 3a320b4..8dd1312 100644
--- a/src/gatt.h
+++ b/src/gatt.h
@@ -21,6 +21,16 @@
*
*/
+struct btd_attribute;
+
void gatt_init(void);
void gatt_cleanup(void);
+
+/* btd_gatt_add_service - Add a service declaration to local attribute database.
+ * @uuid: Service UUID.
+ *
+ * Returns a reference to service declaration attribute. In case of error,
+ * NULL is returned.
+ */
+struct btd_attribute *btd_gatt_add_service(const bt_uuid_t *uuid);
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ v7 07/11] gatt: Add external services tracking
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi, Alvaro Silva
In-Reply-To: <1392835893-6723-1-git-send-email-claudio.takahasi@openbossa.org>
From: Alvaro Silva <alvaro.silva@openbossa.org>
All primary services declarations provided by an external application
will be automatically inserted in the attribute database.
---
src/gatt-dbus.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 109 insertions(+)
diff --git a/src/gatt-dbus.c b/src/gatt-dbus.c
index fd614f9..000d7ae 100644
--- a/src/gatt-dbus.c
+++ b/src/gatt-dbus.c
@@ -39,15 +39,21 @@
#include "log.h"
#include "error.h"
+#include "gatt.h"
#include "gatt-dbus.h"
#define GATT_MGR_IFACE "org.bluez.GattManager1"
+#define SERVICE_IFACE "org.bluez.GattService1"
+
+#define REGISTER_TIMER 1
struct external_app {
char *owner;
char *path;
GDBusClient *client;
+ GSList *proxies;
unsigned int watch;
+ guint register_timer;
};
static GSList *external_apps;
@@ -60,6 +66,36 @@ static int external_app_path_cmp(gconstpointer a, gconstpointer b)
return g_strcmp0(eapp->path, path);
}
+static void proxy_added(GDBusProxy *proxy, void *user_data)
+{
+ struct external_app *eapp = user_data;
+ const char *interface, *path;
+
+ interface = g_dbus_proxy_get_interface(proxy);
+ path = g_dbus_proxy_get_path(proxy);
+
+ DBG("path %s iface %s", path, interface);
+
+ if (g_strcmp0(interface, SERVICE_IFACE) != 0)
+ return;
+
+ eapp->proxies = g_slist_append(eapp->proxies, proxy);
+}
+
+static void proxy_removed(GDBusProxy *proxy, void *user_data)
+{
+ struct external_app *eapp = user_data;
+ const char *interface, *path;
+
+ interface = g_dbus_proxy_get_interface(proxy);
+ path = g_dbus_proxy_get_path(proxy);
+
+ DBG("path %s iface %s", path, interface);
+
+ eapp->proxies = g_slist_remove(eapp->proxies, proxy);
+}
+
+
static void external_app_watch_destroy(gpointer user_data)
{
struct external_app *eapp = user_data;
@@ -70,6 +106,9 @@ static void external_app_watch_destroy(gpointer user_data)
g_dbus_client_unref(eapp->client);
+ if (eapp->register_timer)
+ g_source_remove(eapp->register_timer);
+
g_free(eapp->owner);
g_free(eapp->path);
g_free(eapp);
@@ -99,9 +138,75 @@ static struct external_app *new_external_app(DBusConnection *conn,
eapp->client = client;
eapp->path = g_strdup(path);
+ g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
+ NULL, eapp);
+
return eapp;
}
+static int register_external_service(GDBusProxy *proxy)
+{
+ DBusMessageIter iter;
+ const char *uuid;
+ bt_uuid_t btuuid;
+
+ if (!g_dbus_proxy_get_property(proxy, "UUID", &iter))
+ return -EINVAL;
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return -EINVAL;
+
+ dbus_message_iter_get_basic(&iter, &uuid);
+
+ if (bt_string_to_uuid(&btuuid, uuid) < 0)
+ return -EINVAL;
+
+ if (btd_gatt_add_service(&btuuid) == NULL)
+ return -EINVAL;
+
+ return 0;
+}
+
+static gboolean finish_register(gpointer user_data)
+{
+ struct external_app *eapp = user_data;
+ GSList *list;
+
+ /*
+ * It is not possible to detect when the last proxy object
+ * was reported. "Proxy added" handler reports objects
+ * added on demand or returned by GetManagedObjects().
+ * This timer helps to register all the GATT declarations
+ * (services, characteristics and descriptors) after fetching
+ * all the D-Bus objects.
+ */
+
+ eapp->register_timer = 0;
+
+ for (list = eapp->proxies; list; list = g_slist_next(list)) {
+ const char *interface, *path;
+ GDBusProxy *proxy = list->data;
+
+ interface = g_dbus_proxy_get_interface(proxy);
+ path = g_dbus_proxy_get_path(proxy);
+
+ if (g_strcmp0(SERVICE_IFACE, interface) != 0)
+ continue;
+
+ if (g_strcmp0(path, eapp->path) != 0)
+ continue;
+
+ if (register_external_service(proxy) < 0) {
+ DBG("Inconsistent external service: %s", path);
+ continue;
+ }
+
+ DBG("External service: %s", path);
+ }
+
+ return FALSE;
+}
+
static DBusMessage *register_service(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
@@ -109,6 +214,8 @@ static DBusMessage *register_service(DBusConnection *conn,
DBusMessageIter iter;
const char *path;
+ DBG("Registering GATT Service");
+
if (!dbus_message_iter_init(msg, &iter))
return btd_error_invalid_args(msg);
@@ -127,6 +234,8 @@ static DBusMessage *register_service(DBusConnection *conn,
external_apps = g_slist_prepend(external_apps, eapp);
DBG("New app %p: %s", eapp, path);
+ eapp->register_timer = g_timeout_add_seconds(REGISTER_TIMER,
+ finish_register, eapp);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ v7 08/11] test: Add external service GATT skeleton
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi
In-Reply-To: <1392835893-6723-1-git-send-email-claudio.takahasi@openbossa.org>
This patch adds the initial code for an external GATT service example.
It implements the API defined at doc/gatt-api.txt
---
.gitignore | 1 +
Makefile.tools | 5 +++
test/gatt-service.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 127 insertions(+)
create mode 100644 test/gatt-service.c
diff --git a/.gitignore b/.gitignore
index b86deae..3f3c7d4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -75,6 +75,7 @@ test/sap_client.pyc
test/bluezutils.pyc
unit/test-ringbuf
unit/test-queue
+test/gatt-service
unit/test-eir
unit/test-uuid
unit/test-crc
diff --git a/Makefile.tools b/Makefile.tools
index 012dd70..92f31a2 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -378,3 +378,8 @@ test_scripts += test/sap_client.py test/bluezutils.py \
test/test-heartrate test/test-alert test/test-hfp \
test/test-cyclingspeed test/opp-client test/ftp-client \
test/pbap-client test/map-client
+
+noinst_PROGRAMS += test/gatt-service
+
+test_gatt_service_SOURCES = test/gatt-service.c
+test_gatt_service_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ gdbus/libgdbus-internal.la
diff --git a/test/gatt-service.c b/test/gatt-service.c
new file mode 100644
index 0000000..769fd37
--- /dev/null
+++ b/test/gatt-service.c
@@ -0,0 +1,121 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Instituto Nokia de Tecnologia - INdT
+ *
+ *
+ * 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 <stdio.h>
+
+#include <glib.h>
+#include <dbus/dbus.h>
+#include <gdbus/gdbus.h>
+
+#define SERVICE_IFACE "org.bluez.GattService1"
+
+/* Immediate Alert Service UUID */
+#define IAS_UUID "00001802-0000-1000-8000-00805f9b34fb"
+
+static GMainLoop *main_loop;
+static GSList *services;
+
+static gboolean service_get_uuid(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *user_data)
+{
+ const char *uuid = user_data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &uuid);
+
+ return TRUE;
+}
+
+static gboolean service_get_includes(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *user_data)
+{
+ return TRUE;
+}
+
+static gboolean service_exist_includes(const GDBusPropertyTable *property,
+ void *user_data)
+{
+ return FALSE;
+}
+
+static const GDBusPropertyTable service_properties[] = {
+ { "UUID", "s", service_get_uuid },
+ { "Includes", "ao", service_get_includes, NULL,
+ service_exist_includes },
+ { }
+};
+
+static char *register_service(DBusConnection *conn, const char *uuid)
+{
+ static int id = 1;
+ char *path;
+
+ path = g_strdup_printf("/service%d", id++);
+ if (g_dbus_register_interface(conn, path, SERVICE_IFACE,
+ NULL, NULL, service_properties,
+ g_strdup(uuid), g_free) == FALSE) {
+ printf("Couldn't register service interface\n");
+ g_free(path);
+ return NULL;
+ }
+
+ return path;
+}
+
+static void create_services(DBusConnection *conn)
+{
+ char *service_path;
+
+ service_path = register_service(conn, IAS_UUID);
+
+ services = g_slist_prepend(services, service_path);
+
+ printf("Registered service: %s\n", service_path);
+}
+
+int main(int argc, char *argv[])
+{
+ DBusConnection *dbus_conn;
+
+ dbus_conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);
+
+ main_loop = g_main_loop_new(NULL, FALSE);
+
+ g_dbus_attach_object_manager(dbus_conn);
+
+ printf("gatt-service unique name: %s\n",
+ dbus_bus_get_unique_name(dbus_conn));
+
+ create_services(dbus_conn);
+
+ g_main_loop_run(main_loop);
+
+ g_slist_free_full(services, g_free);
+ dbus_connection_unref(dbus_conn);
+
+ return 0;
+}
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ v7 09/11] test: Add signal handling for gatt-service
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi
In-Reply-To: <1392835893-6723-1-git-send-email-claudio.takahasi@openbossa.org>
This patch implements signal handling to run cleanup tasks before
exiting.
---
test/gatt-service.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/test/gatt-service.c b/test/gatt-service.c
index 769fd37..4059336 100644
--- a/test/gatt-service.c
+++ b/test/gatt-service.c
@@ -27,6 +27,9 @@
#include <errno.h>
#include <stdio.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <sys/signalfd.h>
#include <glib.h>
#include <dbus/dbus.h>
@@ -97,9 +100,83 @@ static void create_services(DBusConnection *conn)
printf("Registered service: %s\n", service_path);
}
+static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
+ gpointer user_data)
+{
+ static bool __terminated = false;
+ struct signalfd_siginfo si;
+ ssize_t result;
+ int fd;
+
+ if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
+ return FALSE;
+
+ fd = g_io_channel_unix_get_fd(channel);
+
+ result = read(fd, &si, sizeof(si));
+ if (result != sizeof(si))
+ return FALSE;
+
+ switch (si.ssi_signo) {
+ case SIGINT:
+ case SIGTERM:
+ if (!__terminated) {
+ printf("Terminating\n");
+ g_main_loop_quit(main_loop);
+ }
+
+ __terminated = true;
+ break;
+ }
+
+ return TRUE;
+}
+
+static guint setup_signalfd(void)
+{
+ GIOChannel *channel;
+ guint source;
+ sigset_t mask;
+ int fd;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGINT);
+ sigaddset(&mask, SIGTERM);
+
+ if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
+ perror("Failed to set signal mask");
+ return 0;
+ }
+
+ fd = signalfd(-1, &mask, 0);
+ if (fd < 0) {
+ perror("Failed to create signal descriptor");
+ return 0;
+ }
+
+ channel = g_io_channel_unix_new(fd);
+
+ g_io_channel_set_close_on_unref(channel, TRUE);
+ g_io_channel_set_encoding(channel, NULL, NULL);
+ g_io_channel_set_buffered(channel, FALSE);
+
+ source = g_io_add_watch(channel,
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ signal_handler, NULL);
+
+ g_io_channel_unref(channel);
+
+ return source;
+}
+
int main(int argc, char *argv[])
{
DBusConnection *dbus_conn;
+ guint signal;
+
+ signal = setup_signalfd();
+ if (signal == 0)
+ return -errno;
dbus_conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);
@@ -114,6 +191,8 @@ int main(int argc, char *argv[])
g_main_loop_run(main_loop);
+ g_source_remove(signal);
+
g_slist_free_full(services, g_free);
dbus_connection_unref(dbus_conn);
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ v7 10/11] test: Add registering external service
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi
In-Reply-To: <1392835893-6723-1-git-send-email-claudio.takahasi@openbossa.org>
This patch extends gatt-service to call RegisterService() when org.bluez
service gets connected to the system bus.
---
test/gatt-service.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/test/gatt-service.c b/test/gatt-service.c
index 4059336..b656ef3 100644
--- a/test/gatt-service.c
+++ b/test/gatt-service.c
@@ -35,6 +35,7 @@
#include <dbus/dbus.h>
#include <gdbus/gdbus.h>
+#define GATT_MGR_IFACE "org.bluez.GattManager1"
#define SERVICE_IFACE "org.bluez.GattService1"
/* Immediate Alert Service UUID */
@@ -100,6 +101,65 @@ static void create_services(DBusConnection *conn)
printf("Registered service: %s\n", service_path);
}
+static void register_external_service_reply(DBusPendingCall *call,
+ void *user_data)
+{
+ DBusMessage *reply = dbus_pending_call_steal_reply(call);
+ DBusError derr;
+
+ dbus_error_init(&derr);
+ dbus_set_error_from_message(&derr, reply);
+
+ if (dbus_error_is_set(&derr))
+ printf("RegisterService: %s\n", derr.message);
+ else
+ printf("RegisterService: OK\n");
+
+ dbus_message_unref(reply);
+ dbus_error_free(&derr);
+}
+
+static void register_external_service(gpointer a, gpointer b)
+{
+ DBusConnection *conn = b;
+ const char *path = a;
+ DBusMessage *msg;
+ DBusPendingCall *call;
+ DBusMessageIter iter, dict;
+
+ msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
+ GATT_MGR_IFACE, "RegisterService");
+ if (msg == NULL) {
+ printf("Couldn't allocate D-Bus message\n");
+ return;
+ }
+
+ dbus_message_iter_init_append(msg, &iter);
+
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &dict);
+
+ /* TODO: Add options dictionary */
+
+ dbus_message_iter_close_container(&iter, &dict);
+
+ if (g_dbus_send_message_with_reply(conn, msg, &call, -1) == FALSE) {
+ dbus_message_unref(msg);
+ return;
+ }
+
+ dbus_pending_call_set_notify(call, register_external_service_reply,
+ NULL, NULL);
+
+ dbus_pending_call_unref(call);
+}
+
+static void connect_handler(DBusConnection *conn, void *user_data)
+{
+ g_slist_foreach(services, register_external_service, conn);
+}
+
static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
gpointer user_data)
{
@@ -171,6 +231,7 @@ static guint setup_signalfd(void)
int main(int argc, char *argv[])
{
+ GDBusClient *client;
DBusConnection *dbus_conn;
guint signal;
@@ -189,8 +250,14 @@ int main(int argc, char *argv[])
create_services(dbus_conn);
+ client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
+
+ g_dbus_client_set_connect_watch(client, connect_handler, NULL);
+
g_main_loop_run(main_loop);
+ g_dbus_client_unref(client);
+
g_source_remove(signal);
g_slist_free_full(services, g_free);
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ v7 11/11] bluetooth.conf: Add ObjectManager interface
From: Claudio Takahasi @ 2014-02-19 18:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: claudio.takahasi
In-Reply-To: <1392835893-6723-1-git-send-email-claudio.takahasi@openbossa.org>
---
src/bluetooth.conf | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/bluetooth.conf b/src/bluetooth.conf
index 0495200..ad8891a 100644
--- a/src/bluetooth.conf
+++ b/src/bluetooth.conf
@@ -18,6 +18,7 @@
<allow send_interface="org.bluez.Profile1"/>
<allow send_interface="org.bluez.HeartRateWatcher1"/>
<allow send_interface="org.bluez.CyclingSpeedWatcher1"/>
+ <allow send_interface="org.freedesktop.DBus.ObjectManager"/>
</policy>
<policy at_console="true">
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH] android/README: Add note on libglib under Valgrind
From: Szymon Janc @ 2014-02-19 19:28 UTC (permalink / raw)
To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1392233027-3201-1-git-send-email-andrzej.kaczmarek@tieto.com>
Hi Andrzej,
On Wednesday 12 February 2014 20:23:47 Andrzej Kaczmarek wrote:
> ---
> android/README | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/android/README b/android/README
> index 75b0a83..3095383 100644
> --- a/android/README
> +++ b/android/README
> @@ -124,6 +124,12 @@ After changing property value Bluetooth need to be
> restarted to apply changes (this can be done using UI, just disable and
> enable it again). Property is persistent, i.e. there's no need to enable
> Valgrind again after reboot.
>
> +It's recommended to have unstripped libglib.so installed which will enable
> +complete backtraces in Valgrind output. Otherwise, in many cases backtrace
> +will break at e.g. g_free() function without prior callers. It's possible
> to +have proper library installed automatically by appropriate entry in
> Android.mk, +see https://code.google.com/p/aosp-bluez.glib/ for an example.
> +
> =============================
> Building and running on Linux
> =============================
Applied, thanks.
--
Szymon K. Janc
szymon.janc@gmail.com
^ permalink raw reply
* [PATCH] Bluetooth: Don't send store hint for devices using identity addresses
From: Marcel Holtmann @ 2014-02-19 19:51 UTC (permalink / raw)
To: linux-bluetooth
The identity resolving keys should only be stored for devices using
resolvable random addresses. If the device is already using an
identity address, inform it about the new identity resolving key,
but tell userspace that this key is not persistent.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
net/bluetooth/mgmt.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 1daa837da091..e8b9d2f261ee 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -4798,7 +4798,22 @@ void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk)
memset(&ev, 0, sizeof(ev));
- ev.store_hint = 0x01;
+ /* For identity resolving keys from devices that are already
+ * using a public address or static random address, do not
+ * ask for storing this key. The identity resolving key really
+ * is only mandatory for devices using resovlable random
+ * addresses.
+ *
+ * Storing all identity resolving keys has the downside that
+ * they will be also loaded on next boot of they system. More
+ * identity resolving keys, means more time during scanning is
+ * needed to actually resolve these addresses.
+ */
+ if (bacmp(&irk->rpa, BDADDR_ANY))
+ ev.store_hint = 0x01;
+ else
+ ev.store_hint = 0x00;
+
bacpy(&ev.rpa, &irk->rpa);
bacpy(&ev.irk.addr.bdaddr, &irk->bdaddr);
ev.irk.addr.type = link_to_bdaddr(LE_LINK, irk->addr_type);
--
1.8.5.3
^ permalink raw reply related
* [PATCH] hog: Fill ev.u.create.{phys,uniq} for UHID_CREATE
From: Petri Gynther @ 2014-02-19 20:15 UTC (permalink / raw)
To: linux-bluetooth
Fill ev.u.create.{phys,uniq} fields when uHID device is created.
These values are copied to kernel hid_device structure.
linux/include/linux/hid.h:
struct hid_device {
...
char name[128]; /* Device name */
char phys[64]; /* Device physical location */
char uniq[64]; /* Device unique identifier (serial #) */
---
profiles/input/hog.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/profiles/input/hog.c b/profiles/input/hog.c
index b9a14b9..35b973b 100644
--- a/profiles/input/hog.c
+++ b/profiles/input/hog.c
@@ -92,6 +92,8 @@ struct hog_device {
uint16_t ctrlpt_handle;
uint8_t flags;
char *name;
+ bdaddr_t src;
+ bdaddr_t dst;
};
struct report {
@@ -396,6 +398,8 @@ static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
strncpy((char *) ev.u.create.name, hogdev->name ?
hogdev->name : "bluez-hog-device",
sizeof(ev.u.create.name) - 1);
+ ba2str(&hogdev->src, (char *) ev.u.create.phys);
+ ba2str(&hogdev->dst, (char *) ev.u.create.uniq);
ev.u.create.vendor = vendor;
ev.u.create.product = product;
ev.u.create.version = version;
@@ -724,6 +728,7 @@ static void attio_disconnected_cb(gpointer user_data)
static struct hog_device *hog_new_device(struct btd_device *device,
uint16_t id)
{
+ struct btd_adapter *adapter = device_get_adapter(device);
struct hog_device *hogdev;
char name[HCI_MAX_NAME_LENGTH + 1];
@@ -736,6 +741,8 @@ static struct hog_device *hog_new_device(struct btd_device *device,
device_get_name(device, name, sizeof(name));
if (strlen(name) > 0)
hogdev->name = g_strdup(name);
+ bacpy(&hogdev->src, btd_adapter_get_address(adapter));
+ bacpy(&hogdev->dst, device_get_address(device));
return hogdev;
}
--
1.9.0.rc1.175.g0b1dcb5
^ permalink raw reply related
* Re: [PATCH] hog: Fill ev.u.create.{phys,uniq} for UHID_CREATE
From: Szymon Janc @ 2014-02-19 20:30 UTC (permalink / raw)
To: Petri Gynther; +Cc: linux-bluetooth
In-Reply-To: <20140219201545.4D13D1007E0@puck.mtv.corp.google.com>
Hi Petri,
On Wednesday 19 February 2014 12:15:45 Petri Gynther wrote:
> Fill ev.u.create.{phys,uniq} fields when uHID device is created.
> These values are copied to kernel hid_device structure.
>
> linux/include/linux/hid.h:
> struct hid_device {
> ...
> char name[128]; /* Device name */
> char phys[64]; /* Device physical location */
> char uniq[64]; /* Device unique identifier (serial #) */
> ---
> profiles/input/hog.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/profiles/input/hog.c b/profiles/input/hog.c
> index b9a14b9..35b973b 100644
> --- a/profiles/input/hog.c
> +++ b/profiles/input/hog.c
> @@ -92,6 +92,8 @@ struct hog_device {
> uint16_t ctrlpt_handle;
> uint8_t flags;
> char *name;
> + bdaddr_t src;
> + bdaddr_t dst;
> };
>
struct hog_device already holds reference to btd_device and both src and dst
can be taken from it where needed. No need to extend struct hog_device.
BTW same goes with name member which could be removed.
> struct report {
> @@ -396,6 +398,8 @@ static void report_map_read_cb(guint8 status, const
> guint8 *pdu, guint16 plen, strncpy((char *) ev.u.create.name, hogdev->name
> ?
> hogdev->name : "bluez-hog-device",
> sizeof(ev.u.create.name) - 1);
> + ba2str(&hogdev->src, (char *) ev.u.create.phys);
> + ba2str(&hogdev->dst, (char *) ev.u.create.uniq);
> ev.u.create.vendor = vendor;
> ev.u.create.product = product;
> ev.u.create.version = version;
> @@ -724,6 +728,7 @@ static void attio_disconnected_cb(gpointer user_data)
> static struct hog_device *hog_new_device(struct btd_device *device,
> uint16_t id)
> {
> + struct btd_adapter *adapter = device_get_adapter(device);
> struct hog_device *hogdev;
> char name[HCI_MAX_NAME_LENGTH + 1];
>
> @@ -736,6 +741,8 @@ static struct hog_device *hog_new_device(struct
> btd_device *device, device_get_name(device, name, sizeof(name));
> if (strlen(name) > 0)
> hogdev->name = g_strdup(name);
> + bacpy(&hogdev->src, btd_adapter_get_address(adapter));
> + bacpy(&hogdev->dst, device_get_address(device));
>
> return hogdev;
> }
--
Szymon K. Janc
szymon.janc@gmail.com
^ permalink raw reply
* [PATCH 1/2] android/hal-bluetooth: Use fixed size buffers for commands
From: Szymon Janc @ 2014-02-19 20:49 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This make code follow same conventions for all commands.
---
android/hal-bluetooth.c | 44 +++++++++++++++++++++++++++-----------------
1 file changed, 27 insertions(+), 17 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 65432a8..a01229a 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -525,8 +525,9 @@ static int get_adapter_property(bt_property_type_t type)
static int set_adapter_property(const bt_property_t *property)
{
- char buf[sizeof(struct hal_cmd_set_adapter_prop) + property->len];
+ char buf[BLUEZ_HAL_MTU];
struct hal_cmd_set_adapter_prop *cmd = (void *) buf;
+ size_t len;
DBG("prop: %s", btproperty2str(property));
@@ -535,8 +536,10 @@ static int set_adapter_property(const bt_property_t *property)
adapter_prop_from_hal(property, &cmd->type, &cmd->len, cmd->val);
+ len = sizeof(*cmd) + cmd->len;
+
return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_ADAPTER_PROP,
- sizeof(*cmd) + cmd->len, cmd, 0, NULL, NULL);
+ len, cmd, 0, NULL, NULL);
}
static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
@@ -579,8 +582,9 @@ static int get_remote_device_property(bt_bdaddr_t *remote_addr,
static int set_remote_device_property(bt_bdaddr_t *remote_addr,
const bt_property_t *property)
{
- struct hal_cmd_set_remote_device_prop *cmd;
- uint8_t buf[sizeof(*cmd) + property->len];
+ char buf[BLUEZ_HAL_MTU];
+ struct hal_cmd_set_remote_device_prop *cmd = (void *) buf;
+ size_t len;
DBG("bdaddr: %s prop: %s", bdaddr2str(remote_addr),
bt_property_type_t2str(property->type));
@@ -588,8 +592,6 @@ static int set_remote_device_property(bt_bdaddr_t *remote_addr,
if (!interface_ready())
return BT_STATUS_NOT_READY;
- cmd = (void *) buf;
-
memcpy(cmd->bdaddr, remote_addr, sizeof(cmd->bdaddr));
/* type match IPC type */
@@ -597,9 +599,11 @@ static int set_remote_device_property(bt_bdaddr_t *remote_addr,
cmd->len = property->len;
memcpy(cmd->val, property->val, property->len);
+ len = sizeof(*cmd) + cmd->len;
+
return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH,
HAL_OP_SET_REMOTE_DEVICE_PROP,
- sizeof(buf), cmd, 0, NULL, NULL);
+ len, cmd, 0, NULL, NULL);
}
static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
@@ -786,40 +790,46 @@ static int dut_mode_configure(uint8_t enable)
sizeof(cmd), &cmd, 0, NULL, NULL);
}
-static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
+static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
{
- uint8_t cmd_buf[sizeof(struct hal_cmd_dut_mode_send) + len];
+ char cmd_buf[BLUEZ_HAL_MTU];
struct hal_cmd_dut_mode_send *cmd = (void *) cmd_buf;
+ size_t len;
- DBG("opcode %u len %u", opcode, len);
+ DBG("opcode %u len %u", opcode, buf_len);
if (!interface_ready())
return BT_STATUS_NOT_READY;
cmd->opcode = opcode;
- cmd->len = len;
+ cmd->len = buf_len;
memcpy(cmd->data, buf, cmd->len);
+ len = sizeof(*cmd) + cmd->len;
+
return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DUT_MODE_SEND,
- sizeof(cmd_buf), cmd, 0, NULL, NULL);
+ len, cmd, 0, NULL, NULL);
}
-static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len)
+static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
{
- uint8_t cmd_buf[sizeof(struct hal_cmd_le_test_mode) + len];
+ char cmd_buf[BLUEZ_HAL_MTU];
struct hal_cmd_le_test_mode *cmd = (void *) cmd_buf;
+ size_t len;
- DBG("opcode %u len %u", opcode, len);
+ DBG("opcode %u len %u", opcode, buf_len);
if (!interface_ready())
return BT_STATUS_NOT_READY;
cmd->opcode = opcode;
- cmd->len = len;
+ cmd->len = buf_len;
memcpy(cmd->data, buf, cmd->len);
+ len = sizeof(*cmd) + cmd->len;
+
return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_LE_TEST_MODE,
- sizeof(cmd_buf), cmd, 0, NULL, NULL);
+ len, cmd, 0, NULL, NULL);
}
static int config_hci_snoop_log(uint8_t enable)
--
1.9.0
^ permalink raw reply related
* [PATCH 2/2] android/hal-handsfree: Use fixed size buffers for commands
From: Szymon Janc @ 2014-02-19 20:49 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1392842978-29373-1-git-send-email-szymon.janc@gmail.com>
This make code follow same conventions for all commands and simplify
code.
---
android/hal-handsfree.c | 90 +++++++++++++++----------------------------------
1 file changed, 27 insertions(+), 63 deletions(-)
diff --git a/android/hal-handsfree.c b/android/hal-handsfree.c
index 601c14f..7964c7d 100644
--- a/android/hal-handsfree.c
+++ b/android/hal-handsfree.c
@@ -360,9 +360,9 @@ static bt_status_t device_status_notification(bthf_network_state_t state,
static bt_status_t cops_response(const char *cops)
{
- struct hal_cmd_handsfree_cops_response *cmd;
- bt_status_t status;
- int len;
+ char buf[BLUEZ_HAL_MTU];
+ struct hal_cmd_handsfree_cops_response *cmd = (void *) buf;
+ size_t len;
DBG("");
@@ -372,22 +372,14 @@ static bt_status_t cops_response(const char *cops)
if (!cops)
return BT_STATUS_PARM_INVALID;
- len = sizeof(*cmd) + strlen(cops);
-
- cmd = malloc(len);
- if (!cmd)
- return BT_STATUS_NOMEM;
-
cmd->len = strlen(cops);
memcpy(cmd->buf, cops, cmd->len);
- status = hal_ipc_cmd(HAL_SERVICE_ID_HANDSFREE,
- HAL_OP_HANDSFREE_COPS_RESPONSE, len, cmd, 0,
- NULL, NULL);
-
- free(cmd);
+ len = sizeof(*cmd) + cmd->len;
- return status;
+ return hal_ipc_cmd(HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_COPS_RESPONSE,
+ len, cmd, 0, NULL, NULL);
}
static bt_status_t cind_response(int svc, int num_active, int num_held,
@@ -416,9 +408,9 @@ static bt_status_t cind_response(int svc, int num_active, int num_held,
static bt_status_t formatted_at_response(const char *rsp)
{
- struct hal_cmd_handsfree_formatted_at_response *cmd;
- bt_status_t status;
- int len;
+ char buf[BLUEZ_HAL_MTU];
+ struct hal_cmd_handsfree_formatted_at_response *cmd = (void *) buf;
+ size_t len;
DBG("");
@@ -428,22 +420,14 @@ static bt_status_t formatted_at_response(const char *rsp)
if (!rsp)
return BT_STATUS_PARM_INVALID;
- len = sizeof(*cmd) + strlen(rsp);
-
- cmd = malloc(len);
- if (!cmd)
- return BT_STATUS_NOMEM;
-
cmd->len = strlen(rsp);
memcpy(cmd->buf, rsp, cmd->len);
- status = hal_ipc_cmd(HAL_SERVICE_ID_HANDSFREE,
- HAL_OP_HANDSFREE_FORMATTED_AT_RESPONSE, len,
- cmd, 0, NULL, NULL);
-
- free(cmd);
+ len = sizeof(*cmd) + cmd->len;
- return status;
+ return hal_ipc_cmd(HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_FORMATTED_AT_RESPONSE,
+ len, cmd, 0, NULL, NULL);
}
static bt_status_t at_response(bthf_at_response_t response, int error)
@@ -470,23 +454,15 @@ static bt_status_t clcc_response(int index, bthf_call_direction_t dir,
const char *number,
bthf_call_addrtype_t type)
{
- struct hal_cmd_handsfree_clcc_response *cmd;
- bt_status_t status;
- int len;
+ char buf[BLUEZ_HAL_MTU];
+ struct hal_cmd_handsfree_clcc_response *cmd = (void *) buf;
+ size_t len;
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
- len = sizeof(*cmd);
- if (number)
- len += strlen(number);
-
- cmd = malloc(len);
- if (!cmd)
- return BT_STATUS_NOMEM;
-
cmd->index = index;
cmd->dir = dir;
cmd->state = state;
@@ -501,13 +477,11 @@ static bt_status_t clcc_response(int index, bthf_call_direction_t dir,
cmd->number_len = 0;
}
- status = hal_ipc_cmd(HAL_SERVICE_ID_HANDSFREE,
- HAL_OP_HANDSFREE_CLCC_RESPONSE, len,
- cmd, 0, NULL, NULL);
-
- free(cmd);
+ len = sizeof(*cmd) + cmd->number_len;
- return status;
+ return hal_ipc_cmd(HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_CLCC_RESPONSE,
+ len, cmd, 0, NULL, NULL);
}
static bt_status_t phone_state_change(int num_active, int num_held,
@@ -515,23 +489,15 @@ static bt_status_t phone_state_change(int num_active, int num_held,
const char *number,
bthf_call_addrtype_t type)
{
- struct hal_cmd_handsfree_phone_state_change *cmd;
- bt_status_t status;
- int len;
+ char buf[BLUEZ_HAL_MTU];
+ struct hal_cmd_handsfree_phone_state_change *cmd = (void *) buf;
+ size_t len;
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
- len = sizeof(*cmd);
- if (number)
- len += strlen(number);
-
- cmd = malloc(len);
- if (!cmd)
- return BT_STATUS_NOMEM;
-
cmd->num_active = num_active;
cmd->num_held = num_held;
cmd->state = state;
@@ -544,13 +510,11 @@ static bt_status_t phone_state_change(int num_active, int num_held,
cmd->number_len = 0;
}
- status = hal_ipc_cmd(HAL_SERVICE_ID_HANDSFREE,
+ len = sizeof(*cmd) + cmd->number_len;
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_HANDSFREE,
HAL_OP_HANDSFREE_PHONE_STATE_CHANGE,
len, cmd, 0, NULL, NULL);
-
- free(cmd);
-
- return status;
}
static void cleanup(void)
--
1.9.0
^ permalink raw reply related
* Re: [PATCH] hog: Fill ev.u.create.{phys,uniq} for UHID_CREATE
From: Petri Gynther @ 2014-02-19 21:15 UTC (permalink / raw)
To: Szymon Janc, Johan Hedberg; +Cc: linux-bluetooth
In-Reply-To: <3638568.rUrzPLdPh8@athlon>
I used hogdev->device directly in:
http://marc.info/?l=linux-bluetooth&m=139105411019568&w=2
But Johan commented on that:
http://marc.info/?l=linux-bluetooth&m=139228316405777&w=2
So that's why I went this route and added name, src, dst.
-- Petri
On Wed, Feb 19, 2014 at 12:30 PM, Szymon Janc <szymon.janc@gmail.com> wrote:
> Hi Petri,
>
> On Wednesday 19 February 2014 12:15:45 Petri Gynther wrote:
>> Fill ev.u.create.{phys,uniq} fields when uHID device is created.
>> These values are copied to kernel hid_device structure.
>>
>> linux/include/linux/hid.h:
>> struct hid_device {
>> ...
>> char name[128]; /* Device name */
>> char phys[64]; /* Device physical location */
>> char uniq[64]; /* Device unique identifier (serial #) */
>> ---
>> profiles/input/hog.c | 7 +++++++
>> 1 file changed, 7 insertions(+)
>>
>> diff --git a/profiles/input/hog.c b/profiles/input/hog.c
>> index b9a14b9..35b973b 100644
>> --- a/profiles/input/hog.c
>> +++ b/profiles/input/hog.c
>> @@ -92,6 +92,8 @@ struct hog_device {
>> uint16_t ctrlpt_handle;
>> uint8_t flags;
>> char *name;
>> + bdaddr_t src;
>> + bdaddr_t dst;
>> };
>>
>
> struct hog_device already holds reference to btd_device and both src and dst
> can be taken from it where needed. No need to extend struct hog_device.
>
> BTW same goes with name member which could be removed.
>
>> struct report {
>> @@ -396,6 +398,8 @@ static void report_map_read_cb(guint8 status, const
>> guint8 *pdu, guint16 plen, strncpy((char *) ev.u.create.name, hogdev->name
>> ?
>> hogdev->name : "bluez-hog-device",
>> sizeof(ev.u.create.name) - 1);
>> + ba2str(&hogdev->src, (char *) ev.u.create.phys);
>> + ba2str(&hogdev->dst, (char *) ev.u.create.uniq);
>> ev.u.create.vendor = vendor;
>> ev.u.create.product = product;
>> ev.u.create.version = version;
>> @@ -724,6 +728,7 @@ static void attio_disconnected_cb(gpointer user_data)
>> static struct hog_device *hog_new_device(struct btd_device *device,
>> uint16_t id)
>> {
>> + struct btd_adapter *adapter = device_get_adapter(device);
>> struct hog_device *hogdev;
>> char name[HCI_MAX_NAME_LENGTH + 1];
>>
>> @@ -736,6 +741,8 @@ static struct hog_device *hog_new_device(struct
>> btd_device *device, device_get_name(device, name, sizeof(name));
>> if (strlen(name) > 0)
>> hogdev->name = g_strdup(name);
>> + bacpy(&hogdev->src, btd_adapter_get_address(adapter));
>> + bacpy(&hogdev->dst, device_get_address(device));
>>
>> return hogdev;
>> }
>
> --
> Szymon K. Janc
> szymon.janc@gmail.com
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox