* Re: [PATCH] Fix printing D-Bus errors when headset record could not be found
From: Johan Hedberg @ 2010-12-27 15:07 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1293452841-7141-1-git-send-email-luiz.dentz@gmail.com>
Hi Luiz,
On Mon, Dec 27, 2010, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
>
> When connection is started via headset_config_stream there is no D-Bus
> message to reply to.
> ---
> audio/headset.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
Pushed upstream. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH 2/4] Use stored device name (if any) instead of EIR data
From: Johan Hedberg @ 2010-12-27 14:53 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: Luiz Augusto von Dentz, linux-bluetooth
In-Reply-To: <AANLkTi=06P4ZpGO-sp7czZtn9FGLkBwPnrxNqDdGspfy@mail.gmail.com>
Hi,
On Mon, Dec 27, 2010, Anderson Lizardo wrote:
> > if the variable name is set
> > than your could would skip eir name completely while the code did
> > actually use the eir name, probably the eir name is updated more
> > frequently so it is probably the most updated one and we should in
> > fact update the storage if they don't match.
>
> I could not find on spec any mention that the "complete" EIR name may
> change.
It also doesn't say that it will not change. So the safe thing would be
not to make any assumption about its permanence, right?
Naturally the user of the remote device might change is name (if the
remote device has such a feature) and then the EIR data would change
too. Note that even if there's a name in storage it doesn't mean that
it's from the same discovery session. It might be from a previous
discovery session a long time ago and the user of the remote device
might have changed its name since then. So imho a complete name in an
EIR should always override whatever is in storage.
For the case of shortened names I don't think there's an indisputably
right answer. The question is what is better: that which is "complete"
or that which is more recent. I've got the feeling that the complete
version would be better for the user, but someone might of course
disagree with this.
Johan
^ permalink raw reply
* Re: [PATCH 2/4] Two merges very similar functions in bluetooth.c
From: Anderson Lizardo @ 2010-12-27 14:41 UTC (permalink / raw)
To: Michal.Labedzki; +Cc: linux-bluetooth
In-Reply-To: <AANLkTi=vSPvd7nFb=aus4Gpkkp3MFdiDv=HwndhYdUvB@mail.gmail.com>
On Mon, Dec 27, 2010 at 10:39 AM, Anderson Lizardo
<anderson.lizardo@openbossa.org> wrote:
> Hi,
>
> On Mon, Dec 27, 2010 at 10:35 AM, <Michal.Labedzki@tieto.com> wrote:
>> On Mon, Dec 27, 2010, Anderson Lizardo wrote:
>>> IMHO, you should keep str2ba and drop the few occurrences of
>>> strtoba(). Same applies to ba2str/batostr.
>>
>>> strtoba() allocates memory by itself, so if you use it instead, you
>>> need to deallocate memory. str2ba(), on the other hand, uses a buffer
>>> given as argument.
>>
>> These function are similar, but not the same. ba2str/str2ba reverse bdaddr, but
>> batostr/strtoba not. I wrote relevant documentation comments, because names look
>> similar, code look similar, but results are different.
>
> Ok, I confess the function names are confusing. One has to look at
> their implementation to make sure which one to use...
Just one more comment: on your commit description, it may appear that
you are merging the functions, while in fact you are just factoring
out common code. I suggest rewording the message so it makes clear you
are factoring out code.
Regards,
--
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH 2/4] Two merges very similar functions in bluetooth.c
From: Anderson Lizardo @ 2010-12-27 14:39 UTC (permalink / raw)
To: Michal.Labedzki; +Cc: linux-bluetooth
In-Reply-To: <E50901D4F2CF69428D43141B7C8586790B4B2D056C@EXMB03.eu.tieto.com>
Hi,
On Mon, Dec 27, 2010 at 10:35 AM, <Michal.Labedzki@tieto.com> wrote:
> On Mon, Dec 27, 2010, Anderson Lizardo wrote:
>> IMHO, you should keep str2ba and drop the few occurrences of
>> strtoba(). Same applies to ba2str/batostr.
>
>> strtoba() allocates memory by itself, so if you use it instead, you
>> need to deallocate memory. str2ba(), on the other hand, uses a buffer
>> given as argument.
>
> These function are similar, but not the same. ba2str/str2ba reverse bdaddr, but
> batostr/strtoba not. I wrote relevant documentation comments, because names look
> similar, code look similar, but results are different.
Ok, I confess the function names are confusing. One has to look at
their implementation to make sure which one to use...
Regards,
--
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH 2/4] Two merges very similar functions in bluetooth.c
From: Michal.Labedzki @ 2010-12-27 14:35 UTC (permalink / raw)
To: anderson.lizardo; +Cc: linux-bluetooth
In-Reply-To: <AANLkTik-sV2+k8_j6xt5F1MAPb-7t9K8JTEzm12f--c4@mail.gmail.com>
On Mon, Dec 27, 2010, Anderson Lizardo wrote:
> IMHO, you should keep str2ba and drop the few occurrences of
> strtoba(). Same applies to ba2str/batostr.
> strtoba() allocates memory by itself, so if you use it instead, you
> need to deallocate memory. str2ba(), on the other hand, uses a buffer
> given as argument.
These function are similar, but not the same. ba2str/str2ba reverse bdaddr, but
batostr/strtoba not. I wrote relevant documentation comments, because names look
similar, code look similar, but results are different.
Regards
^ permalink raw reply
* Re: [PATCH 2/4] Use stored device name (if any) instead of EIR data
From: Anderson Lizardo @ 2010-12-27 14:35 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <AANLkTikcZRjC2KwOpHSqS_6wMcT8skKBMbhMzs=ugK+F@mail.gmail.com>
On Mon, Dec 27, 2010 at 10:14 AM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> It seems your path changes more than just ignore the shortened names,
> which I believed was the purpose here
Note that it does not completely ignore shortened names. If no
complete EIR name has been received yet, it will use the shortened
name (but not store it, as it is temporary). Once a complete name has
been received, it will be stored and used from now on. Actually this
has been the original behavior regarding storage, my patch simply
makes sure any further complete names are ignored, assuming the first
"complete" one is definitive and that the device is not supposed to
rename the "complete" name.
> if the variable name is set
> than your could would skip eir name completely while the code did
> actually use the eir name, probably the eir name is updated more
> frequently so it is probably the most updated one and we should in
> fact update the storage if they don't match.
I could not find on spec any mention that the "complete" EIR name may
change. Note that the original code only store complete EIR name and
the name coming from name resolving.
> Now about the shortened, Im not completely sure if we should ignore it
> or just append something to it, like e.g. ... or ~1, in case the spec
> say it is always the prefix we can at least use it as an hint if the
> name we have resolved does have changed.
As I mentioned above, the shortened names are only ignored after a
"complete" EIR name has been received. I think this is a sane
behavior, assuming the shortened names are temporary (e.g. while name
resolution is not possible or while the device could not send the
complete name using EIR).
I've not found any references to the spec saying the shortened name
has to be a prefix. I believe it is left to the implementer how to
display such shortened names. bluez so far has made no distinction on
the display of shortened names vs. complete names.
Regards,
--
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH 2/4] Use stored device name (if any) instead of EIR data
From: Luiz Augusto von Dentz @ 2010-12-27 14:14 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: linux-bluetooth
In-Reply-To: <1293456068-11615-2-git-send-email-anderson.lizardo@openbossa.org>
Hi,
On Mon, Dec 27, 2010 at 3:21 PM, Anderson Lizardo
<anderson.lizardo@openbossa.org> wrote:
> The stored device name comes from either name resolution or from a
> "complete" EIR name. If available, use it and ignore any further name
> present on EIR data.
> ---
> src/event.c | 16 ++++------------
> 1 files changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/src/event.c b/src/event.c
> index 6598e37..f445dd1 100644
> --- a/src/event.c
> +++ b/src/event.c
> @@ -549,22 +549,14 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
> } else
> legacy = TRUE;
>
> - if (eir_data.name) {
> + if (name == NULL && eir_data.name != NULL) {
> if (eir_data.name_complete) {
> write_device_name(local, peer, eir_data.name);
> name_status = NAME_NOT_REQUIRED;
> -
> - if (name)
> - g_free(name);
> -
> - name = eir_data.name;
> - } else {
> - if (name)
> - free(eir_data.name);
> - else
> - name = eir_data.name;
> }
> - }
> + name = eir_data.name;
> + } else if (eir_data.name != NULL)
> + g_free(eir_data.name);
>
> adapter_update_found_devices(adapter, peer, rssi, class, name, alias,
> legacy, eir_data.services, name_status);
It seems your path changes more than just ignore the shortened names,
which I believed was the purpose here, if the variable name is set
than your could would skip eir name completely while the code did
actually use the eir name, probably the eir name is updated more
frequently so it is probably the most updated one and we should in
fact update the storage if they don't match.
Now about the shortened, Im not completely sure if we should ignore it
or just append something to it, like e.g. ... or ~1, in case the spec
say it is always the prefix we can at least use it as an hint if the
name we have resolved does have changed.
--
Luiz Augusto von Dentz
Computer Engineer
^ permalink raw reply
* [PATCH 4/4] Fix leak of EIR data if RSSI does not change
From: Anderson Lizardo @ 2010-12-27 13:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Anderson Lizardo
In-Reply-To: <1293456068-11615-1-git-send-email-anderson.lizardo@openbossa.org>
If RSSI value does not change, memory used by parsed EIR data would leak
because it would not be assigned to the remote_dev_info structure.
---
src/adapter.c | 19 ++++++++++++-------
src/adapter.h | 11 ++++++-----
src/event.c | 16 ++++++++++++----
3 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index fddf0ad..aff1262 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2917,7 +2917,7 @@ static void remove_same_uuid(gpointer data, gpointer user_data)
}
}
-void adapter_update_device_from_info(struct btd_adapter *adapter,
+gboolean adapter_update_device_from_info(struct btd_adapter *adapter,
bdaddr_t bdaddr, int8_t rssi,
uint8_t evt_type, char *name,
GSList *services, uint8_t flags)
@@ -2931,7 +2931,7 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
dev->le = TRUE;
dev->evt_type = evt_type;
} else if (dev->rssi == rssi)
- return;
+ return FALSE;
dev->rssi = rssi;
@@ -2951,12 +2951,15 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
/* FIXME: check if other information was changed before emitting the
* signal */
adapter_emit_device_found(adapter, dev);
+
+ return TRUE;
}
-void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
- int8_t rssi, uint32_t class, const char *name,
- const char *alias, gboolean legacy,
- GSList *services, name_status_t name_status)
+gboolean adapter_update_found_devices(struct btd_adapter *adapter,
+ bdaddr_t *bdaddr, int8_t rssi, uint32_t class,
+ const char *name, const char *alias,
+ gboolean legacy, GSList *services,
+ name_status_t name_status)
{
struct remote_dev_info *dev;
gboolean new_dev;
@@ -2975,7 +2978,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
dev->legacy = legacy;
dev->name_status = name_status;
} else if (dev->rssi == rssi)
- return;
+ return FALSE;
dev->rssi = rssi;
@@ -2986,6 +2989,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
dev->services = g_slist_concat(dev->services, services);
adapter_emit_device_found(adapter, dev);
+
+ return TRUE;
}
int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr)
diff --git a/src/adapter.h b/src/adapter.h
index 857eec8..cee0bd4 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -134,14 +134,15 @@ int adapter_get_state(struct btd_adapter *adapter);
int adapter_get_discover_type(struct btd_adapter *adapter);
struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter,
struct remote_dev_info *match);
-void adapter_update_device_from_info(struct btd_adapter *adapter,
+gboolean adapter_update_device_from_info(struct btd_adapter *adapter,
bdaddr_t bdaddr, int8_t rssi,
uint8_t evt_type, char *name,
GSList *services, uint8_t flags);
-void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
- int8_t rssi, uint32_t class, const char *name,
- const char *alias, gboolean legacy,
- GSList *services, name_status_t name_status);
+gboolean adapter_update_found_devices(struct btd_adapter *adapter,
+ bdaddr_t *bdaddr, int8_t rssi, uint32_t class,
+ const char *name, const char *alias,
+ gboolean legacy, GSList *services,
+ name_status_t name_status);
int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
void adapter_emit_device_found(struct btd_adapter *adapter,
struct remote_dev_info *dev);
diff --git a/src/event.c b/src/event.c
index 15fac94..795686e 100644
--- a/src/event.c
+++ b/src/event.c
@@ -452,9 +452,13 @@ void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
rssi = *(info->data + info->length);
- adapter_update_device_from_info(adapter, info->bdaddr, rssi,
+ if (!adapter_update_device_from_info(adapter, info->bdaddr, rssi,
info->evt_type, eir_data.name,
- eir_data.services, eir_data.flags);
+ eir_data.services, eir_data.flags)) {
+ g_slist_foreach(eir_data.services, (GFunc) g_free, NULL);
+ g_slist_free(eir_data.services);
+ g_free(eir_data.name);
+ }
}
static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
@@ -556,8 +560,12 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
} else if (eir_data.name != NULL)
g_free(eir_data.name);
- adapter_update_found_devices(adapter, peer, rssi, class, name, alias,
- legacy, eir_data.services, name_status);
+ if (!adapter_update_found_devices(adapter, peer, rssi, class, name,
+ alias, legacy, eir_data.services,
+ name_status)) {
+ g_slist_foreach(eir_data.services, (GFunc) g_free, NULL);
+ g_slist_free(eir_data.services);
+ }
g_free(name);
g_free(alias);
--
1.7.0.4
^ permalink raw reply related
* [PATCH 3/4] Remove outdated comments
From: Anderson Lizardo @ 2010-12-27 13:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Anderson Lizardo
In-Reply-To: <1293456068-11615-1-git-send-email-anderson.lizardo@openbossa.org>
---
src/event.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/src/event.c b/src/event.c
index f445dd1..15fac94 100644
--- a/src/event.c
+++ b/src/event.c
@@ -444,7 +444,6 @@ void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
return;
}
- /* Extract UUIDs from advertising data if any */
memset(&eir_data, 0, sizeof(eir_data));
err = parse_eir_data(&eir_data, info->data, info->length);
if (err < 0)
@@ -518,7 +517,6 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
adapter_set_state(adapter, state);
}
- /* Extract UUIDs from extended inquiry response if any */
memset(&eir_data, 0, sizeof(eir_data));
err = parse_eir_data(&eir_data, data, EIR_DATA_LENGTH);
if (err < 0)
--
1.7.0.4
^ permalink raw reply related
* [PATCH 2/4] Use stored device name (if any) instead of EIR data
From: Anderson Lizardo @ 2010-12-27 13:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Anderson Lizardo
In-Reply-To: <1293456068-11615-1-git-send-email-anderson.lizardo@openbossa.org>
The stored device name comes from either name resolution or from a
"complete" EIR name. If available, use it and ignore any further name
present on EIR data.
---
src/event.c | 16 ++++------------
1 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/src/event.c b/src/event.c
index 6598e37..f445dd1 100644
--- a/src/event.c
+++ b/src/event.c
@@ -549,22 +549,14 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
} else
legacy = TRUE;
- if (eir_data.name) {
+ if (name == NULL && eir_data.name != NULL) {
if (eir_data.name_complete) {
write_device_name(local, peer, eir_data.name);
name_status = NAME_NOT_REQUIRED;
-
- if (name)
- g_free(name);
-
- name = eir_data.name;
- } else {
- if (name)
- free(eir_data.name);
- else
- name = eir_data.name;
}
- }
+ name = eir_data.name;
+ } else if (eir_data.name != NULL)
+ g_free(eir_data.name);
adapter_update_found_devices(adapter, peer, rssi, class, name, alias,
legacy, eir_data.services, name_status);
--
1.7.0.4
^ permalink raw reply related
* [PATCH 1/4] Remove ancient NAME_SENT name resolution status
From: Anderson Lizardo @ 2010-12-27 13:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Anderson Lizardo
The NAME_SENT status was introduced on commit
d6a16516a9f6deae8342f00e8186b02d0019a1e1, when there was a
"RemoteNameUpdate" D-Bus signal. Nowadays, there is no such signal, and
the device name (if any) is always sent on "DeviceFound" signal.
---
src/adapter.h | 1 -
src/event.c | 19 -------------------
2 files changed, 0 insertions(+), 20 deletions(-)
diff --git a/src/adapter.h b/src/adapter.h
index ab83011..857eec8 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -61,7 +61,6 @@ typedef enum {
NAME_NOT_REQUIRED, /* used by get remote name without name resolving */
NAME_REQUIRED, /* remote name needs be resolved */
NAME_REQUESTED, /* HCI remote name request was sent */
- NAME_SENT /* D-Bus signal RemoteNameUpdated sent */
} name_status_t;
struct btd_adapter;
diff --git a/src/event.c b/src/event.c
index cfc47bf..6598e37 100644
--- a/src/event.c
+++ b/src/event.c
@@ -487,7 +487,6 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
struct btd_adapter *adapter;
struct btd_device *device;
char local_addr[18], peer_addr[18], *alias, *name;
- struct remote_dev_info *dev, match;
name_status_t name_status;
struct eir_data eir_data;
int state, err;
@@ -525,20 +524,6 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
if (err < 0)
error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
- memset(&match, 0, sizeof(struct remote_dev_info));
- bacpy(&match.bdaddr, peer);
- match.name_status = NAME_SENT;
- /* if found: don't send the name again */
- dev = adapter_search_found_devices(adapter, &match);
- if (dev) {
- g_free(eir_data.name);
- adapter_update_found_devices(adapter, peer, rssi, class,
- NULL, NULL, dev->legacy,
- eir_data.services,
- NAME_NOT_REQUIRED);
- return;
- }
-
/* the inquiry result can be triggered by NON D-Bus client */
if (adapter_get_discover_type(adapter) & DISC_RESOLVNAME &&
adapter_has_discov_sessions(adapter))
@@ -581,10 +566,6 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
}
}
- if (name && eir_data.name_complete)
- name_status = NAME_SENT;
-
- /* add in the list to track name sent/pending */
adapter_update_found_devices(adapter, peer, rssi, class, name, alias,
legacy, eir_data.services, name_status);
--
1.7.0.4
^ permalink raw reply related
* [PATCH] Fix printing D-Bus errors when headset record could not be found
From: Luiz Augusto von Dentz @ 2010-12-27 12:27 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
When connection is started via headset_config_stream there is no D-Bus
message to reply to.
---
audio/headset.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/audio/headset.c b/audio/headset.c
index 72bf5b6..53a594d 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -1445,7 +1445,8 @@ static void get_record_cb(sdp_list_t *recs, int err, gpointer user_data)
error("Unable to get service record: %s (%d)",
strerror(-err), -err);
p->err = -err;
- error_connect_failed(dev->conn, p->msg, p->err);
+ if (p->msg)
+ error_connect_failed(dev->conn, p->msg, p->err);
goto failed;
}
--
1.7.1
^ permalink raw reply related
* Re: [PATCH 1/4] Filtering interface name from program arguments
From: Anderson Lizardo @ 2010-12-27 12:13 UTC (permalink / raw)
To: Michal Labedzki; +Cc: linux-bluetooth
In-Reply-To: <1293447745-8697-1-git-send-email-michal.labedzki@tieto.com>
Hi,
On Mon, Dec 27, 2010 at 7:02 AM, Michal Labedzki
<michal.labedzki@tieto.com> wrote:
> +/* return 1 if string is ecimal number without leading zeros
> + * return 0 if not */
Typo: ecimal -> decimal
> +static int is_devnumber(const char *c)
> +{
> + if (c[0] == '0' && c[1] != 0)
> + return 0;
> +
> + while (*c) {
> + if (*c < '0' || *c > '9')
> + return 0;
> + ++c;
> + }
> + return 1;
> +}
> +
> +/* return HCI dev_id from string like "hciX", where X is dev_id
> + * return -1 if string not match */
Suggestion: "return -1 if str has invalid format"
> +int hci_filter_devname(const char *str)
> +{
> + int dev_id;
> +
> + if ((strlen(str) >= 4) && (!strncmp(str, "hci", 3)) &&
> + (is_devnumber(str + 3)))
> + dev_id = atoi(str + 3);
> + else
> + dev_id = -1;
> +
> + if (dev_id >= HCI_MAX_DEV)
> + dev_id = -1;
> +
> + return dev_id;
> +}
> +
> +/* return dev_id, which is on UP state, from 'hciX' or 'bdaddr'
> + * otherwise return -1 */
> int hci_devid(const char *str)
> {
> bdaddr_t ba;
> - int id = -1;
> + int dev_id;
>
> - if (!strncmp(str, "hci", 3) && strlen(str) >= 4) {
> - id = atoi(str + 3);
> - if (hci_devba(id, &ba) < 0)
> - return -1;
> - } else {
> + dev_id = hci_filter_devname(str);
> + if (dev_id < 0) {
> errno = ENODEV;
> str2ba(str, &ba);
> - id = hci_for_each_dev(HCI_UP, __same_bdaddr, (long) &ba);
> + dev_id = hci_for_each_dev(HCI_UP, __same_bdaddr, (long) &ba);
> + } else {
> + if (hci_devba(dev_id, &ba) < 0)
> + return -1;
> }
Use "else if (hci_devba(...))" and drop the extra brackets.
>
> - return id;
> + return dev_id;
> }
> diff --git a/test/hciemu.c b/test/hciemu.c
> index a20374f..ae33d72 100644
> --- a/test/hciemu.c
> +++ b/test/hciemu.c
> @@ -1234,15 +1234,16 @@ int main(int argc, char *argv[])
> exit(1);
> }
>
> - if (strlen(argv[0]) > 3 && !strncasecmp(argv[0], "hci", 3)) {
> + dev = hci_filter_devname(argv[0]);
> + if (dev < 0) {
> + if (getbdaddrbyname(argv[0], &vdev.bdaddr) < 0)
> + exit(1);
> + } else {
> dev = hci_devid(argv[0]);
> if (dev < 0) {
> perror("Invalid device");
> exit(1);
> }
> - } else {
> - if (getbdaddrbyname(argv[0], &vdev.bdaddr) < 0)
> - exit(1);
> }
>
> if (detach) {
> diff --git a/test/l2test.c b/test/l2test.c
> index 17883a9..438ba39 100644
> --- a/test/l2test.c
> +++ b/test/l2test.c
> @@ -1101,6 +1101,7 @@ int main(int argc, char *argv[])
> {
> struct sigaction sa;
> int opt, sk, mode = RECV, need_addr = 0;
> + int devid;
>
> bacpy(&bdaddr, BDADDR_ANY);
>
> @@ -1175,10 +1176,11 @@ int main(int argc, char *argv[])
> break;
>
> case 'i':
> - if (!strncasecmp(optarg, "hci", 3))
> - hci_devba(atoi(optarg + 3), &bdaddr);
> - else
> + devid = hci_filter_devname(optarg);
> + if (devid < 0)
> str2ba(optarg, &bdaddr);
> + else
> + hci_devba(devid, &bdaddr);
> break;
>
> case 'P':
> diff --git a/test/rctest.c b/test/rctest.c
> index b3804f5..a828ad9 100644
> --- a/test/rctest.c
> +++ b/test/rctest.c
> @@ -579,7 +579,7 @@ static void usage(void)
> "\t-m multiple connects\n");
>
> printf("Options:\n"
> - "\t[-b bytes] [-i device] [-P channel] [-U uuid]\n"
> + "\t[-b bytes] [-i hciX|bdaddr] [-P channel] [-U uuid]\n"
> "\t[-L seconds] enabled SO_LINGER option\n"
> "\t[-W seconds] enable deferred setup\n"
> "\t[-B filename] use data packets from file\n"
> @@ -597,6 +597,7 @@ int main(int argc, char *argv[])
> {
> struct sigaction sa;
> int opt, sk, mode = RECV, need_addr = 0;
> + int devid;
>
> bacpy(&bdaddr, BDADDR_ANY);
>
> @@ -644,10 +645,11 @@ int main(int argc, char *argv[])
> break;
>
> case 'i':
> - if (!strncasecmp(optarg, "hci", 3))
> - hci_devba(atoi(optarg + 3), &bdaddr);
> - else
> + devid = hci_filter_devname(optarg);
> + if (devid < 0)
> str2ba(optarg, &bdaddr);
> + else
> + hci_devba(devid, &bdaddr);
> break;
>
> case 'P':
> diff --git a/tools/ciptool.c b/tools/ciptool.c
> index edce9da..ec602ef 100644
> --- a/tools/ciptool.c
> +++ b/tools/ciptool.c
> @@ -427,7 +427,7 @@ static void usage(void)
> "\n");
>
> printf("Options:\n"
> - "\t-i [hciX|bdaddr] Local HCI device or BD Address\n"
> + "\t-i <hciX|bdaddr> Local HCI device or BD Address\n"
> "\t-h, --help Display help\n"
> "\n");
>
> @@ -455,10 +455,11 @@ int main(int argc, char *argv[])
> while ((opt = getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
> switch(opt) {
> case 'i':
> - if (!strncmp(optarg, "hci", 3))
> - hci_devba(atoi(optarg + 3), &bdaddr);
> - else
> + i = hci_filter_devname(optarg);
> + if (i < 0)
> str2ba(optarg, &bdaddr);
> + else
> + hci_devba(i, &bdaddr);
> break;
> case 'h':
> usage();
> diff --git a/tools/hciconfig.c b/tools/hciconfig.c
> index f0ae11c..e20963d 100644
> --- a/tools/hciconfig.c
> +++ b/tools/hciconfig.c
> @@ -1849,7 +1849,13 @@ int main(int argc, char *argv[])
> exit(0);
> }
>
> - di.dev_id = atoi(argv[0] + 3);
> + i = hci_filter_devname(argv[0]);
> + if (i < 0) {
> + fprintf(stderr, "No valid device name.\n");
> + exit(1);
> + }
> + di.dev_id = i;
> +
> argc--; argv++;
>
> if (ioctl(ctl, HCIGETDEVINFO, (void *) &di)) {
> diff --git a/tools/hcitool.c b/tools/hcitool.c
> index d50adaf..dc70e63 100644
> --- a/tools/hcitool.c
> +++ b/tools/hcitool.c
> @@ -2560,8 +2560,8 @@ static void usage(void)
> printf("Usage:\n"
> "\thcitool [options] <command> [command parameters]\n");
> printf("Options:\n"
> - "\t--help\tDisplay help\n"
> - "\t-i dev\tHCI device\n");
> + "\t--help Display help\n"
> + "\t-i <hciX|bdaddr> Local HCI device or BD Address\n");
> printf("Commands:\n");
> for (i = 0; command[i].cmd; i++)
> printf("\t%-4s\t%s\n", command[i].cmd,
> diff --git a/tools/l2ping.c b/tools/l2ping.c
> index 29fb3d0..dd0ccbd 100644
> --- a/tools/l2ping.c
> +++ b/tools/l2ping.c
> @@ -255,7 +255,8 @@ static void usage(void)
> {
> printf("l2ping - L2CAP ping\n");
> printf("Usage:\n");
> - printf("\tl2ping [-i device] [-s size] [-c count] [-t timeout] [-d delay] [-f] [-r] [-v] <bdaddr>\n");
> + printf("\tl2ping [-i <hciX|bdaddr> local hci or bd address] [-s size]"
> + "[-c count] [-t timeout] [-d delay] [-f] [-r] [-v] <bdaddr>\n");
The change above looks strange. You could drop "local hci or bd
address" (it is implicit from "<hciX|bdaddr>").
> printf("\t-f Flood ping (delay = 0)\n");
> printf("\t-r Reverse ping\n");
> printf("\t-v Verify request and response payload\n");
> @@ -264,17 +265,18 @@ static void usage(void)
> int main(int argc, char *argv[])
> {
> int opt;
> -
> + int devid;
Add an empty line here.
> /* Default options */
> bacpy(&bdaddr, BDADDR_ANY);
>
> while ((opt=getopt(argc,argv,"i:d:s:c:t:frv")) != EOF) {
> switch(opt) {
> case 'i':
> - if (!strncasecmp(optarg, "hci", 3))
> - hci_devba(atoi(optarg + 3), &bdaddr);
> - else
> + devid = hci_filter_devname(optarg);
> + if (devid < 0)
> str2ba(optarg, &bdaddr);
> + else
> + hci_devba(devid, &bdaddr);
> break;
>
> case 'd':
> diff --git a/tools/main.c b/tools/main.c
> index 6800445..c000fba 100644
> --- a/tools/main.c
> +++ b/tools/main.c
> @@ -753,10 +753,11 @@ int main(int argc, char *argv[])
> while ((opt = getopt_long(argc, argv, "+i:f:rahAESML:", main_options, NULL)) != -1) {
> switch(opt) {
> case 'i':
> - if (strncmp(optarg, "hci", 3) == 0)
> - hci_devba(atoi(optarg + 3), &bdaddr);
> - else
> + dev_id = hci_filter_devname(optarg);
> + if (dev_id < 0)
> str2ba(optarg, &bdaddr);
> + else
> + hci_devba(dev_id, &bdaddr);
> break;
>
> case 'f':
> diff --git a/tools/sdptool.c b/tools/sdptool.c
> index 140a46a..c782e62 100644
> --- a/tools/sdptool.c
> +++ b/tools/sdptool.c
> @@ -4209,7 +4209,7 @@ static void usage(void)
> "\tsdptool [options] <command> [command parameters]\n");
> printf("Options:\n"
> "\t-h\t\tDisplay help\n"
> - "\t-i\t\tSpecify source interface\n");
> + "\t-i\t\tSpecify source interface or bdaddr\n");
>
> printf("Commands:\n");
> for (i = 0; command[i].cmd; i++)
> @@ -4242,10 +4242,11 @@ int main(int argc, char *argv[])
> while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
> switch(opt) {
> case 'i':
> - if (!strncmp(optarg, "hci", 3))
> - hci_devba(atoi(optarg + 3), &interface);
> - else
> + i = hci_filter_devname(optarg);
> + if (i < 0)
> str2ba(optarg, &interface);
> + else
> + hci_devba(i, &interface);
> break;
>
> case 'h':
> --
> 1.7.0.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
--
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH 3/4] Fix memory leaks after using strtoba, batostr
From: Anderson Lizardo @ 2010-12-27 11:53 UTC (permalink / raw)
To: Michal Labedzki; +Cc: linux-bluetooth
In-Reply-To: <1293447745-8697-3-git-send-email-michal.labedzki@tieto.com>
Hi,
This patch would not be necessary if you keep only str2ba() and
ba2str() (like I commented on patch 2/4).
Regards,
--
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH 4/4] Better filtering input string contain bdaddr
From: Anderson Lizardo @ 2010-12-27 11:52 UTC (permalink / raw)
To: Michal Labedzki; +Cc: linux-bluetooth
In-Reply-To: <1293447745-8697-4-git-send-email-michal.labedzki@tieto.com>
On Mon, Dec 27, 2010 at 7:02 AM, Michal Labedzki
<michal.labedzki@tieto.com> wrote:
> + if (((*ptr < 'A' || *ptr > 'F') &&
> + (*ptr < 'a' || *ptr > 'f') &&
> + (*ptr < '0' || *ptr > '9')) ||
> + ( (ptr - str) == 2 && *ptr != ':')) {
> + bt_free(ba);
> + goto err_bdaddr;
> + }
The logic above seems wrong. Make sure you are not mixing || and &&.
> +
> + ++i;
> + ++ptr;
I think the usual coding style in bluez uses post-increment in these
cases (e.g. i++).
Regards,
--
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH 2/4] Two merges very similar functions in bluetooth.c
From: Anderson Lizardo @ 2010-12-27 11:46 UTC (permalink / raw)
To: Michal Labedzki; +Cc: linux-bluetooth
In-Reply-To: <1293447745-8697-2-git-send-email-michal.labedzki@tieto.com>
On Mon, Dec 27, 2010 at 7:02 AM, Michal Labedzki
<michal.labedzki@tieto.com> wrote:
> in lib/bluetooth.c merge "str2ba" and "strtoba", "ba2str" and "batostr"
IMHO, you should keep str2ba and drop the few occurrences of
strtoba(). Same applies to ba2str/batostr.
strtoba() allocates memory by itself, so if you use it instead, you
need to deallocate memory. str2ba(), on the other hand, uses a buffer
given as argument.
Regards,
--
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil
^ permalink raw reply
* [PATCH 4/4] Better filtering input string contain bdaddr
From: Michal Labedzki @ 2010-12-27 11:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Michal Labedzki
In-Reply-To: <1293447745-8697-1-git-send-email-michal.labedzki@tieto.com>
---
lib/bluetooth.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 48 insertions(+), 7 deletions(-)
diff --git a/lib/bluetooth.c b/lib/bluetooth.c
index 3a4e3f4..9333eeb 100644
--- a/lib/bluetooth.c
+++ b/lib/bluetooth.c
@@ -60,23 +60,64 @@ char *batostr(const bdaddr_t *ba)
return str;
}
+/* convert to bdaddr_t string describes with regular expression "(XX:){0,5}XX"
+ * where X is "[0-9A-Fa-f]"
+ * shorter address is filling with ":00" at the end
+ */
bdaddr_t *strtoba(const char *str)
{
const char *ptr = str;
int i;
+ int parts;
+ int length;
+ bdaddr_t *ba;
+ unsigned int b;
+
+ length = strlen(str);
+ if (length <= 1 || length > 17)
+ goto err_bdaddr;
- uint8_t *ba = bt_malloc(sizeof(bdaddr_t));
+ ba = bt_malloc(sizeof(bdaddr_t));
if (!ba)
return NULL;
- for (i = 0; i < 6; i++) {
- ba[i] = (uint8_t) strtol(ptr, NULL, 16);
- if (i != 5 && !(ptr = strchr(ptr,':')))
- ptr = ":00:00:00:00:00";
- ptr++;
+ i = 0;
+ parts = 0;
+ while (*ptr) {
+ if (i == 2 && *ptr == ':') {
+ i = 0;
+ ba->b[parts] = strtol(ptr - 2, NULL, 16);
+ ++parts;
+ ++ptr;
+ }
+
+ if (((*ptr < 'A' || *ptr > 'F') &&
+ (*ptr < 'a' || *ptr > 'f') &&
+ (*ptr < '0' || *ptr > '9')) ||
+ ( (ptr - str) == 2 && *ptr != ':')) {
+ bt_free(ba);
+ goto err_bdaddr;
+ }
+
+ ++i;
+ ++ptr;
}
- return (bdaddr_t *) ba;
+ if (*(ptr - 1) == ':' || i == 1) {
+ bt_free(ba);
+ goto err_bdaddr;
+ }
+
+ ba->b[parts] = strtol(ptr - 2, NULL, 16);
+ for (i = parts + 1 ; i < 6 ; ++i) {
+ ba->b[i] = 0;
+ }
+
+ return ba;
+
+err_bdaddr:
+ fprintf(stderr, "Incorrect bdaddr format\n");
+ exit(1);
}
/* reverse bdaddr and do batostr */
--
1.7.0.4
^ permalink raw reply related
* [PATCH 3/4] Fix memory leaks after using strtoba, batostr
From: Michal Labedzki @ 2010-12-27 11:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Michal Labedzki
In-Reply-To: <1293447745-8697-1-git-send-email-michal.labedzki@tieto.com>
---
compat/bnep.c | 5 +++--
compat/pand.c | 9 ++++++---
test/hciemu.c | 8 ++++++--
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/compat/bnep.c b/compat/bnep.c
index 9b0d8b8..f651dfd 100644
--- a/compat/bnep.c
+++ b/compat/bnep.c
@@ -137,9 +137,10 @@ int bnep_show_connections(void)
}
for (i = 0; i < req.cnum; i++) {
- printf("%s %s %s\n", ci[i].device,
- batostr((bdaddr_t *) ci[i].dst),
+ char *tmp_bastr = batostr((bdaddr_t *) ci[i].dst);
+ printf("%s %s %s\n", ci[i].device, tmp_bastr,
bnep_svc2str(ci[i].role));
+ bt_free(tmp_bastr);
}
return 0;
}
diff --git a/compat/pand.c b/compat/pand.c
index 7331fad..8a50020 100644
--- a/compat/pand.c
+++ b/compat/pand.c
@@ -456,10 +456,13 @@ static void do_show(void)
static void do_kill(char *dst)
{
- if (dst)
- bnep_kill_connection((void *) strtoba(dst));
- else
+ if (dst) {
+ bdaddr_t *tmp_ba = strtoba(dst);
+ bnep_kill_connection((void *) tmp_ba);
+ bt_free(tmp_ba);
+ } else {
bnep_kill_all_connections();
+ }
}
static void sig_hup(int sig)
diff --git a/test/hciemu.c b/test/hciemu.c
index ae33d72..031b867 100644
--- a/test/hciemu.c
+++ b/test/hciemu.c
@@ -499,8 +499,10 @@ static void accept_connection(uint8_t *data)
static void close_connection(struct vhci_conn *conn)
{
+ char *tmp_bastr = batostr(&conn->dest);
syslog(LOG_INFO, "Closing connection %s handle %d",
- batostr(&conn->dest), conn->handle);
+ tmp_bastr, conn->handle);
+ bt_free(tmp_bastr);
g_io_channel_close(conn->chan);
g_io_channel_unref(conn->chan);
@@ -1017,7 +1019,9 @@ static int getbdaddrbyname(char *str, bdaddr_t *ba)
if (n == 5) {
/* BD address */
- baswap(ba, strtoba(str));
+ bdaddr_t *tmp_ba = strtoba(str);
+ baswap(ba, tmp_ba);
+ bt_free(tmp_ba);
return 0;
}
--
1.7.0.4
^ permalink raw reply related
* [PATCH 2/4] Two merges very similar functions in bluetooth.c
From: Michal Labedzki @ 2010-12-27 11:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Michal Labedzki
In-Reply-To: <1293447745-8697-1-git-send-email-michal.labedzki@tieto.com>
in lib/bluetooth.c merge "str2ba" and "strtoba", "ba2str" and "batostr"
---
lib/bluetooth.c | 34 +++++++++++++++++-----------------
1 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/lib/bluetooth.c b/lib/bluetooth.c
index 4af2ef6..3a4e3f4 100644
--- a/lib/bluetooth.c
+++ b/lib/bluetooth.c
@@ -55,8 +55,7 @@ char *batostr(const bdaddr_t *ba)
return NULL;
sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
- ba->b[0], ba->b[1], ba->b[2],
- ba->b[3], ba->b[4], ba->b[5]);
+ ba->b[0], ba->b[1], ba->b[2], ba->b[3], ba->b[4], ba->b[5]);
return str;
}
@@ -80,29 +79,30 @@ bdaddr_t *strtoba(const char *str)
return (bdaddr_t *) ba;
}
+/* reverse bdaddr and do batostr */
int ba2str(const bdaddr_t *ba, char *str)
{
- uint8_t b[6];
-
- baswap((bdaddr_t *) b, ba);
- return sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
- b[0], b[1], b[2], b[3], b[4], b[5]);
+ bdaddr_t b;
+ char *bastr;
+
+ baswap(&b, ba);
+ bastr = batostr(&b);
+ strcpy(str, bastr);
+ bt_free(bastr);
+ return *str && 1;
}
+/* do strtoba and return reverse bdaddr */
int str2ba(const char *str, bdaddr_t *ba)
{
- uint8_t b[6];
- const char *ptr = str;
+ bdaddr_t *b;
int i;
- for (i = 0; i < 6; i++) {
- b[i] = (uint8_t) strtol(ptr, NULL, 16);
- if (i != 5 && !(ptr = strchr(ptr, ':')))
- ptr = ":00:00:00:00:00";
- ptr++;
- }
-
- baswap(ba, (bdaddr_t *) b);
+ b = strtoba(str);
+ if (b == NULL)
+ return 0;
+ baswap(ba, b);
+ bt_free(b);
return 0;
}
--
1.7.0.4
^ permalink raw reply related
* [PATCH 1/4] Filtering interface name from program arguments
From: Michal Labedzki @ 2010-12-27 11:02 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Michal Labedzki
tools: Name must be "hciX", where X is 0..HCI_MAX_DEV. Any other like "tty1, ""hci001"
or "hci1x" will no longer work as "hci1".
tools: Add info that "bdaddr" can be put for parameter "interface".
---
attrib/gatttool.c | 9 ++++++---
compat/pand.c | 2 +-
lib/hci.c | 53 +++++++++++++++++++++++++++++++++++++++++++++--------
lib/hci_lib.h | 1 +
test/hciemu.c | 9 +++++----
test/l2test.c | 8 +++++---
test/rctest.c | 10 ++++++----
tools/ciptool.c | 9 +++++----
tools/hciconfig.c | 8 +++++++-
tools/hcitool.c | 4 ++--
tools/l2ping.c | 12 +++++++-----
tools/main.c | 7 ++++---
tools/sdptool.c | 9 +++++----
13 files changed, 99 insertions(+), 42 deletions(-)
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index a234e36..43b4f57 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -105,10 +105,13 @@ static GIOChannel *do_connect(gboolean le)
/* Local adapter */
if (opt_src != NULL) {
- if (!strncmp(opt_src, "hci", 3))
- hci_devba(atoi(opt_src + 3), &sba);
- else
+ int devid;
+
+ devid = hci_filter_devname(opt_src);
+ if (devid < 0)
str2ba(opt_src, &sba);
+ else
+ hci_devba(devid, &sba);
} else
bacpy(&sba, BDADDR_ANY);
diff --git a/compat/pand.c b/compat/pand.c
index c3860fa..7331fad 100644
--- a/compat/pand.c
+++ b/compat/pand.c
@@ -586,7 +586,7 @@ static const char *main_help =
"\t--role -r <role> Local PAN role (PANU, NAP, GN)\n"
"\t--service -d <role> Remote PAN service (PANU, NAP, GN)\n"
"\t--ethernet -e <name> Network interface name\n"
- "\t--device -i <bdaddr> Source bdaddr\n"
+ "\t--device -i <hciX|bdaddr> Source interface or bdaddr\n"
"\t--nosdp -D Disable SDP\n"
"\t--auth -A Enable authentication\n"
"\t--encrypt -E Enable encryption\n"
diff --git a/lib/hci.c b/lib/hci.c
index 048fda4..bb01d90 100644
--- a/lib/hci.c
+++ b/lib/hci.c
@@ -887,22 +887,57 @@ int hci_get_route(bdaddr_t *bdaddr)
(long) (bdaddr ? bdaddr : BDADDR_ANY));
}
+/* return 1 if string is ecimal number without leading zeros
+ * return 0 if not */
+static int is_devnumber(const char *c)
+{
+ if (c[0] == '0' && c[1] != 0)
+ return 0;
+
+ while (*c) {
+ if (*c < '0' || *c > '9')
+ return 0;
+ ++c;
+ }
+ return 1;
+}
+
+/* return HCI dev_id from string like "hciX", where X is dev_id
+ * return -1 if string not match */
+int hci_filter_devname(const char *str)
+{
+ int dev_id;
+
+ if ((strlen(str) >= 4) && (!strncmp(str, "hci", 3)) &&
+ (is_devnumber(str + 3)))
+ dev_id = atoi(str + 3);
+ else
+ dev_id = -1;
+
+ if (dev_id >= HCI_MAX_DEV)
+ dev_id = -1;
+
+ return dev_id;
+}
+
+/* return dev_id, which is on UP state, from 'hciX' or 'bdaddr'
+ * otherwise return -1 */
int hci_devid(const char *str)
{
bdaddr_t ba;
- int id = -1;
+ int dev_id;
- if (!strncmp(str, "hci", 3) && strlen(str) >= 4) {
- id = atoi(str + 3);
- if (hci_devba(id, &ba) < 0)
- return -1;
- } else {
+ dev_id = hci_filter_devname(str);
+ if (dev_id < 0) {
errno = ENODEV;
str2ba(str, &ba);
- id = hci_for_each_dev(HCI_UP, __same_bdaddr, (long) &ba);
+ dev_id = hci_for_each_dev(HCI_UP, __same_bdaddr, (long) &ba);
+ } else {
+ if (hci_devba(dev_id, &ba) < 0)
+ return -1;
}
- return id;
+ return dev_id;
}
int hci_devinfo(int dev_id, struct hci_dev_info *di)
@@ -925,6 +960,8 @@ int hci_devinfo(int dev_id, struct hci_dev_info *di)
return ret;
}
+/* return status 0 and bdaddr assigned to dev_id
+ * otherwise status -1 */
int hci_devba(int dev_id, bdaddr_t *bdaddr)
{
struct hci_dev_info di;
diff --git a/lib/hci_lib.h b/lib/hci_lib.h
index b63a2a4..ef00f99 100644
--- a/lib/hci_lib.h
+++ b/lib/hci_lib.h
@@ -60,6 +60,7 @@ int hci_inquiry(int dev_id, int len, int num_rsp, const uint8_t *lap, inquiry_in
int hci_devinfo(int dev_id, struct hci_dev_info *di);
int hci_devba(int dev_id, bdaddr_t *bdaddr);
int hci_devid(const char *str);
+int hci_filter_devname(const char *str);
int hci_read_local_name(int dd, int len, char *name, int to);
int hci_write_local_name(int dd, const char *name, int to);
diff --git a/test/hciemu.c b/test/hciemu.c
index a20374f..ae33d72 100644
--- a/test/hciemu.c
+++ b/test/hciemu.c
@@ -1234,15 +1234,16 @@ int main(int argc, char *argv[])
exit(1);
}
- if (strlen(argv[0]) > 3 && !strncasecmp(argv[0], "hci", 3)) {
+ dev = hci_filter_devname(argv[0]);
+ if (dev < 0) {
+ if (getbdaddrbyname(argv[0], &vdev.bdaddr) < 0)
+ exit(1);
+ } else {
dev = hci_devid(argv[0]);
if (dev < 0) {
perror("Invalid device");
exit(1);
}
- } else {
- if (getbdaddrbyname(argv[0], &vdev.bdaddr) < 0)
- exit(1);
}
if (detach) {
diff --git a/test/l2test.c b/test/l2test.c
index 17883a9..438ba39 100644
--- a/test/l2test.c
+++ b/test/l2test.c
@@ -1101,6 +1101,7 @@ int main(int argc, char *argv[])
{
struct sigaction sa;
int opt, sk, mode = RECV, need_addr = 0;
+ int devid;
bacpy(&bdaddr, BDADDR_ANY);
@@ -1175,10 +1176,11 @@ int main(int argc, char *argv[])
break;
case 'i':
- if (!strncasecmp(optarg, "hci", 3))
- hci_devba(atoi(optarg + 3), &bdaddr);
- else
+ devid = hci_filter_devname(optarg);
+ if (devid < 0)
str2ba(optarg, &bdaddr);
+ else
+ hci_devba(devid, &bdaddr);
break;
case 'P':
diff --git a/test/rctest.c b/test/rctest.c
index b3804f5..a828ad9 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -579,7 +579,7 @@ static void usage(void)
"\t-m multiple connects\n");
printf("Options:\n"
- "\t[-b bytes] [-i device] [-P channel] [-U uuid]\n"
+ "\t[-b bytes] [-i hciX|bdaddr] [-P channel] [-U uuid]\n"
"\t[-L seconds] enabled SO_LINGER option\n"
"\t[-W seconds] enable deferred setup\n"
"\t[-B filename] use data packets from file\n"
@@ -597,6 +597,7 @@ int main(int argc, char *argv[])
{
struct sigaction sa;
int opt, sk, mode = RECV, need_addr = 0;
+ int devid;
bacpy(&bdaddr, BDADDR_ANY);
@@ -644,10 +645,11 @@ int main(int argc, char *argv[])
break;
case 'i':
- if (!strncasecmp(optarg, "hci", 3))
- hci_devba(atoi(optarg + 3), &bdaddr);
- else
+ devid = hci_filter_devname(optarg);
+ if (devid < 0)
str2ba(optarg, &bdaddr);
+ else
+ hci_devba(devid, &bdaddr);
break;
case 'P':
diff --git a/tools/ciptool.c b/tools/ciptool.c
index edce9da..ec602ef 100644
--- a/tools/ciptool.c
+++ b/tools/ciptool.c
@@ -427,7 +427,7 @@ static void usage(void)
"\n");
printf("Options:\n"
- "\t-i [hciX|bdaddr] Local HCI device or BD Address\n"
+ "\t-i <hciX|bdaddr> Local HCI device or BD Address\n"
"\t-h, --help Display help\n"
"\n");
@@ -455,10 +455,11 @@ int main(int argc, char *argv[])
while ((opt = getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
switch(opt) {
case 'i':
- if (!strncmp(optarg, "hci", 3))
- hci_devba(atoi(optarg + 3), &bdaddr);
- else
+ i = hci_filter_devname(optarg);
+ if (i < 0)
str2ba(optarg, &bdaddr);
+ else
+ hci_devba(i, &bdaddr);
break;
case 'h':
usage();
diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index f0ae11c..e20963d 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -1849,7 +1849,13 @@ int main(int argc, char *argv[])
exit(0);
}
- di.dev_id = atoi(argv[0] + 3);
+ i = hci_filter_devname(argv[0]);
+ if (i < 0) {
+ fprintf(stderr, "No valid device name.\n");
+ exit(1);
+ }
+ di.dev_id = i;
+
argc--; argv++;
if (ioctl(ctl, HCIGETDEVINFO, (void *) &di)) {
diff --git a/tools/hcitool.c b/tools/hcitool.c
index d50adaf..dc70e63 100644
--- a/tools/hcitool.c
+++ b/tools/hcitool.c
@@ -2560,8 +2560,8 @@ static void usage(void)
printf("Usage:\n"
"\thcitool [options] <command> [command parameters]\n");
printf("Options:\n"
- "\t--help\tDisplay help\n"
- "\t-i dev\tHCI device\n");
+ "\t--help Display help\n"
+ "\t-i <hciX|bdaddr> Local HCI device or BD Address\n");
printf("Commands:\n");
for (i = 0; command[i].cmd; i++)
printf("\t%-4s\t%s\n", command[i].cmd,
diff --git a/tools/l2ping.c b/tools/l2ping.c
index 29fb3d0..dd0ccbd 100644
--- a/tools/l2ping.c
+++ b/tools/l2ping.c
@@ -255,7 +255,8 @@ static void usage(void)
{
printf("l2ping - L2CAP ping\n");
printf("Usage:\n");
- printf("\tl2ping [-i device] [-s size] [-c count] [-t timeout] [-d delay] [-f] [-r] [-v] <bdaddr>\n");
+ printf("\tl2ping [-i <hciX|bdaddr> local hci or bd address] [-s size]"
+ "[-c count] [-t timeout] [-d delay] [-f] [-r] [-v] <bdaddr>\n");
printf("\t-f Flood ping (delay = 0)\n");
printf("\t-r Reverse ping\n");
printf("\t-v Verify request and response payload\n");
@@ -264,17 +265,18 @@ static void usage(void)
int main(int argc, char *argv[])
{
int opt;
-
+ int devid;
/* Default options */
bacpy(&bdaddr, BDADDR_ANY);
while ((opt=getopt(argc,argv,"i:d:s:c:t:frv")) != EOF) {
switch(opt) {
case 'i':
- if (!strncasecmp(optarg, "hci", 3))
- hci_devba(atoi(optarg + 3), &bdaddr);
- else
+ devid = hci_filter_devname(optarg);
+ if (devid < 0)
str2ba(optarg, &bdaddr);
+ else
+ hci_devba(devid, &bdaddr);
break;
case 'd':
diff --git a/tools/main.c b/tools/main.c
index 6800445..c000fba 100644
--- a/tools/main.c
+++ b/tools/main.c
@@ -753,10 +753,11 @@ int main(int argc, char *argv[])
while ((opt = getopt_long(argc, argv, "+i:f:rahAESML:", main_options, NULL)) != -1) {
switch(opt) {
case 'i':
- if (strncmp(optarg, "hci", 3) == 0)
- hci_devba(atoi(optarg + 3), &bdaddr);
- else
+ dev_id = hci_filter_devname(optarg);
+ if (dev_id < 0)
str2ba(optarg, &bdaddr);
+ else
+ hci_devba(dev_id, &bdaddr);
break;
case 'f':
diff --git a/tools/sdptool.c b/tools/sdptool.c
index 140a46a..c782e62 100644
--- a/tools/sdptool.c
+++ b/tools/sdptool.c
@@ -4209,7 +4209,7 @@ static void usage(void)
"\tsdptool [options] <command> [command parameters]\n");
printf("Options:\n"
"\t-h\t\tDisplay help\n"
- "\t-i\t\tSpecify source interface\n");
+ "\t-i\t\tSpecify source interface or bdaddr\n");
printf("Commands:\n");
for (i = 0; command[i].cmd; i++)
@@ -4242,10 +4242,11 @@ int main(int argc, char *argv[])
while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
switch(opt) {
case 'i':
- if (!strncmp(optarg, "hci", 3))
- hci_devba(atoi(optarg + 3), &interface);
- else
+ i = hci_filter_devname(optarg);
+ if (i < 0)
str2ba(optarg, &interface);
+ else
+ hci_devba(i, &interface);
break;
case 'h':
--
1.7.0.4
^ permalink raw reply related
* Re: [PATCH] Add Broadcaster property in DeviceFound signal
From: Johan Hedberg @ 2010-12-23 22:40 UTC (permalink / raw)
To: Sheldon Demario; +Cc: linux-bluetooth
In-Reply-To: <1293139987-17536-1-git-send-email-sheldon.demario@openbossa.org>
Hi Sheldon,
On Thu, Dec 23, 2010, Sheldon Demario wrote:
> Broadcaster property is required to distinguish the device role. If the remote
> is sending an advertising event, two possible roles are possible: Peripheral or
> Broadcaster.
>
> This change is required to pass on qualification tests which require filtering
> Broadcasting devices during General Discovery Procedure.
> ---
> doc/adapter-api.txt | 3 ++-
> src/adapter.c | 8 ++++++++
> 2 files changed, 10 insertions(+), 1 deletions(-)
Pushed upstream after I reformated your commit message to properly fit a
80 column wide terminal. Please pay attention to that in the future.
Johan
^ permalink raw reply
* Re: [PATCH v5 2/5] Change CreatePairedDevice to support LE devices
From: Johan Hedberg @ 2010-12-23 22:37 UTC (permalink / raw)
To: Sheldon Demario; +Cc: linux-bluetooth
In-Reply-To: <1293139790-9646-1-git-send-email-sheldon.demario@openbossa.org>
Hi Sheldon,
On Thu, Dec 23, 2010, Sheldon Demario wrote:
> CreatePairedDevice implements now the same behaviour of CreateDevice,
> triggering Discover All Primary Services when needed. SMP negotiation
> starts when the link is established. LE capable kernel is required to
> test this method properly.
>
> Limitation: For dual mode devices, Discover All Primary Services is not
> being executed after SDP search if GATT record is found.
> ---
> src/adapter.c | 102 +++++++++++++++++++++++++++++++++++++----------------
> src/device.c | 89 ++++++++++++++++++++++++----------------------
> src/device.h | 5 ++-
> src/glib-helper.c | 12 +++++-
> src/glib-helper.h | 1 +
> 5 files changed, 132 insertions(+), 77 deletions(-)
Pushed upstream. Thanks.
Johan
^ permalink raw reply
* [PATCH] Add Broadcaster property in DeviceFound signal
From: Sheldon Demario @ 2010-12-23 21:33 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Sheldon Demario
Broadcaster property is required to distinguish the device role. If the remote
is sending an advertising event, two possible roles are possible: Peripheral or
Broadcaster.
This change is required to pass on qualification tests which require filtering
Broadcasting devices during General Discovery Procedure.
---
doc/adapter-api.txt | 3 ++-
src/adapter.c | 8 ++++++++
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt
index f287f29..5272d74 100644
--- a/doc/adapter-api.txt
+++ b/doc/adapter-api.txt
@@ -185,7 +185,8 @@ Signals PropertyChanged(string name, variant value)
The dictionary can contain basically the same values
that are returned by the GetProperties method
from the org.bluez.Device interface. In addition there
- can be values for the RSSI and the TX power level.
+ can be values for the RSSI, the TX power level and
+ Broadcaster role.
DeviceDisappeared(string address)
diff --git a/src/adapter.c b/src/adapter.c
index bf92211..fddf0ad 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2829,12 +2829,20 @@ void adapter_emit_device_found(struct btd_adapter *adapter,
}
if (dev->le) {
+ gboolean broadcaster;
+
+ if (dev->flags & (EIR_LIM_DISC | EIR_GEN_DISC))
+ broadcaster = FALSE;
+ else
+ broadcaster = TRUE;
+
emit_device_found(adapter->path, paddr,
"Address", DBUS_TYPE_STRING, &paddr,
"RSSI", DBUS_TYPE_INT16, &rssi,
"Name", DBUS_TYPE_STRING, &dev->name,
"Paired", DBUS_TYPE_BOOLEAN, &paired,
"UUIDs", DBUS_TYPE_ARRAY, &dev->uuids,
+ "Broadcaster", DBUS_TYPE_BOOLEAN, &broadcaster,
dev->uuid_count, NULL);
return;
}
--
1.7.3.2
^ permalink raw reply related
* [PATCH v5 2/5] Change CreatePairedDevice to support LE devices
From: Sheldon Demario @ 2010-12-23 21:29 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Sheldon Demario
In-Reply-To: <20101221084243.GA14108@jh-x301>
CreatePairedDevice implements now the same behaviour of CreateDevice,
triggering Discover All Primary Services when needed. SMP negotiation
starts when the link is established. LE capable kernel is required to
test this method properly.
Limitation: For dual mode devices, Discover All Primary Services is not
being executed after SDP search if GATT record is found.
---
src/adapter.c | 102 +++++++++++++++++++++++++++++++++++++----------------
src/device.c | 89 ++++++++++++++++++++++++----------------------
src/device.h | 5 ++-
src/glib-helper.c | 12 +++++-
src/glib-helper.h | 1 +
5 files changed, 132 insertions(+), 77 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 1913171..fddf0ad 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1520,15 +1520,48 @@ static gboolean event_is_connectable(uint8_t type)
}
}
+static struct btd_device *create_device_internal(DBusConnection *conn,
+ struct btd_adapter *adapter,
+ const gchar *address,
+ gboolean force, int *err)
+{
+ struct remote_dev_info *dev, match;
+ struct btd_device *device;
+ device_type_t type;
+
+ memset(&match, 0, sizeof(struct remote_dev_info));
+ str2ba(address, &match.bdaddr);
+ match.name_status = NAME_ANY;
+
+ dev = adapter_search_found_devices(adapter, &match);
+ if (dev && dev->flags)
+ type = flags2type(dev->flags);
+ else
+ type = DEVICE_TYPE_BREDR;
+
+ if (!force && type == DEVICE_TYPE_LE &&
+ !event_is_connectable(dev->evt_type)) {
+ if (err)
+ *err = -ENOTCONN;
+
+ return NULL;
+ }
+
+ device = adapter_create_device(conn, adapter, address, type);
+ if (!device && err)
+ *err = -ENOMEM;
+
+ return device;
+}
+
static DBusMessage *create_device(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct btd_adapter *adapter = data;
struct btd_device *device;
- struct remote_dev_info *dev, match;
const gchar *address;
+ DBusMessage *reply;
int err;
- device_type_t type;
if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address,
DBUS_TYPE_INVALID) == FALSE)
@@ -1545,41 +1578,36 @@ static DBusMessage *create_device(DBusConnection *conn,
DBG("%s", address);
- memset(&match, 0, sizeof(struct remote_dev_info));
- str2ba(address, &match.bdaddr);
- match.name_status = NAME_ANY;
+ device = create_device_internal(conn, adapter, address, TRUE, &err);
+ if (!device)
+ goto failed;
- dev = adapter_search_found_devices(adapter, &match);
- if (dev && dev->flags)
- type = flags2type(dev->flags);
+ if (device_get_type(device) != DEVICE_TYPE_LE)
+ err = device_browse_sdp(device, conn, msg, NULL, FALSE);
else
- type = DEVICE_TYPE_BREDR;
+ err = device_browse_primary(device, conn, msg, FALSE);
- device = adapter_create_device(conn, adapter, address, type);
- if (!device)
- return NULL;
+ if (err < 0) {
+ adapter_remove_device(conn, adapter, device, TRUE);
+ return btd_error_failed(msg, strerror(-err));
+ }
- if (type == DEVICE_TYPE_LE && !event_is_connectable(dev->evt_type)) {
+ return NULL;
+
+failed:
+ if (err == -ENOTCONN) {
/* Device is not connectable */
const char *path = device_get_path(device);
- DBusMessage *reply;
reply = dbus_message_new_method_return(msg);
dbus_message_append_args(reply,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
-
- return reply;
- }
-
- err = device_browse(device, conn, msg, NULL, FALSE);
- if (err < 0) {
- adapter_remove_device(conn, adapter, device, TRUE);
- return btd_error_failed(msg, strerror(-err));
- }
+ DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+ } else
+ reply = btd_error_failed(msg, strerror(-err));
- return NULL;
+ return reply;
}
static uint8_t parse_io_capability(const char *capability)
@@ -1604,6 +1632,7 @@ static DBusMessage *create_paired_device(DBusConnection *conn,
struct btd_device *device;
const gchar *address, *agent_path, *capability, *sender;
uint8_t cap;
+ int err;
if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address,
DBUS_TYPE_OBJECT_PATH, &agent_path,
@@ -1628,12 +1657,23 @@ static DBusMessage *create_paired_device(DBusConnection *conn,
if (cap == IO_CAPABILITY_INVALID)
return btd_error_invalid_args(msg);
- device = adapter_get_device(conn, adapter, address);
- if (!device)
- return btd_error_failed(msg,
- "Unable to create a new device object");
+ device = adapter_find_device(adapter, address);
+ if (!device) {
+ device = create_device_internal(conn, adapter, address,
+ FALSE, &err);
+ if (!device)
+ return btd_error_failed(msg, strerror(-err));
+ }
+
+ if (device_get_type(device) != DEVICE_TYPE_LE)
+ return device_create_bonding(device, conn, msg,
+ agent_path, cap);
- return device_create_bonding(device, conn, msg, agent_path, cap);
+ err = device_browse_primary(device, conn, msg, TRUE);
+ if (err < 0)
+ return btd_error_failed(msg, strerror(-err));
+
+ return NULL;
}
static gint device_path_cmp(struct btd_device *device, const gchar *path)
diff --git a/src/device.c b/src/device.c
index e093b82..c33b22b 100644
--- a/src/device.c
+++ b/src/device.c
@@ -588,7 +588,7 @@ static DBusMessage *discover_services(DBusConnection *conn,
return btd_error_invalid_args(msg);
if (strlen(pattern) == 0) {
- err = device_browse(device, conn, msg, NULL, FALSE);
+ err = device_browse_sdp(device, conn, msg, NULL, FALSE);
if (err < 0)
goto fail;
} else {
@@ -599,7 +599,7 @@ static DBusMessage *discover_services(DBusConnection *conn,
sdp_uuid128_to_uuid(&uuid);
- err = device_browse(device, conn, msg, &uuid, FALSE);
+ err = device_browse_sdp(device, conn, msg, &uuid, FALSE);
if (err < 0)
goto fail;
}
@@ -992,6 +992,11 @@ void device_get_name(struct btd_device *device, char *name, size_t len)
strncpy(name, device->name, len);
}
+device_type_t device_get_type(struct btd_device *device)
+{
+ return device->type;
+}
+
void device_remove_bonding(struct btd_device *device)
{
char filename[PATH_MAX + 1];
@@ -1599,41 +1604,62 @@ done:
browse_request_free(req);
}
-static struct browse_req *browse_primary(struct btd_device *device, int *err)
+int device_browse_primary(struct btd_device *device, DBusConnection *conn,
+ DBusMessage *msg, gboolean secure)
{
struct btd_adapter *adapter = device->adapter;
struct browse_req *req;
bdaddr_t src;
- int ret;
+ int err;
+
+ if (device->browse)
+ return -EBUSY;
req = g_new0(struct browse_req, 1);
req->device = btd_device_ref(device);
adapter_get_address(adapter, &src);
- ret = bt_discover_primary(&src, &device->bdaddr, -1, primary_cb, req,
- NULL);
-
- if (ret < 0) {
+ err = bt_discover_primary(&src, &device->bdaddr, -1, primary_cb, req,
+ secure, NULL);
+ if (err < 0) {
browse_request_free(req);
- if (err)
- *err = ret;
+ return err;
+ }
- return NULL;
+ if (conn == NULL)
+ conn = get_dbus_connection();
+
+ req->conn = dbus_connection_ref(conn);
+ device->browse = req;
+
+ if (msg) {
+ const char *sender = dbus_message_get_sender(msg);
+
+ req->msg = dbus_message_ref(msg);
+ /* Track the request owner to cancel it
+ * automatically if the owner exits */
+ req->listener_id = g_dbus_add_disconnect_watch(conn,
+ sender,
+ discover_services_req_exit,
+ req, NULL);
}
- return req;
+ return err;
}
-static struct browse_req *browse_sdp(struct btd_device *device, uuid_t *search,
- gboolean reverse, int *err)
+int device_browse_sdp(struct btd_device *device, DBusConnection *conn,
+ DBusMessage *msg, uuid_t *search, gboolean reverse)
{
struct btd_adapter *adapter = device->adapter;
struct browse_req *req;
bt_callback_t cb;
bdaddr_t src;
uuid_t uuid;
- int ret;
+ int err;
+
+ if (device->browse)
+ return -EBUSY;
adapter_get_address(adapter, &src);
@@ -1648,34 +1674,11 @@ static struct browse_req *browse_sdp(struct btd_device *device, uuid_t *search,
cb = browse_cb;
}
- ret = bt_search_service(&src, &device->bdaddr, &uuid, cb, req, NULL);
- if (ret < 0) {
+ err = bt_search_service(&src, &device->bdaddr, &uuid, cb, req, NULL);
+ if (err < 0) {
browse_request_free(req);
- if (err)
- *err = ret;
-
- return NULL;
- }
-
- return req;
-}
-
-int device_browse(struct btd_device *device, DBusConnection *conn,
- DBusMessage *msg, uuid_t *search, gboolean reverse)
-{
- struct browse_req *req;
- int err = 0;
-
- if (device->browse)
- return -EBUSY;
-
- if (device->type == DEVICE_TYPE_LE)
- req = browse_primary(device, &err);
- else
- req = browse_sdp(device, search, reverse, &err);
-
- if (req == NULL)
return err;
+ }
if (conn == NULL)
conn = get_dbus_connection();
@@ -1786,7 +1789,7 @@ static gboolean start_discovery(gpointer user_data)
{
struct btd_device *device = user_data;
- device_browse(device, NULL, NULL, NULL, TRUE);
+ device_browse_sdp(device, NULL, NULL, NULL, TRUE);
device->discov_timer = 0;
@@ -2123,7 +2126,7 @@ void device_bonding_complete(struct btd_device *device, uint8_t status)
device->discov_timer = 0;
}
- device_browse(device, bonding->conn, bonding->msg,
+ device_browse_sdp(device, bonding->conn, bonding->msg,
NULL, FALSE);
bonding_request_free(bonding);
diff --git a/src/device.h b/src/device.h
index 86721bf..5dea953 100644
--- a/src/device.h
+++ b/src/device.h
@@ -47,9 +47,12 @@ struct btd_device *device_create(DBusConnection *conn,
const gchar *address, device_type_t type);
void device_set_name(struct btd_device *device, const char *name);
void device_get_name(struct btd_device *device, char *name, size_t len);
+device_type_t device_get_type(struct btd_device *device);
void device_remove(struct btd_device *device, gboolean remove_stored);
gint device_address_cmp(struct btd_device *device, const gchar *address);
-int device_browse(struct btd_device *device, DBusConnection *conn,
+int device_browse_primary(struct btd_device *device, DBusConnection *conn,
+ DBusMessage *msg, gboolean secure);
+int device_browse_sdp(struct btd_device *device, DBusConnection *conn,
DBusMessage *msg, uuid_t *search, gboolean reverse);
void device_probe_drivers(struct btd_device *device, GSList *profiles);
const sdp_record_t *btd_device_get_record(struct btd_device *device,
diff --git a/src/glib-helper.c b/src/glib-helper.c
index 648dd62..01517a3 100644
--- a/src/glib-helper.c
+++ b/src/glib-helper.c
@@ -517,9 +517,11 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
int bt_discover_primary(const bdaddr_t *src, const bdaddr_t *dst, int psm,
bt_primary_t cb, void *user_data,
+ gboolean secure,
bt_destroy_t destroy)
{
struct gattrib_context *ctxt;
+ BtIOSecLevel sec_level;
GIOChannel *io;
ctxt = g_try_new0(struct gattrib_context, 1);
@@ -532,19 +534,25 @@ int bt_discover_primary(const bdaddr_t *src, const bdaddr_t *dst, int psm,
ctxt->cb = cb;
ctxt->destroy = destroy;
+ if (secure == TRUE)
+ sec_level = BT_IO_SEC_HIGH;
+ else
+ sec_level = BT_IO_SEC_LOW;
+
+
if (psm < 0)
io = bt_io_connect(BT_IO_L2CAP, connect_cb, ctxt, NULL, NULL,
BT_IO_OPT_SOURCE_BDADDR, src,
BT_IO_OPT_DEST_BDADDR, dst,
BT_IO_OPT_CID, GATT_CID,
- BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+ BT_IO_OPT_SEC_LEVEL, sec_level,
BT_IO_OPT_INVALID);
else
io = bt_io_connect(BT_IO_L2CAP, connect_cb, ctxt, NULL, NULL,
BT_IO_OPT_SOURCE_BDADDR, src,
BT_IO_OPT_DEST_BDADDR, dst,
BT_IO_OPT_PSM, psm,
- BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+ BT_IO_OPT_SEC_LEVEL, sec_level,
BT_IO_OPT_INVALID);
if (io == NULL) {
diff --git a/src/glib-helper.h b/src/glib-helper.h
index ad81d7f..25fe276 100644
--- a/src/glib-helper.h
+++ b/src/glib-helper.h
@@ -32,6 +32,7 @@ int bt_cancel_discovery(const bdaddr_t *src, const bdaddr_t *dst);
int bt_discover_primary(const bdaddr_t *src, const bdaddr_t *dst, int psm,
bt_primary_t cb, void *user_data,
+ gboolean secure,
bt_destroy_t destroy);
gchar *bt_uuid2string(uuid_t *uuid);
--
1.7.3.2
^ permalink raw reply related
* Re: [PATCH] Updated TODO list for LE HCI Scan, Advertise and Connect commands.
From: Claudio Takahasi @ 2010-12-23 20:41 UTC (permalink / raw)
To: Sumit Kumar BAJPAI; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <4765B7BC10CB4C488A56C73E15D6FBA31DA368123F@EXDCVYMBSTM005.EQ1STM.local>
Hi Sumit,
On Thu, Dec 23, 2010 at 7:07 AM, Sumit Kumar BAJPAI
<sumitkumar.bajpai@stericsson.com> wrote:
> Updated TODO list for HCI commands for LE that ST-Ericsson plans to
> implement and contribute back.
>
> ---
> TODO | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 93 insertions(+), 0 deletions(-)
>
> diff --git a/TODO b/TODO
> index 49a9e76..e62c6e5 100644
> --- a/TODO
> +++ b/TODO
> @@ -66,6 +66,99 @@ Low Energy
> Priority: Low
> Complexity: C2
>
> +- Implement Set Advertise data via Host interface. This Set Advertise Data is
> + used by advertising device to advertise with some data field. This is via
> + undirected and connectable events. Data field is maximum of 30 octets, and is
> + primarily used for small data advertisement. Scanning device can see in scan
> + results the advertised data as set by the advertising device.
> + See Volume 2, Part E, section 7.8.7 for more information.
> +
> + Priority: Low
> + Complexity: C1
> +
> +- Implement Set Advertise parameters via Host interface. This Set Advertise
> + parameters is used by advertising device to set advertising parameters. The
> + Host shall not issue this command when advertising is enabled in the
> + Controller; if it is the Command Disallowed error code shall be used.
> + See Volume 2, Part E, section 7.8.5 for more information.
> +
> + Priority: Low
> + Complexity: C1
> +
> +- Implement Set Scan Response Data via host interface. This data is set by the
> + advertiser in case it wants to send data only to those devices that are
> + currently actively scanning. This is via undirected and connectable events.
> + Data can be set before or after advertising and can be maximum of 30 octets.
> + See Volume 2, Part E, section 7.8.8 for more information.
> +
> + Priority: Low
> + Complexity: C1
We don't need to expose a method to allow the applications to change
the advertising parameters. The idea is to manage them automatically
based on the registered gatt servers.
Broadcaster Role is out of scope at the moment. Peripheral, we are
planning to start the implementation soon, but first we need to define
the GATT server API.
IMHO we need to align the advertising parameter settings with the
Adapter "Discoverable" property and the registered GATT servers.
Set Scan Response Data: I don't an answer at the moment.
> +
> +- Implement Read Advertise Channel Tx Power via Host interface. This Read
> + Advertise Channel Tx power is used by advertising host to read the transmit
> + power level used for LE advertising channel packets.
> + See Volume 2, Part E, section 7.8.6 for more information.
> +
> + Priority: Low
> + Complexity: C1
Could you please give an usage example?
If I understood correctly we will need a function
hci_le_read_xxx_tx_power() to fill the TX Power Level in the
advertising data, right?
> +
> +- Implement Add Device to White List in LE controller via host interface.
> + This command is used to add a single device to white list stored in the
> + controller. Once the device is in white list it should follow scan and
> + connect rules as stated in advertising filter policy.
> + See Volume 2, Part E, section 7.8.16 for more information.
> +
> + Priority: Low
> + Complexity: C1
> +
> +- Implement Remove Device from White List in LE controller via host interface.
> + This command is used to remove a single device from white list stored in the
> + controller. This command has certain restrictions on its usage. Command
> + complete event is generated on completion.
> + See Volume 2, Part E, section 7.8.17 for more information.
> +
> + Priority: Low
> + Complexity: C1
> +
> +- Implement Clear White List in LE controller via host interface. This command
> + is used to clear the white list stored in the controller. This command has
> + certain restrictions on its usage. This command has no command parameters
> + to be pushed on controller. Command complete event is generated on completion.
> + See Volume 2, Part E, section 7.8.15 for more information.
> +
> + Priority: Low
> + Complexity: C1
> +
> +- Implement Read White List Size in LE controller via host interface. This
> + command is used to read the maximum size of the white list supported by the
> + controller.
> + See Volume 2, Part E, section 7.8.14 for more information.
> +
> + Priority: Low
> + Complexity: C1
Maybe we will need this feature to implement the Register Application
API. Automatic connections are planned, but it can be useful to
reduce/filter the amount of advertising reports.
> +
> +- Implement Read LE buffer Size via host interface. This data is used to read
> + the maximum size of data portion of HCI LE ACL Data Packets sent from the
> + Host to the Controller. The Host will segment the data transmitted to the
> + Controller according to these values, so that the HCI Data Packets will
> + contain data with up to this size. The LE_Read_Buffer_Size command also
> + returns the total number of HCI LE ACL Data Packets that can be stored in
> + the data buffers of the Controller. The LE_Read_Buffer_Size command must be
> + issued by the Host before it sends any data to an LE Controller.
> + See Volume 2, Part E, section 7.8.2 for more information.
> +
> + Priority: Low
> + Complexity: C1
> +
> +- Implement LE Connection Update command via Host interface. The
> + LE_Connection_Update command is used to change the Link Layer connection
> + parameters of a connection. This command shall only be used when the local
> + device's role is Master.
> + See Volume 2, Part E, section 7.8.18 for more information.
> +
> + Priority: Medium
> + Complexity: C1
Is it necessary to notify the userpace or it is a kernel task only?
Please remove it if it is a kernel task.
For the other tasks I suggest to keep them in the TODO file to track
the missing features, no matter if we will use them directly(eg:
hcitool, hciconfig) or in the API/services implementation.
If possible please add the expected deliverable for each task, it will
make easier to other developers to contribute.
Regards.
Claudio
^ 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