* [PATCH BlueZ 4/5] lib: Use SDP_IS_TEXT_STR()/SDP_IS_SEQ() where possible
From: Anderson Lizardo @ 2013-01-07 11:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Anderson Lizardo
In-Reply-To: <1357559795-22090-1-git-send-email-anderson.lizardo@openbossa.org>
---
lib/sdp.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/lib/sdp.c b/lib/sdp.c
index 2dac6c7..ca474cd 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -570,7 +570,7 @@ static void extract_svclass_uuid(sdp_data_t *data, uuid_t *uuid)
{
sdp_data_t *d;
- if (!data || data->dtd < SDP_SEQ8 || data->dtd > SDP_SEQ32)
+ if (!data || !SDP_IS_SEQ(data->dtd))
return;
d = data->val.dataseq;
@@ -1912,7 +1912,7 @@ int sdp_get_uuidseq_attr(const sdp_record_t *rec, uint16_t attr,
sdp_data_t *sdpdata = sdp_data_get(rec, attr);
*seqp = NULL;
- if (sdpdata && sdpdata->dtd >= SDP_SEQ8 && sdpdata->dtd <= SDP_SEQ32) {
+ if (sdpdata && SDP_IS_SEQ(sdpdata->dtd)) {
sdp_data_t *d;
for (d = sdpdata->val.dataseq; d; d = d->next) {
uuid_t *u;
@@ -2128,9 +2128,7 @@ int sdp_get_string_attr(const sdp_record_t *rec, uint16_t attrid, char *value,
sdp_data_t *sdpdata = sdp_data_get(rec, attrid);
if (sdpdata)
/* Verify that it is what the caller expects */
- if (sdpdata->dtd == SDP_TEXT_STR8 ||
- sdpdata->dtd == SDP_TEXT_STR16 ||
- sdpdata->dtd == SDP_TEXT_STR32)
+ if (SDP_IS_TEXT_STR(sdpdata->dtd))
if ((int) strlen(sdpdata->val.str) < valuelen) {
strcpy(value, sdpdata->val.str);
return 0;
@@ -4744,7 +4742,7 @@ int sdp_get_supp_feat(const sdp_record_t *rec, sdp_list_t **seqp)
sdpdata = sdp_data_get(rec, SDP_ATTR_SUPPORTED_FEATURES_LIST);
- if (!sdpdata || sdpdata->dtd < SDP_SEQ8 || sdpdata->dtd > SDP_SEQ32)
+ if (!sdpdata || !SDP_IS_SEQ(sdpdata->dtd))
return sdp_get_uuidseq_attr(rec,
SDP_ATTR_SUPPORTED_FEATURES_LIST, seqp);
@@ -4752,7 +4750,7 @@ int sdp_get_supp_feat(const sdp_record_t *rec, sdp_list_t **seqp)
sdp_data_t *dd;
sdp_list_t *subseq;
- if (d->dtd < SDP_SEQ8 || d->dtd > SDP_SEQ32)
+ if (!SDP_IS_SEQ(d->dtd))
goto fail;
subseq = NULL;
--
1.7.9.5
^ permalink raw reply related
* [PATCH BlueZ 5/5] health: Use SDP_IS_TEXT_STR()/SDP_IS_SEQ() where possible
From: Anderson Lizardo @ 2013-01-07 11:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Anderson Lizardo
In-Reply-To: <1357559795-22090-1-git-send-email-anderson.lizardo@openbossa.org>
---
profiles/health/hdp_util.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/profiles/health/hdp_util.c b/profiles/health/hdp_util.c
index 5799ae5..5f81806 100644
--- a/profiles/health/hdp_util.c
+++ b/profiles/health/hdp_util.c
@@ -767,15 +767,13 @@ static gboolean get_mdep_from_rec(const sdp_record_t *rec, uint8_t role,
return TRUE;
list = sdp_data_get(rec, SDP_ATTR_SUPPORTED_FEATURES_LIST);
- if (list == NULL || (list->dtd != SDP_SEQ8 && list->dtd != SDP_SEQ16 &&
- list->dtd != SDP_SEQ32))
+ if (list == NULL || !SDP_IS_SEQ(list->dtd))
return FALSE;
for (feat = list->val.dataseq; feat; feat = feat->next) {
sdp_data_t *data_type, *mdepid, *role_t, *desc_t;
- if (feat->dtd != SDP_SEQ8 && feat->dtd != SDP_SEQ16 &&
- feat->dtd != SDP_SEQ32)
+ if (!SDP_IS_SEQ(feat->dtd))
continue;
mdepid = feat->val.dataseq;
@@ -803,10 +801,8 @@ static gboolean get_mdep_from_rec(const sdp_record_t *rec, uint8_t role,
if (mdep != NULL)
*mdep = mdepid->val.uint8;
- if (desc != NULL && desc_t != NULL &&
- (desc_t->dtd == SDP_TEXT_STR8 ||
- desc_t->dtd == SDP_TEXT_STR16 ||
- desc_t->dtd == SDP_TEXT_STR32))
+ if (desc != NULL && desc_t != NULL &&
+ SDP_IS_TEXT_STR(desc_t->dtd))
*desc = g_strdup(desc_t->val.str);
return TRUE;
@@ -887,8 +883,7 @@ static gboolean get_prot_desc_entry(sdp_data_t *entry, int type, guint16 *val)
sdp_data_t *iter;
int proto;
- if (entry == NULL || (entry->dtd != SDP_SEQ8 &&
- entry->dtd != SDP_SEQ16 && entry->dtd != SDP_SEQ32))
+ if (entry == NULL || !SDP_IS_SEQ(entry->dtd))
return FALSE;
iter = entry->val.dataseq;
@@ -920,8 +915,7 @@ static gboolean hdp_get_prot_desc_list(const sdp_record_t *rec, guint16 *psm,
return TRUE;
pdl = sdp_data_get(rec, SDP_ATTR_PROTO_DESC_LIST);
- if (pdl == NULL || (pdl->dtd != SDP_SEQ8 && pdl->dtd != SDP_SEQ16 &&
- pdl->dtd != SDP_SEQ32))
+ if (pdl == NULL || !SDP_IS_SEQ(pdl->dtd))
return FALSE;
p0 = pdl->val.dataseq;
--
1.7.9.5
^ permalink raw reply related
* Re: [PATCH BlueZ 4/4] input: Validate SDP HIDDescriptorList subattributes
From: Anderson Lizardo @ 2013-01-07 11:59 UTC (permalink / raw)
To: Anderson Lizardo, linux-bluetooth
In-Reply-To: <20130107082734.GA8075@x220.ger.corp.intel.com>
Hi Johan,
On Mon, Jan 7, 2013 at 4:27 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
>> + if (d->dtd < SDP_SEQ8 || d->dtd > SDP_SEQ32)
>> + goto invalid_desc;
>
> Please always be explicit on what values you're checking for instead of
> assuming that the reader of the code knows what's contained within some
> range. In this case there's already a convenient SDP_IS_SEQ() macro you
> could use.
>
>> + if (d->dtd < SDP_SEQ8 || d->dtd > SDP_SEQ32)
>> + goto invalid_desc;
>
> Same here.
>
>> + if (!d || d->dtd < SDP_TEXT_STR8 || d->dtd > SDP_TEXT_STR32)
>> + goto invalid_desc;
>
> I suppose the best way to handle this one is to add a SDP_IS_STR() macro
> (in a separate patch) to lib/sdp.h and then use it in this patch.
Just sent a couple of patches fixing these problems and similar ones
in lib/sdp.c and health plugin source.
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH BlueZ 1/5] lib: Add SDP_IS_TEXT_STR() macro for SDP_TEXT_STR* checking
From: Johan Hedberg @ 2013-01-07 12:18 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: linux-bluetooth
In-Reply-To: <1357559795-22090-1-git-send-email-anderson.lizardo@openbossa.org>
Hi Lizardo,
On Mon, Jan 07, 2013, Anderson Lizardo wrote:
> This new macro avoids constructs like "if (d->dtd < SDP_TEXT_STR8 ||
> d->dtd > SDP_TEXT_STR32)" which are harder to read.
> ---
> lib/sdp.h | 2 ++
> 1 file changed, 2 insertions(+)
All patches in this set have been applied. Thanks.
Johan
^ permalink raw reply
* [PATCH 1/2] audio: Replace g_hash_table_contains() with g_hash_table_lookup()
From: Jaganath Kanakkassery @ 2013-01-07 12:33 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Jaganath Kanakkassery
g_hash_table_contains() is supported only from GLib 2.32. If BlueZ has to
build against GLib 2.28 this patch replaces g_hash_table_contains() to
g_hash_table_lookup()
---
profiles/audio/player.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/profiles/audio/player.c b/profiles/audio/player.c
index 8748893..4198bdb 100644
--- a/profiles/audio/player.c
+++ b/profiles/audio/player.c
@@ -172,8 +172,13 @@ static gboolean get_status(const GDBusPropertyTable *property,
static gboolean setting_exists(const GDBusPropertyTable *property, void *data)
{
struct media_player *mp = data;
+ const char *value;
+
+ value = g_hash_table_lookup(mp->settings, property->name);
+ if (value == NULL)
+ return FALSE;
- return g_hash_table_contains(mp->settings, property->name);
+ return TRUE;
}
static gboolean get_setting(const GDBusPropertyTable *property,
--
1.7.9.5
^ permalink raw reply related
* [PATCH 2/2] shared: Fix build break
From: Jaganath Kanakkassery @ 2013-01-07 12:33 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Jaganath Kanakkassery
In-Reply-To: <1357562033-26230-1-git-send-email-jaganath.k@samsung.com>
This patch fixes the below build error
src/shared/mgmt.c: In function ‘mgmt_cancel_index’:
src/shared/mgmt.c:559:30: error: cast to pointer from integer of
different size [-Werror=int-to-pointer-cast]
cc1: all warnings being treated as errors
make[1]: *** [src/shared/bluetoothd-mgmt.o] Error 1
make: *** [all] Error 2
---
src/shared/mgmt.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index 2297caf..c832a88 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
@@ -553,10 +553,12 @@ bool mgmt_cancel(struct mgmt *mgmt, unsigned int id)
bool mgmt_cancel_index(struct mgmt *mgmt, uint16_t index)
{
+ guint id = index;
+
if (!mgmt)
return false;
- return cancel_request(mgmt, GUINT_TO_POINTER(index),
+ return cancel_request(mgmt, GUINT_TO_POINTER(id),
compare_request_index);
}
--
1.7.9.5
^ permalink raw reply related
* Re: [PATCH 1/2] audio: Replace g_hash_table_contains() with g_hash_table_lookup()
From: Ludek Finstrle @ 2013-01-07 13:12 UTC (permalink / raw)
To: Jaganath Kanakkassery; +Cc: linux-bluetooth
In-Reply-To: <1357562033-26230-1-git-send-email-jaganath.k@samsung.com>
Hello,
Mon, Jan 07, 2013 at 06:03:52PM +0530, Jaganath Kanakkassery napsal(a):
> g_hash_table_contains() is supported only from GLib 2.32. If BlueZ has to
> build against GLib 2.28 this patch replaces g_hash_table_contains() to
> g_hash_table_lookup()
> ---
> profiles/audio/player.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/profiles/audio/player.c b/profiles/audio/player.c
> index 8748893..4198bdb 100644
> --- a/profiles/audio/player.c
> +++ b/profiles/audio/player.c
> @@ -172,8 +172,13 @@ static gboolean get_status(const GDBusPropertyTable *property,
> static gboolean setting_exists(const GDBusPropertyTable *property, void *data)
> {
> struct media_player *mp = data;
> + const char *value;
> +
> + value = g_hash_table_lookup(mp->settings, property->name);
> + if (value == NULL)
> + return FALSE;
>
> - return g_hash_table_contains(mp->settings, property->name);
> + return TRUE;
> }
Doesn't
return g_hash_table_lookup(mp->settings, property->name) != NULL;
do the same? Maybe it's againist some code style but looks better
than several lines.
Luf
^ permalink raw reply
* Re: [PATCH 1/2] audio: Replace g_hash_table_contains() with g_hash_table_lookup()
From: Jaganath Kanakkassery @ 2013-01-07 13:52 UTC (permalink / raw)
To: Ludek Finstrle; +Cc: linux-bluetooth
In-Reply-To: <20130107131215.GC914@pzkagis.cz>
Hi Ludek,
--------------------------------------------------
From: "Ludek Finstrle" <luf@pzkagis.cz>
Sent: Monday, January 07, 2013 6:42 PM
To: "Jaganath Kanakkassery" <jaganath.k@samsung.com>
Cc: <linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH 1/2] audio: Replace g_hash_table_contains() with
g_hash_table_lookup()
> Hello,
>
> Mon, Jan 07, 2013 at 06:03:52PM +0530, Jaganath Kanakkassery napsal(a):
>> g_hash_table_contains() is supported only from GLib 2.32. If BlueZ has to
>> build against GLib 2.28 this patch replaces g_hash_table_contains() to
>> g_hash_table_lookup()
>> ---
>> profiles/audio/player.c | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/profiles/audio/player.c b/profiles/audio/player.c
>> index 8748893..4198bdb 100644
>> --- a/profiles/audio/player.c
>> +++ b/profiles/audio/player.c
>> @@ -172,8 +172,13 @@ static gboolean get_status(const GDBusPropertyTable
>> *property,
>> static gboolean setting_exists(const GDBusPropertyTable *property, void
>> *data)
>> {
>> struct media_player *mp = data;
>> + const char *value;
>> +
>> + value = g_hash_table_lookup(mp->settings, property->name);
>> + if (value == NULL)
>> + return FALSE;
>>
>> - return g_hash_table_contains(mp->settings, property->name);
>> + return TRUE;
>> }
>
> Doesn't
>
> return g_hash_table_lookup(mp->settings, property->name) != NULL;
>
> do the same? Maybe it's againist some code style but looks better
> than several lines.
I think
return g_hash_table_lookup(mp->settings, property->name) ? TRUE : FALSE;
would be better?
Thanks,
Jaganath
^ permalink raw reply
* Re: [PATCH] adapter: Fix storage to be used by BlueZ 4 or 5
From: Johan Hedberg @ 2013-01-07 14:20 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1357556011-9493-1-git-send-email-frederic.danis@linux.intel.com>
Hi Frédéric,
On Mon, Jan 07, 2013, Frédéric Danis wrote:
> Conversion should be performed only one time, but using "converted"
> entry in device related files generates a bogus device object with
> dev_CONVERTED path when starting BlueZ 4.
>
> If "settings" file has been created we've done the conversion and
> we can use it to check if conversion has already been done.
>
> Remove "converted" entries in converted files
> ---
> src/adapter.c | 177 +++++++++++++++++++++++++++++++--------------------------
> 1 file changed, 95 insertions(+), 82 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply
* Security Block w/ PAN Profile
From: Birchler, Neil @ 2013-01-07 15:16 UTC (permalink / raw)
To: linux-bluetooth@vger.kernel.org
Greetings,
I'm working on using PAN to communicate between Android devices and an embedded system. I have successfully used BlueZ 4.60 for quite some time, but our embedded system's BSP has rolled from 4.60 to 4.98. When I try to use the same connection methodology we've been using successfully with 4.98, I get 'Security Block' errors and the PAN connection doesn't come up. I've attached the output of hcidump, as well as the syslog output with debugging turned on for bluetoothd. Any advice on where to look would be appreciated, as I'm out of ideas.
Thanks,
Neil Birchler
nbirchler@staudertech.com
hcidump output:
HCI sniffer - Bluetooth packet analyzer ver 2.5
device: hci0 snap_len: 1500 filter: 0xffffffff
2013-01-01 19:41:47.711831 > HCI Event: Connect Request (0x04) plen 10
bdaddr 0C:71:5D:35:35:35 class 0x5a020c type ACL
2013-01-01 19:41:47.712014 < HCI Command: Accept Connection Request (0x01|0x0009) plen 7
bdaddr 0C:71:5D:35:35:35 role 0x01
Role: Slave
2013-01-01 19:41:47.721829 > HCI Event: Command Status (0x0f) plen 4
Accept Connection Request (0x01|0x0009) status 0x00 ncmd 1
2013-01-01 19:41:47.871794 > HCI Event: Connect Complete (0x03) plen 11
status 0x00 handle 37 bdaddr 0C:71:5D:35:35:35 type ACL encrypt 0x00
2013-01-01 19:41:47.871943 < HCI Command: Read Remote Supported Features (0x01|0x001b) plen 2
handle 37
2013-01-01 19:41:47.882232 > HCI Event: Page Scan Repetition Mode Change (0x20) plen 7
bdaddr 0C:71:5D:35:35:35 mode 0
2013-01-01 19:41:47.882430 > HCI Event: Command Status (0x0f) plen 4
Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 0
2013-01-01 19:41:47.901891 > HCI Event: Max Slots Change (0x1b) plen 3
handle 37 slots 5
2013-01-01 19:41:47.911813 > HCI Event: Command Status (0x0f) plen 4
Unknown (0x00|0x0000) status 0x00 ncmd 1
2013-01-01 19:41:47.921815 > HCI Event: Read Remote Supported Features (0x0b) plen 11
status 0x00 handle 37
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
2013-01-01 19:41:47.921947 < HCI Command: Read Remote Extended Features (0x01|0x001c) plen 3
handle 37 page 1
2013-01-01 19:41:47.932331 > HCI Event: Command Status (0x0f) plen 4
Read Remote Extended Features (0x01|0x001c) status 0x00 ncmd 1
2013-01-01 19:41:47.932518 > HCI Event: Read Remote Extended Features (0x23) plen 13
status 0x00 handle 37 page 1 max 1
Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
2013-01-01 19:41:47.941841 > HCI Event: Link Key Request (0x17) plen 6
bdaddr 0C:71:5D:35:35:35
2013-01-01 19:41:47.946631 < HCI Command: Link Key Request Reply (0x01|0x000b) plen 22
bdaddr 0C:71:5D:35:35:35 key F76F28010A620BC0651BF18AE4B26B3C
2013-01-01 19:41:47.961757 > HCI Event: Command Complete (0x0e) plen 10
Link Key Request Reply (0x01|0x000b) ncmd 1
status 0x00 bdaddr 0C:71:5D:35:35:35
2013-01-01 19:41:47.991743 > HCI Event: Encrypt Change (0x08) plen 4
status 0x00 handle 37 encrypt 0x01
2013-01-01 19:41:48.021733 > ACL data: handle 37 flags 0x02 dlen 10
L2CAP(s): Info req: type 2
2013-01-01 19:41:48.021850 < ACL data: handle 37 flags 0x02 dlen 16
L2CAP(s): Info rsp: type 2 result 0
Extended feature mask 0x0080
Fixed Channels
2013-01-01 19:41:48.051737 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 37 packets 1
2013-01-01 19:41:48.051902 > ACL data: handle 37 flags 0x02 dlen 10
L2CAP(s): Info req: type 3
2013-01-01 19:41:48.051977 < ACL data: handle 37 flags 0x02 dlen 20
L2CAP(s): Info rsp: type 3 result 0
Fixed channel list 0x00000002
L2CAP Signalling Channel
2013-01-01 19:41:48.061818 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 37 packets 1
2013-01-01 19:41:48.061973 > ACL data: handle 37 flags 0x02 dlen 12
L2CAP(s): Connect req: psm 15 scid 0x0040
2013-01-01 19:41:48.062106 < ACL data: handle 37 flags 0x02 dlen 16
L2CAP(s): Connect rsp: dcid 0x0040 scid 0x0040 result 1 status 0
Connection pending - No futher information available
2013-01-01 19:41:48.062320 < ACL data: handle 37 flags 0x02 dlen 10
L2CAP(s): Info req: type 2
2013-01-01 19:41:48.091761 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 37 packets 1
2013-01-01 19:41:48.091925 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 37 packets 1
2013-01-01 19:41:48.101725 > ACL data: handle 37 flags 0x02 dlen 16
L2CAP(s): Info rsp: type 2 result 0
Extended feature mask 0x0018
Enhanced Retransmission mode
Streaming mode
2013-01-01 19:41:48.101880 < HCI Command: Authentication Requested (0x01|0x0011) plen 2
handle 37
2013-01-01 19:41:48.102005 < ACL data: handle 37 flags 0x02 dlen 16
L2CAP(s): Connect rsp: dcid 0x0040 scid 0x0040 result 1 status 1
Connection pending - Authentication pending
2013-01-01 19:41:48.111773 > HCI Event: Command Status (0x0f) plen 4
Authentication Requested (0x01|0x0011) status 0x00 ncmd 1
2013-01-01 19:41:48.111941 > HCI Event: Link Key Request (0x17) plen 6
bdaddr 0C:71:5D:35:35:35
2013-01-01 19:41:48.112969 < ACL data: handle 37 flags 0x02 dlen 16
L2CAP(s): Connect rsp: dcid 0x0040 scid 0x0040 result 3 status 0
Connection refused - security block
2013-01-01 19:41:48.115041 < HCI Command: Link Key Request Reply (0x01|0x000b) plen 22
bdaddr 0C:71:5D:35:35:35 key F76F28010A620BC0651BF18AE4B26B3C
2013-01-01 19:41:48.132281 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 37 packets 1
2013-01-01 19:41:48.132448 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 37 packets 1
2013-01-01 19:41:48.132569 > HCI Event: Command Complete (0x0e) plen 10
Link Key Request Reply (0x01|0x000b) ncmd 1
status 0x00 bdaddr 0C:71:5D:35:35:35
2013-01-01 19:41:48.151736 > HCI Event: Auth Complete (0x06) plen 3
status 0x00 handle 37
2013-01-01 19:41:48.151877 < ACL data: handle 37 flags 0x02 dlen 16
L2CAP(s): Connect rsp: dcid 0x0040 scid 0x0040 result 0 status 0
Connection successful
2013-01-01 19:41:48.171738 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 37 packets 1
2013-01-01 19:41:48.171942 > ACL data: handle 37 flags 0x02 dlen 10
L2CAP(s): Command rej: reason 0
Command not understood
2013-01-01 19:41:50.221777 > HCI Event: Disconn Complete (0x05) plen 4
status 0x00 handle 37 reason 0x13
Reason: Remote User Terminated Connection
syslog output:
Jan 1 19:41:47 (none) daemon.debug bluetoothd[784]: src/adapter.c:adapter_get_device() 0C:71:5D:35:35:35
Jan 1 19:41:47 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:remote_features_information() hci0 status 0
Jan 1 19:41:47 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:link_key_request() hci0 dba 0C:71:5D:35:35:35
Jan 1 19:41:47 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:get_auth_info() hci0 dba 0C:71:5D:35:35:35
Jan 1 19:41:47 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:link_key_request() kernel auth requirements = 0x04
Jan 1 19:41:47 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:link_key_request() Matching key found
Jan 1 19:41:47 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:link_key_request() link key type 0x05
Jan 1 19:41:48 (none) daemon.debug bluetoothd[784]: network/server.c:confirm_event() BNEP: incoming connect from 0C:71:5D:35:35:35
Jan 1 19:41:48 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:link_key_request() hci0 dba 0C:71:5D:35:35:35
Jan 1 19:41:48 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:get_auth_info() hci0 dba 0C:71:5D:35:35:35
Jan 1 19:41:48 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:link_key_request() kernel auth requirements = 0x04
Jan 1 19:41:48 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:link_key_request() Matching key found
Jan 1 19:41:48 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:link_key_request() link key type 0x05
Jan 1 19:41:48 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:auth_complete() hci0 status 0
Jan 1 19:41:48 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:bonding_complete() status 0x00
Jan 1 19:41:48 (none) daemon.debug bluetoothd[784]: src/adapter.c:adapter_get_device() 0C:71:5D:35:35:35
Jan 1 19:41:48 (none) daemon.debug bluetoothd[784]: src/device.c:device_bonding_complete() bonding (nil) status 0x00
Jan 1 19:41:50 (none) daemon.debug bluetoothd[784]: plugins/hciops.c:disconn_complete() handle 37 status 0x00
Jan 1 19:41:50 (none) daemon.debug bluetoothd[784]: src/event.c:btd_event_disconn_complete()
Jan 1 19:41:50 (none) daemon.debug bluetoothd[784]: src/adapter.c:adapter_remove_connection()
This message is a confidential communication from Stauder Technologies. The information contained in this electronic communication, and any attachments thereto, is privileged and confidential and intended solely for use by the addressee(s). Any other use, dissemination, or copying of this electronic communication is strictly prohibited. If this was erroneously sent to you, please notify us immediately at (636) 498-6658.
^ permalink raw reply
* [PATCH 0/9] Battery Profile implementation
From: Paulo Borges @ 2013-01-07 19:40 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Borges
This patch series implements GATT Battery profile, and it is based on
the work of Chen Ganir.
Battery Profile is mandatory for HoG (HID over GATT).
What has been done upon the previous version:
* bugfixes
* new storage schema using key-files
* compliant with object manager
Although I've changed all commits in the series, I just took the
authorship of commits modified meaninfuly.
Chen Ganir (6):
battery: Add GATT Battery Client Service skeleton
battery: Discover Characteristic Descriptors
battery: Get Battery ID
battery: Add Battery to device
battery: Read Battery level characteristic
battery: Add support for notifications
Paulo Borges (3):
battery: Add generic device battery documentation
battery: Implement Generic device battery
battery: Support persistent battery level
Makefile.plugins | 3 +
doc/battery-api.txt | 24 ++
lib/uuid.h | 3 +
profiles/battery/battery.c | 638 ++++++++++++++++++++++++++++++++++++++++++++
src/device.c | 140 ++++++++++
src/device.h | 15 ++
test/test-device | 15 ++
7 files changed, 838 insertions(+)
create mode 100644 doc/battery-api.txt
create mode 100644 profiles/battery/battery.c
--
1.7.9.5
^ permalink raw reply
* [PATCH 1/9] battery: Add generic device battery documentation
From: Paulo Borges @ 2013-01-07 19:40 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Borges
In-Reply-To: <1357587664-16818-1-git-send-email-paulo.borges@openbossa.org>
Add documentation for the generic battery D-Bus interface.
---
doc/battery-api.txt | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100644 doc/battery-api.txt
diff --git a/doc/battery-api.txt b/doc/battery-api.txt
new file mode 100644
index 0000000..9267bbd
--- /dev/null
+++ b/doc/battery-api.txt
@@ -0,0 +1,24 @@
+BlueZ D-Bus Battery API description
+***********************************
+
+ Texas Instruments, Inc. <chen.ganir@ti.com>
+
+Device Battery hierarchy
+========================
+
+Service org.bluez
+Interface org.bluez.Battery1
+Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/BATTYYYY
+
+Methods Refresh()
+
+ Refresh the battery level. If the battery level changed,
+ the Level signal will be sent with the new value.
+
+Properties uint16 Level [readonly]
+
+ Battery level (0-100).
+
+ object Device [readonly]
+
+ Device object that owns the battery.
--
1.7.9.5
^ permalink raw reply related
* [PATCH 2/9] battery: Implement Generic device battery
From: Paulo Borges @ 2013-01-07 19:40 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Borges
In-Reply-To: <1357587664-16818-1-git-send-email-paulo.borges@openbossa.org>
Add implementation for the generic battery in bluetooth device.
This patch adds new D-Bus interface for adding/removing/changing
peer device battery status, allowing management of remote device
batteries.
---
src/device.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/device.h | 15 ++++++
test/test-device | 15 ++++++
3 files changed, 170 insertions(+)
diff --git a/src/device.c b/src/device.c
index 20099e6..bbd0bbf 100644
--- a/src/device.c
+++ b/src/device.c
@@ -187,6 +187,7 @@ struct btd_device {
int8_t rssi;
gint ref;
+ GSList *batteries;
GIOChannel *att_io;
guint cleanup_id;
@@ -331,6 +332,24 @@ static void store_device_info(struct btd_device *device)
device->store_id = g_idle_add(store_device_info_cb, device);
}
+struct btd_battery {
+ uint16_t level;
+ char *path;
+ struct btd_device *device;
+ refresh_battery_cb refresh;
+};
+
+static void battery_free(gpointer user_data)
+{
+ struct btd_battery *b = user_data;
+
+ g_dbus_unregister_interface(btd_get_dbus_connection(), b->path,
+ BATTERY_INTERFACE);
+ btd_device_unref(b->device);
+ g_free(b->path);
+ g_free(b);
+}
+
static void browse_request_free(struct browse_req *req)
{
if (req->listener_id)
@@ -393,6 +412,7 @@ static void device_free(gpointer user_data)
g_slist_free_full(device->primaries, g_free);
g_slist_free_full(device->attios, g_free);
g_slist_free_full(device->attios_offline, g_free);
+ g_slist_free_full(device->batteries, battery_free);
attio_cleanup(device);
@@ -4111,3 +4131,123 @@ void btd_device_set_pnpid(struct btd_device *device, uint16_t source,
store_device_info(device);
}
+
+static DBusMessage *refresh_batt_level(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct btd_battery *b = data;
+
+ if (!b->refresh)
+ return btd_error_not_supported(msg);
+
+ b->refresh(b);
+
+ return dbus_message_new_method_return(msg);
+}
+
+static gboolean battery_property_get_level(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct btd_battery *batt = data;
+ uint16_t level = batt->level;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &level);
+
+ return TRUE;
+}
+
+static gboolean battery_property_get_device(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct btd_battery *batt = data;
+ const char *str = device_get_path(batt->device);
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &str);
+
+ return TRUE;
+}
+
+static GDBusMethodTable battery_methods[] = {
+ { GDBUS_METHOD("Refresh",
+ NULL, NULL,
+ refresh_batt_level) },
+ { }
+};
+
+static const GDBusPropertyTable battery_properties[] = {
+ { "Level", "q", battery_property_get_level },
+ { "Device", "o", battery_property_get_device },
+ { }
+};
+
+struct btd_battery *btd_device_add_battery(struct btd_device *device)
+{
+ struct btd_battery *batt;
+
+ batt = g_new0(struct btd_battery, 1);
+ batt->path = g_strdup_printf("%s/BATT%04X", device->path,
+ g_slist_length(device->batteries));
+
+ if (!g_dbus_register_interface(btd_get_dbus_connection(), batt->path,
+ BATTERY_INTERFACE, battery_methods, NULL,
+ battery_properties, batt, NULL)) {
+ error("D-Bus register interface %s failed", BATTERY_INTERFACE);
+ g_free(batt->path);
+ g_free(batt);
+ return NULL;
+ }
+
+ batt->device = btd_device_ref(device);
+ device->batteries = g_slist_append(device->batteries, batt);
+
+ return batt;
+}
+
+void btd_device_remove_battery(struct btd_battery *batt)
+{
+ struct btd_device *dev = batt->device;
+
+ dev->batteries = g_slist_remove(dev->batteries, batt);
+
+ battery_free(batt);
+}
+
+gboolean btd_device_set_battery_opt(struct btd_battery *batt,
+ battery_option_t opt1, ...)
+{
+ va_list args;
+ battery_option_t opt = opt1;
+ int level;
+
+ if (!batt)
+ return FALSE;
+
+ va_start(args, opt1);
+
+ while (opt != BATTERY_OPT_INVALID) {
+ switch (opt) {
+ case BATTERY_OPT_LEVEL:
+ level = va_arg(args, int);
+ if (level != batt->level) {
+ batt->level = level;
+ g_dbus_emit_property_changed(
+ btd_get_dbus_connection(),
+ batt->path, BATTERY_INTERFACE,
+ "Level");
+ }
+ break;
+ case BATTERY_OPT_REFRESH_FUNC:
+ batt->refresh = va_arg(args, refresh_battery_cb);
+ break;
+ default:
+ error("Unknown option %d", opt);
+ return FALSE;
+ }
+
+ opt = va_arg(args, int);
+ }
+
+ va_end(args);
+
+ return TRUE;
+}
diff --git a/src/device.h b/src/device.h
index ae70690..0f7babd 100644
--- a/src/device.h
+++ b/src/device.h
@@ -23,8 +23,18 @@
*/
#define DEVICE_INTERFACE "org.bluez.Device1"
+#define BATTERY_INTERFACE "org.bluez.Battery1"
struct btd_device;
+struct btd_battery;
+
+typedef void (*refresh_battery_cb) (struct btd_battery *batt);
+
+typedef enum {
+ BATTERY_OPT_INVALID = 0,
+ BATTERY_OPT_LEVEL,
+ BATTERY_OPT_REFRESH_FUNC,
+} battery_option_t;
struct btd_device *device_create(struct btd_adapter *adapter,
const char *address, uint8_t bdaddr_type);
@@ -116,3 +126,8 @@ void device_profile_connected(struct btd_device *dev,
struct btd_profile *profile, int err);
void device_profile_disconnected(struct btd_device *dev,
struct btd_profile *profile, int err);
+
+struct btd_battery *btd_device_add_battery(struct btd_device *device);
+void btd_device_remove_battery(struct btd_battery *batt);
+gboolean btd_device_set_battery_opt(struct btd_battery *batt,
+ battery_option_t opt1, ...);
diff --git a/test/test-device b/test/test-device
index 3d7b852..ee144f1 100755
--- a/test/test-device
+++ b/test/test-device
@@ -27,6 +27,7 @@ if (len(args) < 1):
print("Usage: %s <command>" % (sys.argv[0]))
print("")
print(" list")
+ print(" batteries <address>")
print(" create <address>")
print(" remove <address|path>")
print(" connect <address> [profile]")
@@ -196,5 +197,19 @@ if (args[0] == "blocked"):
props.Set("org.bluez.Device1", "Blocked", value)
sys.exit(0)
+if (args[0] == "batteries"):
+ if (len(args) < 2):
+ print("Need address parameter")
+ else:
+ BATT_INTERFACE = "org.bluez.Battery1"
+ objs = bluezutils.get_managed_objects()
+ device = bluezutils.find_device(args[1], options.dev_id)
+ batteries = [path for path, ifaces in objs.iteritems()
+ if (lambda obj: obj and obj.get("Device") ==
+ device.object_path)(ifaces.get(BATT_INTERFACE))]
+ for batt in batteries:
+ print(batt)
+ sys.exit(0)
+
print("Unknown command")
sys.exit(1)
--
1.7.9.5
^ permalink raw reply related
* [PATCH 3/9] battery: Add GATT Battery Client Service skeleton
From: Paulo Borges @ 2013-01-07 19:40 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Chen Ganir
In-Reply-To: <1357587664-16818-1-git-send-email-paulo.borges@openbossa.org>
From: Chen Ganir <chen.ganir@ti.com>
Add support for the Battery Service Gatt Client side. Implement
the basic skeleton.
---
Makefile.plugins | 3 +
lib/uuid.h | 2 +
profiles/battery/battery.c | 214 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 219 insertions(+)
create mode 100644 profiles/battery/battery.c
diff --git a/Makefile.plugins b/Makefile.plugins
index faab011..33694b1 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -79,6 +79,9 @@ builtin_sources += profiles/scanparam/scan.c
builtin_modules += deviceinfo
builtin_sources += profiles/deviceinfo/deviceinfo.c
+builtin_modules += battery
+builtin_sources += profiles/battery/battery.c
+
if EXPERIMENTAL
builtin_modules += alert
builtin_sources += profiles/alert/server.c
diff --git a/lib/uuid.h b/lib/uuid.h
index 1e8188a..8736749 100644
--- a/lib/uuid.h
+++ b/lib/uuid.h
@@ -56,6 +56,8 @@ extern "C" {
#define PNPID_UUID "00002a50-0000-1000-8000-00805f9b34fb"
#define DEVICE_INFORMATION_UUID "0000180a-0000-1000-8000-00805f9b34fb"
+#define BATTERY_SERVICE_UUID "0000180f-0000-1000-8000-00805f9b34fb"
+
#define GATT_UUID "00001801-0000-1000-8000-00805f9b34fb"
#define IMMEDIATE_ALERT_UUID "00001802-0000-1000-8000-00805f9b34fb"
#define LINK_LOSS_UUID "00001803-0000-1000-8000-00805f9b34fb"
diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c
new file mode 100644
index 0000000..73c06ff
--- /dev/null
+++ b/profiles/battery/battery.c
@@ -0,0 +1,214 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2012 Texas Instruments, Inc.
+ *
+ * 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 <glib.h>
+#include <bluetooth/uuid.h>
+#include <stdbool.h>
+
+#include "adapter.h"
+#include "device.h"
+#include "profile.h"
+#include "plugin.h"
+#include "attrib/att.h"
+#include "attrib/gattrib.h"
+#include "attrib/gatt.h"
+#include "attio.h"
+#include "log.h"
+
+struct battery {
+ struct btd_device *dev; /* Device reference */
+ GAttrib *attrib; /* GATT connection */
+ guint attioid; /* Att watcher id */
+ struct att_range *svc_range; /* Battery range */
+ GSList *chars; /* Characteristics */
+};
+
+struct characteristic {
+ struct gatt_char attr; /* Characteristic */
+ struct battery *batt; /* Parent Battery Service */
+};
+
+static GSList *servers;
+
+static gint cmp_device(gconstpointer a, gconstpointer b)
+{
+ const struct battery *batt = a;
+ const struct btd_device *dev = b;
+
+ if (dev == batt->dev)
+ return 0;
+
+ return -1;
+}
+
+static void battery_free(gpointer user_data)
+{
+ struct battery *batt = user_data;
+
+ if (batt->chars != NULL)
+ g_slist_free_full(batt->chars, g_free);
+
+ if (batt->attioid > 0)
+ btd_device_remove_attio_callback(batt->dev, batt->attioid);
+
+ if (batt->attrib != NULL)
+ g_attrib_unref(batt->attrib);
+
+ btd_device_unref(batt->dev);
+ g_free(batt);
+}
+
+static void configure_battery_cb(GSList *characteristics, guint8 status,
+ gpointer user_data)
+{
+ struct battery *batt = user_data;
+ GSList *l;
+
+ if (status != 0) {
+ error("Discover Battery characteristics: %s",
+ att_ecode2str(status));
+ return;
+ }
+
+ for (l = characteristics; l; l = l->next) {
+ struct gatt_char *c = l->data;
+ struct characteristic *ch;
+
+ ch = g_new0(struct characteristic, 1);
+ ch->attr.handle = c->handle;
+ ch->attr.properties = c->properties;
+ ch->attr.value_handle = c->value_handle;
+ memcpy(ch->attr.uuid, c->uuid, MAX_LEN_UUID_STR + 1);
+ ch->batt = batt;
+
+ batt->chars = g_slist_append(batt->chars, ch);
+ }
+}
+
+static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
+{
+ struct battery *batt = user_data;
+
+ batt->attrib = g_attrib_ref(attrib);
+
+ if (batt->chars == NULL) {
+ gatt_discover_char(batt->attrib, batt->svc_range->start,
+ batt->svc_range->end, NULL,
+ configure_battery_cb, batt);
+ }
+}
+
+static void attio_disconnected_cb(gpointer user_data)
+{
+ struct battery *batt = user_data;
+
+ g_attrib_unref(batt->attrib);
+ batt->attrib = NULL;
+}
+
+static gint primary_uuid_cmp(gconstpointer a, gconstpointer b)
+{
+ const struct gatt_primary *prim = a;
+ const char *uuid = b;
+
+ return g_strcmp0(prim->uuid, uuid);
+}
+
+static int battery_register(struct btd_device *device)
+{
+ struct battery *batt;
+ struct gatt_primary *prim;
+ GSList *primaries, *l;
+
+ primaries = btd_device_get_primaries(device);
+
+ while ((l = g_slist_find_custom(primaries, BATTERY_SERVICE_UUID,
+ primary_uuid_cmp))) {
+ prim = l->data;
+
+ batt = g_new0(struct battery, 1);
+ batt->dev = btd_device_ref(device);
+
+ batt->svc_range = g_new0(struct att_range, 1);
+ batt->svc_range->start = prim->range.start;
+ batt->svc_range->end = prim->range.end;
+
+ servers = g_slist_prepend(servers, batt);
+
+ batt->attioid = btd_device_add_attio_callback(device,
+ attio_connected_cb, attio_disconnected_cb, batt);
+
+ primaries = g_slist_remove(primaries, prim);
+ }
+
+ return 0;
+}
+
+static void battery_unregister(struct btd_device *device)
+{
+ struct battery *batt;
+ GSList *l;
+
+ while ((l = g_slist_find_custom(servers, device, cmp_device))) {
+ batt = l->data;
+ servers = g_slist_remove(servers, batt);
+
+ battery_free(batt);
+ }
+}
+
+static int battery_driver_probe(struct btd_profile *p,
+ struct btd_device *device,
+ GSList *uuids)
+{
+ return battery_register(device);
+}
+
+static void battery_driver_remove(struct btd_profile *p,
+ struct btd_device *device)
+{
+ battery_unregister(device);
+}
+
+static struct btd_profile battery_profile = {
+ .name = "battery",
+ .remote_uuids = BTD_UUIDS(BATTERY_SERVICE_UUID),
+ .device_probe = battery_driver_probe,
+ .device_remove = battery_driver_remove
+};
+
+static int battery_manager_init(void)
+{
+ return btd_profile_register(&battery_profile);
+}
+
+static void battery_manager_exit(void)
+{
+ btd_profile_unregister(&battery_profile);
+}
+
+BLUETOOTH_PLUGIN_DEFINE(battery, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
+ battery_manager_init, battery_manager_exit)
--
1.7.9.5
^ permalink raw reply related
* [PATCH 4/9] battery: Discover Characteristic Descriptors
From: Paulo Borges @ 2013-01-07 19:40 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Chen Ganir
In-Reply-To: <1357587664-16818-1-git-send-email-paulo.borges@openbossa.org>
From: Chen Ganir <chen.ganir@ti.com>
Discover all characteristic descriptors, and build a descriptor
list. Presentation Format Descriptor and Client Characteristic
Configuration descriptors are searched.
---
profiles/battery/battery.c | 72 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 71 insertions(+), 1 deletion(-)
diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c
index 73c06ff..8e7e4c5 100644
--- a/profiles/battery/battery.c
+++ b/profiles/battery/battery.c
@@ -49,6 +49,13 @@ struct battery {
struct characteristic {
struct gatt_char attr; /* Characteristic */
struct battery *batt; /* Parent Battery Service */
+ GSList *desc; /* Descriptors */
+};
+
+struct descriptor {
+ struct characteristic *ch; /* Parent Characteristic */
+ uint16_t handle; /* Descriptor Handle */
+ bt_uuid_t uuid; /* UUID */
};
static GSList *servers;
@@ -64,12 +71,21 @@ static gint cmp_device(gconstpointer a, gconstpointer b)
return -1;
}
+static void char_free(gpointer user_data)
+{
+ struct characteristic *c = user_data;
+
+ g_slist_free_full(c->desc, g_free);
+
+ g_free(c);
+}
+
static void battery_free(gpointer user_data)
{
struct battery *batt = user_data;
if (batt->chars != NULL)
- g_slist_free_full(batt->chars, g_free);
+ g_slist_free_full(batt->chars, char_free);
if (batt->attioid > 0)
btd_device_remove_attio_callback(batt->dev, batt->attioid);
@@ -78,9 +94,48 @@ static void battery_free(gpointer user_data)
g_attrib_unref(batt->attrib);
btd_device_unref(batt->dev);
+ g_free(batt->svc_range);
g_free(batt);
}
+static void discover_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
+ gpointer user_data)
+{
+ struct characteristic *ch = user_data;
+ struct att_data_list *list;
+ uint8_t format;
+ int i;
+
+ if (status != 0) {
+ error("Discover all characteristic descriptors failed [%s]: %s",
+ ch->attr.uuid, att_ecode2str(status));
+ return;
+ }
+
+ list = dec_find_info_resp(pdu, len, &format);
+ if (list == NULL)
+ return;
+
+ for (i = 0; i < list->num; i++) {
+ struct descriptor *desc;
+ uint8_t *value;
+
+ value = list->data[i];
+ desc = g_new0(struct descriptor, 1);
+ desc->handle = att_get_u16(value);
+ desc->ch = ch;
+
+ if (format == 0x01)
+ desc->uuid = att_get_uuid16(&value[2]);
+ else
+ desc->uuid = att_get_uuid128(&value[2]);
+
+ ch->desc = g_slist_append(ch->desc, desc);
+ }
+
+ att_data_list_free(list);
+}
+
static void configure_battery_cb(GSList *characteristics, guint8 status,
gpointer user_data)
{
@@ -96,6 +151,7 @@ static void configure_battery_cb(GSList *characteristics, guint8 status,
for (l = characteristics; l; l = l->next) {
struct gatt_char *c = l->data;
struct characteristic *ch;
+ uint16_t start, end;
ch = g_new0(struct characteristic, 1);
ch->attr.handle = c->handle;
@@ -105,6 +161,20 @@ static void configure_battery_cb(GSList *characteristics, guint8 status,
ch->batt = batt;
batt->chars = g_slist_append(batt->chars, ch);
+
+ start = c->value_handle + 1;
+
+ if (l->next != NULL) {
+ struct gatt_char *c = l->next->data;
+ if (start == c->handle)
+ continue;
+ end = c->handle - 1;
+ } else if (c->value_handle != batt->svc_range->end)
+ end = batt->svc_range->end;
+ else
+ continue;
+
+ gatt_find_info(batt->attrib, start, end, discover_desc_cb, ch);
}
}
--
1.7.9.5
^ permalink raw reply related
* [PATCH 5/9] battery: Get Battery ID
From: Paulo Borges @ 2013-01-07 19:41 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Chen Ganir
In-Reply-To: <1357587664-16818-1-git-send-email-paulo.borges@openbossa.org>
From: Chen Ganir <chen.ganir@ti.com>
Read the battery level format characteristic descriptor to get the
unique namespace and description values.
---
lib/uuid.h | 1 +
profiles/battery/battery.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/lib/uuid.h b/lib/uuid.h
index 8736749..3abdd44 100644
--- a/lib/uuid.h
+++ b/lib/uuid.h
@@ -57,6 +57,7 @@ extern "C" {
#define DEVICE_INFORMATION_UUID "0000180a-0000-1000-8000-00805f9b34fb"
#define BATTERY_SERVICE_UUID "0000180f-0000-1000-8000-00805f9b34fb"
+#define BATTERY_LEVEL_UUID "00002a19-0000-1000-8000-00805f9b34fb"
#define GATT_UUID "00001801-0000-1000-8000-00805f9b34fb"
#define IMMEDIATE_ALERT_UUID "00001802-0000-1000-8000-00805f9b34fb"
diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c
index 8e7e4c5..8bbfaf7 100644
--- a/profiles/battery/battery.c
+++ b/profiles/battery/battery.c
@@ -50,6 +50,8 @@ struct characteristic {
struct gatt_char attr; /* Characteristic */
struct battery *batt; /* Parent Battery Service */
GSList *desc; /* Descriptors */
+ uint8_t ns; /* Battery Namespace */
+ uint16_t description; /* Battery description */
};
struct descriptor {
@@ -98,6 +100,53 @@ static void battery_free(gpointer user_data)
g_free(batt);
}
+static void batterylevel_presentation_format_desc_cb(guint8 status,
+ const guint8 *pdu, guint16 len,
+ gpointer user_data)
+{
+ struct descriptor *desc = user_data;
+ uint8_t value[ATT_MAX_VALUE_LEN];
+ int vlen;
+
+ if (status != 0) {
+ error("Presentation Format desc read failed: %s",
+ att_ecode2str(status));
+ return;
+ }
+
+ vlen = dec_read_resp(pdu, len, value, sizeof(value));
+ if (vlen < 0) {
+ error("Presentation Format desc read failed: Protocol error");
+ return;
+ }
+
+ if (vlen < 7) {
+ error("Presentation Format desc read failed: Invalid range");
+ return;
+ }
+
+ desc->ch->ns = value[4];
+ desc->ch->description = att_get_u16(&value[5]);
+}
+
+static void process_batterylevel_desc(struct descriptor *desc)
+{
+ struct characteristic *ch = desc->ch;
+ char uuidstr[MAX_LEN_UUID_STR];
+ bt_uuid_t btuuid;
+
+ bt_uuid16_create(&btuuid, GATT_CHARAC_FMT_UUID);
+
+ if (bt_uuid_cmp(&desc->uuid, &btuuid) == 0) {
+ gatt_read_char(ch->batt->attrib, desc->handle,
+ batterylevel_presentation_format_desc_cb, desc);
+ return;
+ }
+
+ bt_uuid_to_string(&desc->uuid, uuidstr, MAX_LEN_UUID_STR);
+ DBG("Ignored descriptor %s characteristic %s", uuidstr, ch->attr.uuid);
+}
+
static void discover_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
gpointer user_data)
{
@@ -131,6 +180,7 @@ static void discover_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
desc->uuid = att_get_uuid128(&value[2]);
ch->desc = g_slist_append(ch->desc, desc);
+ process_batterylevel_desc(desc);
}
att_data_list_free(list);
@@ -153,6 +203,9 @@ static void configure_battery_cb(GSList *characteristics, guint8 status,
struct characteristic *ch;
uint16_t start, end;
+ if (g_strcmp0(c->uuid, BATTERY_LEVEL_UUID) != 0)
+ continue;
+
ch = g_new0(struct characteristic, 1);
ch->attr.handle = c->handle;
ch->attr.properties = c->properties;
--
1.7.9.5
^ permalink raw reply related
* [PATCH 6/9] battery: Add Battery to device
From: Paulo Borges @ 2013-01-07 19:41 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Chen Ganir
In-Reply-To: <1357587664-16818-1-git-send-email-paulo.borges@openbossa.org>
From: Chen Ganir <chen.ganir@ti.com>
Add/Remove battery from device
---
profiles/battery/battery.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c
index 8bbfaf7..fef83d9 100644
--- a/profiles/battery/battery.c
+++ b/profiles/battery/battery.c
@@ -47,6 +47,7 @@ struct battery {
};
struct characteristic {
+ struct btd_battery *devbatt; /* device_battery pointer */
struct gatt_char attr; /* Characteristic */
struct battery *batt; /* Parent Battery Service */
GSList *desc; /* Descriptors */
@@ -79,6 +80,8 @@ static void char_free(gpointer user_data)
g_slist_free_full(c->desc, g_free);
+ btd_device_remove_battery(c->devbatt);
+
g_free(c);
}
@@ -217,6 +220,8 @@ static void configure_battery_cb(GSList *characteristics, guint8 status,
start = c->value_handle + 1;
+ ch->devbatt = btd_device_add_battery(ch->batt->dev);
+
if (l->next != NULL) {
struct gatt_char *c = l->next->data;
if (start == c->handle)
--
1.7.9.5
^ permalink raw reply related
* [PATCH 7/9] battery: Read Battery level characteristic
From: Paulo Borges @ 2013-01-07 19:41 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Chen Ganir
In-Reply-To: <1357587664-16818-1-git-send-email-paulo.borges@openbossa.org>
From: Chen Ganir <chen.ganir@ti.com>
Implement support for reading the battery level characteristic on
connection establishment.
---
profiles/battery/battery.c | 86 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 86 insertions(+)
diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c
index fef83d9..186bb1c 100644
--- a/profiles/battery/battery.c
+++ b/profiles/battery/battery.c
@@ -53,6 +53,7 @@ struct characteristic {
GSList *desc; /* Descriptors */
uint8_t ns; /* Battery Namespace */
uint16_t description; /* Battery description */
+ uint8_t level; /* Battery level */
};
struct descriptor {
@@ -103,6 +104,78 @@ static void battery_free(gpointer user_data)
g_free(batt);
}
+static void read_batterylevel_cb(guint8 status, const guint8 *pdu, guint16 len,
+ gpointer user_data)
+{
+ struct characteristic *ch = user_data;
+ uint8_t value[ATT_MAX_VALUE_LEN];
+ int vlen;
+
+ if (status != 0) {
+ error("Failed to read Battery Level:%s", att_ecode2str(status));
+ return;
+ }
+
+ vlen = dec_read_resp(pdu, len, value, sizeof(value));
+ if (vlen < 0) {
+ error("Failed to read Battery Level: Protocol error");
+ return;
+ }
+
+ if (vlen != 1) {
+ error("Failed to read Battery Level: Wrong pdu len");
+ return;
+ }
+
+ ch->level = value[0];
+ btd_device_set_battery_opt(ch->devbatt, BATTERY_OPT_LEVEL, ch->level,
+ BATTERY_OPT_INVALID);
+}
+
+static void process_batteryservice_char(struct characteristic *ch)
+{
+ if (g_strcmp0(ch->attr.uuid, BATTERY_LEVEL_UUID) == 0) {
+ gatt_read_char(ch->batt->attrib, ch->attr.value_handle,
+ read_batterylevel_cb, ch);
+ }
+}
+
+static gint device_battery_cmp(gconstpointer a, gconstpointer b)
+{
+ const struct characteristic *ch = a;
+ const struct btd_battery *batt = b;
+
+ if (batt == ch->devbatt)
+ return 0;
+
+ return -1;
+}
+
+static struct characteristic *find_battery_char(struct btd_battery *db)
+{
+ GSList *l, *b;
+
+ for (l = servers; l != NULL; l = g_slist_next(l)) {
+ struct battery *batt = l->data;
+
+ b = g_slist_find_custom(batt->chars, db, device_battery_cmp);
+ if (b && batt->attrib)
+ return b->data;
+ }
+
+ return NULL;
+}
+
+static void batterylevel_refresh_cb(struct btd_battery *batt)
+{
+ struct characteristic *ch;
+
+ ch = find_battery_char(batt);
+
+ if (ch)
+ process_batteryservice_char(ch);
+}
+
static void batterylevel_presentation_format_desc_cb(guint8 status,
const guint8 *pdu, guint16 len,
gpointer user_data)
@@ -220,8 +293,15 @@ static void configure_battery_cb(GSList *characteristics, guint8 status,
start = c->value_handle + 1;
+ process_batteryservice_char(ch);
+
ch->devbatt = btd_device_add_battery(ch->batt->dev);
+ btd_device_set_battery_opt(ch->devbatt,
+ BATTERY_OPT_REFRESH_FUNC,
+ batterylevel_refresh_cb,
+ BATTERY_OPT_INVALID);
+
if (l->next != NULL) {
struct gatt_char *c = l->next->data;
if (start == c->handle)
@@ -246,6 +326,12 @@ static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
gatt_discover_char(batt->attrib, batt->svc_range->start,
batt->svc_range->end, NULL,
configure_battery_cb, batt);
+ } else {
+ GSList *l;
+ for (l = batt->chars; l; l = l->next) {
+ struct characteristic *c = l->data;
+ process_batteryservice_char(c);
+ }
}
}
--
1.7.9.5
^ permalink raw reply related
* [PATCH 8/9] battery: Add support for notifications
From: Paulo Borges @ 2013-01-07 19:41 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Chen Ganir
In-Reply-To: <1357587664-16818-1-git-send-email-paulo.borges@openbossa.org>
From: Chen Ganir <chen.ganir@ti.com>
Add support for emitting PropertyChanged when a battery level
characteristic notification is sent from the peer device.
---
profiles/battery/battery.c | 79 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 78 insertions(+), 1 deletion(-)
diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c
index 186bb1c..2ef4f6b 100644
--- a/profiles/battery/battery.c
+++ b/profiles/battery/battery.c
@@ -54,6 +54,8 @@ struct characteristic {
uint8_t ns; /* Battery Namespace */
uint16_t description; /* Battery description */
uint8_t level; /* Battery level */
+ gboolean can_notify; /* Char can notify flag */
+ guint notifyid;
};
struct descriptor {
@@ -79,6 +81,9 @@ static void char_free(gpointer user_data)
{
struct characteristic *c = user_data;
+ if (c->notifyid && c->batt->attrib != NULL)
+ g_attrib_unregister(c->batt->attrib, c->notifyid);
+
g_slist_free_full(c->desc, g_free);
btd_device_remove_battery(c->devbatt);
@@ -140,6 +145,44 @@ static void process_batteryservice_char(struct characteristic *ch)
}
}
+static void proc_batterylevel(struct characteristic *c, const uint8_t *pdu,
+ uint16_t len, gboolean final)
+{
+ if (!pdu) {
+ error("Battery level notification: Invalid pdu length");
+ return;
+ }
+
+ c->level = pdu[1];
+
+ btd_device_set_battery_opt(c->devbatt, BATTERY_OPT_LEVEL, c->level,
+ BATTERY_OPT_INVALID);
+}
+
+static void notif_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
+{
+ struct characteristic *ch = user_data;
+
+ proc_batterylevel(ch, pdu, len, FALSE);
+}
+
+static void batterylevel_enable_notify_cb(guint8 status, const guint8 *pdu,
+ guint16 len, gpointer user_data)
+{
+ struct characteristic *ch = user_data;
+ struct battery *batt = ch->batt;
+
+ if (status != 0) {
+ error("Could not enable batt level notification.");
+ ch->can_notify = FALSE;
+ process_batteryservice_char(ch);
+ }
+
+ ch->notifyid = g_attrib_register(batt->attrib,
+ ATT_OP_HANDLE_NOTIFY, ch->attr.value_handle,
+ notif_handler, ch, NULL);
+}
+
static gint device_battery_cmp(gconstpointer a, gconstpointer b)
{
const struct characteristic *ch = a;
@@ -176,6 +219,21 @@ static void batterylevel_refresh_cb(struct btd_battery *batt)
process_batteryservice_char(ch);
}
+static void enable_battery_notification(struct characteristic *ch,
+ uint16_t handle)
+{
+ uint8_t atval[2];
+ uint16_t val;
+
+ val = GATT_CLIENT_CHARAC_CFG_NOTIF_BIT;
+
+ ch->can_notify = TRUE;
+
+ att_put_u16(val, atval);
+ gatt_write_char(ch->batt->attrib, handle, atval, 2,
+ batterylevel_enable_notify_cb, ch);
+}
+
static void batterylevel_presentation_format_desc_cb(guint8 status,
const guint8 *pdu, guint16 len,
gpointer user_data)
@@ -211,6 +269,14 @@ static void process_batterylevel_desc(struct descriptor *desc)
char uuidstr[MAX_LEN_UUID_STR];
bt_uuid_t btuuid;
+ bt_uuid16_create(&btuuid, GATT_CLIENT_CHARAC_CFG_UUID);
+
+ if (bt_uuid_cmp(&desc->uuid, &btuuid) == 0 && g_strcmp0(ch->attr.uuid,
+ BATTERY_LEVEL_UUID) == 0) {
+ enable_battery_notification(ch, desc->handle);
+ return;
+ }
+
bt_uuid16_create(&btuuid, GATT_CHARAC_FMT_UUID);
if (bt_uuid_cmp(&desc->uuid, &btuuid) == 0) {
@@ -330,7 +396,8 @@ static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
GSList *l;
for (l = batt->chars; l; l = l->next) {
struct characteristic *c = l->data;
- process_batteryservice_char(c);
+ if (!c->can_notify)
+ process_batteryservice_char(c);
}
}
}
@@ -338,6 +405,16 @@ static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
static void attio_disconnected_cb(gpointer user_data)
{
struct battery *batt = user_data;
+ GSList *l;
+
+ for (l = batt->chars; l; l = l->next) {
+ struct characteristic *c = l->data;
+
+ if (c->notifyid) {
+ g_attrib_unregister(batt->attrib, c->notifyid);
+ c->notifyid = 0;
+ }
+ }
g_attrib_unref(batt->attrib);
batt->attrib = NULL;
--
1.7.9.5
^ permalink raw reply related
* [PATCH 9/9] battery: Support persistent battery level
From: Paulo Borges @ 2013-01-07 19:41 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Borges
In-Reply-To: <1357587664-16818-1-git-send-email-paulo.borges@openbossa.org>
Store battery level when read, and use the level from storage
when connecting, to reduce GATT traffic.
---
profiles/battery/battery.c | 137 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 135 insertions(+), 2 deletions(-)
diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c
index 2ef4f6b..e4a6e53 100644
--- a/profiles/battery/battery.c
+++ b/profiles/battery/battery.c
@@ -27,6 +27,8 @@
#include <glib.h>
#include <bluetooth/uuid.h>
#include <stdbool.h>
+#include <sys/file.h>
+#include <stdlib.h>
#include "adapter.h"
#include "device.h"
@@ -37,6 +39,11 @@
#include "attrib/gatt.h"
#include "attio.h"
#include "log.h"
+#include "storage.h"
+
+#define BATTERY_FILE "batteries"
+#define BATTERY_GROUP_FORMAT "%04X"
+#define BATTERY_KEY_LEVEL "Level"
struct battery {
struct btd_device *dev; /* Device reference */
@@ -77,10 +84,133 @@ static gint cmp_device(gconstpointer a, gconstpointer b)
return -1;
}
+static gboolean store_battery_char(struct characteristic *chr)
+{
+ GKeyFile *key_file;
+ char filename[PATH_MAX + 1];
+ char adapter_addr[18];
+ char device_addr[18];
+ char group[5];
+ char *str;
+ gsize length = 0;
+
+ ba2str(adapter_get_address(device_get_adapter(chr->batt->dev)),
+ adapter_addr);
+ ba2str(device_get_address(chr->batt->dev), device_addr);
+
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/" BATTERY_FILE,
+ adapter_addr, device_addr);
+
+ snprintf(group, sizeof(group), BATTERY_GROUP_FORMAT, chr->attr.handle);
+
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
+
+ g_key_file_set_integer(key_file, group, BATTERY_KEY_LEVEL, chr->level);
+
+ create_file(filename, S_IRUSR | S_IWUSR);
+
+ str = g_key_file_to_data(key_file, &length, NULL);
+ g_file_set_contents(filename, str, length, NULL);
+
+ g_free(str);
+ g_key_file_free(key_file);
+
+ return TRUE;
+}
+
+static int read_battery_char(struct characteristic *chr)
+{
+ GKeyFile *key_file;
+ char filename[PATH_MAX + 1];
+ char adapter_addr[18];
+ char device_addr[18];
+ char group[5];
+ int chr_value;
+
+ ba2str(adapter_get_address(device_get_adapter(chr->batt->dev)),
+ adapter_addr);
+ ba2str(device_get_address(chr->batt->dev), device_addr);
+
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/" BATTERY_FILE,
+ adapter_addr, device_addr);
+
+ snprintf(group, sizeof(group), BATTERY_GROUP_FORMAT, chr->attr.handle);
+
+ key_file = g_key_file_new();
+ if (!g_key_file_load_from_file(key_file, filename, 0, NULL)) {
+ g_key_file_free(key_file);
+ return 0;
+ }
+
+ chr_value = g_key_file_get_integer(key_file, group, BATTERY_KEY_LEVEL,
+ NULL);
+ g_key_file_free(key_file);
+
+ return chr_value;
+}
+
+static void del_battery_char(struct characteristic *chr)
+{
+ GKeyFile *key_file;
+ char filename[PATH_MAX + 1];
+ char adapter_addr[18];
+ char device_addr[18];
+ char group[5];
+ char *str;
+ gsize length = 0;
+
+ ba2str(adapter_get_address(device_get_adapter(chr->batt->dev)),
+ adapter_addr);
+ ba2str(device_get_address(chr->batt->dev), device_addr);
+
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/" BATTERY_FILE,
+ adapter_addr, device_addr);
+
+ snprintf(group, sizeof(group), BATTERY_GROUP_FORMAT, chr->attr.handle);
+
+ key_file = g_key_file_new();
+ if (!g_key_file_load_from_file(key_file, filename, 0, NULL)) {
+ g_key_file_free(key_file);
+ return;
+ }
+
+ g_key_file_remove_key(key_file, group, BATTERY_KEY_LEVEL, NULL);
+
+ create_file(filename, S_IRUSR | S_IWUSR);
+
+ str = g_key_file_to_data(key_file, &length, NULL);
+ g_file_set_contents(filename, str, length, NULL);
+
+ g_free(str);
+ g_key_file_free(key_file);
+}
+
+static gboolean read_battery_level_value(struct characteristic *chr)
+{
+ int level;
+
+ if (!chr)
+ return FALSE;
+
+ level = read_battery_char(chr);
+ if (!level)
+ return FALSE;
+
+ chr->level = level;
+
+ btd_device_set_battery_opt(chr->devbatt, BATTERY_OPT_LEVEL, chr->level,
+ BATTERY_OPT_INVALID);
+
+ return TRUE;
+}
+
static void char_free(gpointer user_data)
{
struct characteristic *c = user_data;
+ del_battery_char(c);
+
if (c->notifyid && c->batt->attrib != NULL)
g_attrib_unregister(c->batt->attrib, c->notifyid);
@@ -135,6 +265,8 @@ static void read_batterylevel_cb(guint8 status, const guint8 *pdu, guint16 len,
ch->level = value[0];
btd_device_set_battery_opt(ch->devbatt, BATTERY_OPT_LEVEL, ch->level,
BATTERY_OPT_INVALID);
+
+ store_battery_char(ch);
}
static void process_batteryservice_char(struct characteristic *ch)
@@ -359,7 +491,8 @@ static void configure_battery_cb(GSList *characteristics, guint8 status,
start = c->value_handle + 1;
- process_batteryservice_char(ch);
+ if (!read_battery_level_value(ch))
+ process_batteryservice_char(ch);
ch->devbatt = btd_device_add_battery(ch->batt->dev);
@@ -396,7 +529,7 @@ static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
GSList *l;
for (l = batt->chars; l; l = l->next) {
struct characteristic *c = l->data;
- if (!c->can_notify)
+ if (!read_battery_level_value(c) && !c->can_notify)
process_batteryservice_char(c);
}
}
--
1.7.9.5
^ permalink raw reply related
* Re: [PATCH 1/2] audio: Replace g_hash_table_contains() with g_hash_table_lookup()
From: Luiz Augusto von Dentz @ 2013-01-07 20:00 UTC (permalink / raw)
To: Jaganath Kanakkassery; +Cc: Ludek Finstrle, linux-bluetooth@vger.kernel.org
In-Reply-To: <39D5295DD81346F9A6FC2AFB8D19919F@sisodomain.com>
Hi Jaganath,
On Mon, Jan 7, 2013 at 3:52 PM, Jaganath Kanakkassery
<jaganath.k@samsung.com> wrote:
> Hi Ludek,
>
> --------------------------------------------------
> From: "Ludek Finstrle" <luf@pzkagis.cz>
> Sent: Monday, January 07, 2013 6:42 PM
> To: "Jaganath Kanakkassery" <jaganath.k@samsung.com>
> Cc: <linux-bluetooth@vger.kernel.org>
> Subject: Re: [PATCH 1/2] audio: Replace g_hash_table_contains() with
> g_hash_table_lookup()
>
>
>> Hello,
>>
>> Mon, Jan 07, 2013 at 06:03:52PM +0530, Jaganath Kanakkassery napsal(a):
>>>
>>> g_hash_table_contains() is supported only from GLib 2.32. If BlueZ has to
>>> build against GLib 2.28 this patch replaces g_hash_table_contains() to
>>> g_hash_table_lookup()
>>> ---
>>> profiles/audio/player.c | 7 ++++++-
>>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/profiles/audio/player.c b/profiles/audio/player.c
>>> index 8748893..4198bdb 100644
>>> --- a/profiles/audio/player.c
>>> +++ b/profiles/audio/player.c
>>> @@ -172,8 +172,13 @@ static gboolean get_status(const GDBusPropertyTable
>>> *property,
>>> static gboolean setting_exists(const GDBusPropertyTable *property, void
>>> *data)
>>> {
>>> struct media_player *mp = data;
>>> + const char *value;
>>> +
>>> + value = g_hash_table_lookup(mp->settings, property->name);
>>> + if (value == NULL)
>>> + return FALSE;
>>>
>>> - return g_hash_table_contains(mp->settings, property->name);
>>> + return TRUE;
>>> }
>>
>>
>> Doesn't
>>
>> return g_hash_table_lookup(mp->settings, property->name) != NULL;
>>
>> do the same? Maybe it's againist some code style but looks better
>> than several lines.
>
>
> I think
> return g_hash_table_lookup(mp->settings, property->name) ? TRUE : FALSE;
> would be better?
Shorter form is != NULL, so lets go with it, still haven't figure out
why we didn't bring back glib-compat for such functions, when we
finally upgrade it will take much more time to revert this one by one.
--
Luiz Augusto von Dentz
^ permalink raw reply
* usage of g_test_fail() which is introduced in Glib 2.30
From: Syam Sidhardhan @ 2013-01-07 20:35 UTC (permalink / raw)
To: linux-bluetooth
Hi Marcel,
In the latest Bluez snapshot I'm getting the g_test_fail compilation
error. The problem
happens because we use the Glib minimum version requirement
as 2.28 and this API is introduced in GLib version 2.30.
Do we need to use the g_test_fail() now with Glib 2.28?
I guess we cannot replace it with a wrapper function.
Possible Patch:
From: Syam Sidhardhan <s.syam@samsung.com>
Date: Mon, 7 Jan 2013 17:22:00 -0300
Subject: [PATCH 1/1] unit: Remove g_test_fail()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
g_test_fail() is introduced in Glib v2.30 and we are using
Glib v2.28 as the minimum requirement for the build.
This patch resolves the compilation error that happen with
Glib version < 2.30.
Error log:
CC unit/test-mgmt.o
unit/test-mgmt.c: In function ‘check_actions’:
unit/test-mgmt.c:100:2: error: implicit declaration of
function ‘g_test_fail’ [-Werror=implicit-function-declaration]
cc1: all warnings being treated as errors
make[1]: *** [unit/test-mgmt.o] Error 1
make: *** [all] Error 2
---
unit/test-mgmt.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/unit/test-mgmt.c b/unit/test-mgmt.c
index 2d1a5d6..6b3689c 100644
--- a/unit/test-mgmt.c
+++ b/unit/test-mgmt.c
@@ -97,7 +97,6 @@ static void check_actions(struct context *context,
}
g_test_message("Command not handled\n");
- g_test_fail();
}
static gboolean server_handler(GIOChannel *channel, GIOCondition cond,
--
1.7.0.4
Regards,
Syam.
^ permalink raw reply related
* Re: [PATCH 2/2] Bluetooth: Update management interface revision
From: Syam Sidhardhan @ 2013-01-07 20:47 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: Syam Sidhardhan, linux-bluetooth
In-Reply-To: <1356630354.19248.58.camel@aeonflux>
Hi Marcel,
On Thu, Dec 27, 2012 at 11:15 PM, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Syam,
>
>> This enable us to introduce a check in user space to know
>> whether it's safe to pass non-16bit UUID's to kernel or not.
>> Currently the kernel support only 16bit UUID's in the EIR.
>>
>> Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
>> ---
>> net/bluetooth/mgmt.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> NAK. As I said before, I want the kernel to support 32-bit and 128-bit
> UUIDs. There is no point in doing a minimal fix. I want to see this
> fixed properly.
Ok, I'll send the 32-bit and 128-bit support patches soon.
Thanks,
Syam
^ permalink raw reply
* Re: [PATCH 2/2] Bluetooth: Fix ACL alive for long in case of non pariable devices
From: Syam Sidhardhan @ 2013-01-07 20:49 UTC (permalink / raw)
To: Syam Sidhardhan; +Cc: linux-bluetooth
In-Reply-To: <1356097469-24073-2-git-send-email-s.syam@samsung.com>
Hi,
On Fri, Dec 21, 2012 at 7:14 PM, Syam Sidhardhan <s.syam@samsung.com> wrote:
> For certain devices (ex: HID mouse), support for authentication,
> pairing and bonding is optional. For such devices, the ACL alive
> for too long after the l2cap disconnection.
>
> To avoid keep ACL alive for too long, set the ACL timeout back to
> HCI_DISCONN_TIMEOUT when l2cap is connected.
>
> commit id:a9ea3ed9b71cc3271dd59e76f65748adcaa76422 might have introduce
> this issue.
>
> Signed-off-by: Sang-Ki Park <sangki79.park@samsung.com>
> Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
> ---
> I'm not sure whether we need hci_conn_hold() and hci_conn_put() across
> while updating the disc_timeout. In certain other places in the code
> it's done. Ex: hci_auth_complete_evt(), hci_link_key_notify_evt() etc.
> Here I took that as the reference.
>
> net/bluetooth/l2cap_core.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 82a3bdc..7a544c2 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -1360,7 +1360,6 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
> sk = chan->sk;
>
> hci_conn_hold(conn->hcon);
> - conn->hcon->disc_timeout = HCI_DISCONN_TIMEOUT;
>
> bacpy(&bt_sk(sk)->src, conn->src);
> bacpy(&bt_sk(sk)->dst, conn->dst);
> @@ -1380,6 +1379,10 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
>
> BT_DBG("conn %p", conn);
>
> + hci_conn_hold(conn->hcon);
> + conn->hcon->disc_timeout = HCI_DISCONN_TIMEOUT;
> + hci_conn_put(conn->hcon);
> +
> if (!hcon->out && hcon->type == LE_LINK)
> l2cap_le_conn_ready(conn);
>
> --
> 1.7.9.5
>
ping.
Thanks,
Syam.
^ permalink raw reply
* New kernel APIs and actually testing them
From: Marcel Holtmann @ 2013-01-07 23:35 UTC (permalink / raw)
To: linux-bluetooth
Hi everyone,
our kernel APIs are not as good as they were years back. There are a
bunch of the management commands that are actually broken. And they have
been broken for years now. For example Set Device Class, Load Long Term
Keys, Confirm Name and maybe even others. Some commands are really
relaxing when it comes to accept certain input variables and turning
them into booleans. Which is also a bad idea.
This all has to stop. From now on, I do not want to see any kernel API
additions (management or socket) that we do not have a proper testing
tool for that can verify its correct behavior. Also adding new APIs
until we have verified the old ones is not something I like to do
either.
During the holidays I started a tool called mgmt-tester that allows
end-to-end testing of the management interface by using emulated HCI
controllers. You just need to load hci_vhci kernel module and run it.
There is a lot of extra work to do for actually ensuring that we are
sending the right HCI commands on different controller versions, but it
is possible to verify this since it is all emulated. Nobody needs the
latest hardware. Look into the emulator directory for my effort in
providing flexible support for simulating different behaviors.
This work of testing our APIs needs to be done NOW. So instead of
everybody trying to squeeze in the latest features, I rather see the
core being improved first and made rock solid.
I welcome every patch that tries to improve this situation.
Regards
Marcel
^ 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