* Re: [PATCH 2/2] Remove wrong checking for legacy devices
From: Anderson Lizardo @ 2011-04-29 18:44 UTC (permalink / raw)
To: Claudio Takahasi, Luiz Augusto von Dentz, linux-bluetooth
In-Reply-To: <BANLkTi=dTXOX+vcCnDt0Z4f9X5hRbyi7bg@mail.gmail.com>
On Fri, Apr 29, 2011 at 2:41 PM, Anderson Lizardo
<anderson.lizardo@openbossa.org> wrote:
> Hi Johan,
>
> On Fri, Apr 29, 2011 at 1:56 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
>>> BTW: why this information needs to be exposed through the DeviceFound() signal?
>>> It is not used internally in the adapter.c source.
>>
>> It's useful for pairing UIs. If a device is expected to produce legacy
>> pairing when calling CreatePairedDevice the UI can ask the user for the
>> PIN *before* calling CreatePairedDevice and thereby eliminate the risk of
>> user response timeout locally.
>
> Maybe this is useful do be documented on doc/device-api.txt? The
> LegacyPairing only mentions "This property is useful in the
> Adapter.DeviceFound signal to anticipate whether legacy or simple
> pairing will occur.", but it is not mentioned *why* the API user might
> want to detect legacy pairing devices.
On another story, I'm not sure about BR/EDR, but for LE there is a
timeout associated with SMP pairing. Would this "anticipate user PIN
request" thing be necessary on this case as well?
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH 2/2] Remove wrong checking for legacy devices
From: Anderson Lizardo @ 2011-04-29 18:41 UTC (permalink / raw)
To: Claudio Takahasi, Luiz Augusto von Dentz, linux-bluetooth
In-Reply-To: <20110429175625.GA29649@jh-x301>
Hi Johan,
On Fri, Apr 29, 2011 at 1:56 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
>> BTW: why this information needs to be exposed through the DeviceFound() signal?
>> It is not used internally in the adapter.c source.
>
> It's useful for pairing UIs. If a device is expected to produce legacy
> pairing when calling CreatePairedDevice the UI can ask the user for the
> PIN *before* calling CreatePairedDevice and thereby eliminate the risk of
> user response timeout locally.
Maybe this is useful do be documented on doc/device-api.txt? The
LegacyPairing only mentions "This property is useful in the
Adapter.DeviceFound signal to anticipate whether legacy or simple
pairing will occur.", but it is not mentioned *why* the API user might
want to detect legacy pairing devices.
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH 2/2] Remove wrong checking for legacy devices
From: Johan Hedberg @ 2011-04-29 17:56 UTC (permalink / raw)
To: Claudio Takahasi; +Cc: Luiz Augusto von Dentz, linux-bluetooth
In-Reply-To: <BANLkTin=vjdpnB3v9-AfXwPjvGV+F1wP4Q@mail.gmail.com>
Hi Claudio,
On Fri, Apr 29, 2011, Claudio Takahasi wrote:
> > On Fri, Apr 29, 2011 at 1:34 AM, Claudio Takahasi
> > <claudio.takahasi@openbossa.org> wrote:
> >> Infer that the found device is a legacy device based on the presence
> >> of its name in the storage is wrong.
> >> ---
> >> src/event.c | 2 --
> >> 1 files changed, 0 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/src/event.c b/src/event.c
> >> index 5373e33..b873000 100644
> >> --- a/src/event.c
> >> +++ b/src/event.c
> >> @@ -481,8 +481,6 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
> >>
> >> if (data)
> >> legacy = FALSE;
> >> - else if (name == NULL)
> >> - legacy = TRUE;
> >> else if (read_remote_features(local, peer, NULL, features) == 0) {
> >> if (features[0] & 0x01)
> >> legacy = FALSE;
> >> --
> >
> > That was some use of it, but I can't remember now, maybe some broken
> > stack which has feature bits broken or we do actually infer if we ever
> > connect to the device before trying to read its features from the
> > storage.
> >
> >
> > --
> > Luiz Augusto von Dentz
> > Computer Engineer
> >
>
> I found the commit that introduced this code, but it is still not clear to me:
> 989c60c0b9c96edf1fbdf80356abf05bac336673
I think the logic has gone like this: we get the remote features as a
side effect of a successful remote name request, so by checking for the
name first we don't do an unnecessary file-system lookup.
> BTW: why this information needs to be exposed through the DeviceFound() signal?
> It is not used internally in the adapter.c source.
It's useful for pairing UIs. If a device is expected to produce legacy
pairing when calling CreatePairedDevice the UI can ask the user for the
PIN *before* calling CreatePairedDevice and thereby eliminate the risk of
user response timeout locally.
Johan
^ permalink raw reply
* Re: [PATCH 2/2] Remove wrong checking for legacy devices
From: Claudio Takahasi @ 2011-04-29 12:53 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <BANLkTimm=CVbBrLEPWf8Q0BgvtMmZaxNBg@mail.gmail.com>
Hi Luiz,
On Fri, Apr 29, 2011 at 8:27 AM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> Hi Claudio,
>
> On Fri, Apr 29, 2011 at 1:34 AM, Claudio Takahasi
> <claudio.takahasi@openbossa.org> wrote:
>> Infer that the found device is a legacy device based on the presence
>> of its name in the storage is wrong.
>> ---
>> src/event.c | 2 --
>> 1 files changed, 0 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/event.c b/src/event.c
>> index 5373e33..b873000 100644
>> --- a/src/event.c
>> +++ b/src/event.c
>> @@ -481,8 +481,6 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
>>
>> if (data)
>> legacy = FALSE;
>> - else if (name == NULL)
>> - legacy = TRUE;
>> else if (read_remote_features(local, peer, NULL, features) == 0) {
>> if (features[0] & 0x01)
>> legacy = FALSE;
>> --
>
> That was some use of it, but I can't remember now, maybe some broken
> stack which has feature bits broken or we do actually infer if we ever
> connect to the device before trying to read its features from the
> storage.
>
>
> --
> Luiz Augusto von Dentz
> Computer Engineer
>
I found the commit that introduced this code, but it is still not clear to me:
989c60c0b9c96edf1fbdf80356abf05bac336673
BTW: why this information needs to be exposed through the DeviceFound() signal?
It is not used internally in the adapter.c source.
BR,
Claudio
^ permalink raw reply
* Re: [PATCH 2/2] Remove wrong checking for legacy devices
From: Luiz Augusto von Dentz @ 2011-04-29 11:27 UTC (permalink / raw)
To: Claudio Takahasi; +Cc: linux-bluetooth
In-Reply-To: <1304030070-6575-2-git-send-email-claudio.takahasi@openbossa.org>
Hi Claudio,
On Fri, Apr 29, 2011 at 1:34 AM, Claudio Takahasi
<claudio.takahasi@openbossa.org> wrote:
> Infer that the found device is a legacy device based on the presence
> of its name in the storage is wrong.
> ---
> src/event.c | 2 --
> 1 files changed, 0 insertions(+), 2 deletions(-)
>
> diff --git a/src/event.c b/src/event.c
> index 5373e33..b873000 100644
> --- a/src/event.c
> +++ b/src/event.c
> @@ -481,8 +481,6 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
>
> if (data)
> legacy = FALSE;
> - else if (name == NULL)
> - legacy = TRUE;
> else if (read_remote_features(local, peer, NULL, features) == 0) {
> if (features[0] & 0x01)
> legacy = FALSE;
> --
That was some use of it, but I can't remember now, maybe some broken
stack which has feature bits broken or we do actually infer if we ever
connect to the device before trying to read its features from the
storage.
--
Luiz Augusto von Dentz
Computer Engineer
^ permalink raw reply
* [PATCH] Fix crash when calling finalize_setup_errno
From: Luiz Augusto von Dentz @ 2011-04-29 10:56 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
finalize_setup_errno last parameter must be NULL otherwise it may access
invalid memory.
---
audio/a2dp.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/audio/a2dp.c b/audio/a2dp.c
index 741b134..9cd7207 100644
--- a/audio/a2dp.c
+++ b/audio/a2dp.c
@@ -775,7 +775,7 @@ static void endpoint_open_cb(struct media_endpoint *endpoint, void *ret,
if (ret == NULL) {
setup->stream = NULL;
- finalize_setup_errno(setup, -EPERM, finalize_config);
+ finalize_setup_errno(setup, -EPERM, finalize_config, NULL);
return;
}
@@ -785,7 +785,7 @@ static void endpoint_open_cb(struct media_endpoint *endpoint, void *ret,
error("Error on avdtp_open %s (%d)", strerror(-err), -err);
setup->stream = NULL;
- finalize_setup_errno(setup, err, finalize_config);
+ finalize_setup_errno(setup, err, finalize_config, NULL);
}
static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
@@ -842,7 +842,7 @@ static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
return;
setup->stream = NULL;
- finalize_setup_errno(setup, -EPERM, finalize_config);
+ finalize_setup_errno(setup, -EPERM, finalize_config, NULL);
return;
}
@@ -850,7 +850,7 @@ static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
if (ret < 0) {
error("Error on avdtp_open %s (%d)", strerror(-ret), -ret);
setup->stream = NULL;
- finalize_setup_errno(setup, ret, finalize_config);
+ finalize_setup_errno(setup, ret, finalize_config, NULL);
}
}
@@ -1043,7 +1043,7 @@ static void suspend_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
perr = avdtp_start(session, a2dp_sep->stream);
if (perr < 0) {
error("Error on avdtp_start %s (%d)", strerror(-perr), -perr);
- finalize_setup_errno(setup, -EIO, finalize_suspend);
+ finalize_setup_errno(setup, -EIO, finalize_suspend, NULL);
}
}
@@ -1064,7 +1064,7 @@ static gboolean close_ind(struct avdtp *session, struct avdtp_local_sep *sep,
return TRUE;
finalize_setup_errno(setup, -ECONNRESET, finalize_suspend,
- finalize_resume);
+ finalize_resume, NULL);
return TRUE;
}
@@ -1097,7 +1097,7 @@ static gboolean a2dp_reconfigure(gpointer data)
return FALSE;
failed:
- finalize_setup_errno(setup, posix_err, finalize_config);
+ finalize_setup_errno(setup, posix_err, finalize_config, NULL);
return FALSE;
}
--
1.7.1
^ permalink raw reply related
* FW: [PATCH] Check session->msg at sync_getphonebook_callback() in file client/sync.c
From: Zheng, Wu @ 2011-04-29 10:05 UTC (permalink / raw)
To: vinicius.gomes@openbossa.org; +Cc: linux-bluetooth@vger.kernel.org
Hi:
I will modify the code style and thank you.
> -----Original Message-----
> From: Vinicius Costa Gomes [mailto:vinicius.gomes@openbossa.org]
> Sent: Wednesday, April 27, 2011 2:42 AM
> To: Zheng, Wu
> Cc: linux-bluetooth@vger.kernel.org
> Subject: Re: [PATCH] Check session->msg at sync_getphonebook_callback()
> in file client/sync.c
>
> Hi,
>
> On 11:03 Tue 26 Apr, Zheng, Wu wrote:
> > Otherwise,session->msg will be NULL and cause segmentation fault
> error.The reason is that the condition of transfer->fd>0 && session-
> >msg is ok and session->msg will be set to NULL in the func of
> session_notify_progress when sync profile is used.
>
> Please try to keep your commit title to less than 72 characters (if
> possible
> less than 50) and the commit message to less than 72 characters.
>
> >
> > ---
> > client/sync.c | 5 +++++
> > 1 files changed, 5 insertions(+), 0 deletions(-)
> >
> > diff --git a/client/sync.c b/client/sync.c
> > index 3622a3d..28ace61 100644
> > --- a/client/sync.c
> > +++ b/client/sync.c
> > @@ -78,6 +78,9 @@ static void sync_getphonebook_callback(struct
> session_data *session,
> > DBusMessage *reply;
> > char *buf = NULL;
> >
> > + if (session->msg == NULL)
> > + goto done;
> > +
> > reply = dbus_message_new_method_return(session->msg);
> >
> > if (transfer->filled > 0)
> > @@ -91,6 +94,8 @@ static void sync_getphonebook_callback(struct
> session_data *session,
> > g_dbus_send_message(session->conn, reply);
> > dbus_message_unref(session->msg);
> > session->msg = NULL;
>
> Add an empty line here.
>
> > +done:
> > + transfer_unregister(transfer);
>
> There's a trailing space here.
>
> Also, taking a look at the code, if the reply is big enough (is it
> possible?),
> the callback could be called more than one time for one transfer, right?
> Seems
> it would cause some unexpected problems.
>
The callback will only be invoked once when one transfer of sync is completed.
The reason of checking session->msg = NULL is that the func of session_notify_progress will set session->msg = NULL in the process of transferring.
> > }
> >
> > static DBusMessage *sync_getphonebook(DBusConnection *connection,
> > --
> > 1.7.3.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
>
>
> Cheers,
> --
> Vinicius
^ permalink raw reply
* RE: [PATCH v3 5/7] Bluetooth: Double check sec req for pre 2.1 device
From: Waldemar.Rymarkiewicz @ 2011-04-29 8:30 UTC (permalink / raw)
To: johan.hedberg, padovan, linux-bluetooth
In-Reply-To: <20110428210852.GA25436@jh-x301>
Johan,
>Never mind. d->sec_level is obviously the security requirement
>for the RFCOMM link which could be different from the current
>ACL security level. Nevertheless, I think instead of doing the
>complicated if-statement on the key_type & pin_length you can
>simply check the value of conn->sec_level.
>
I agree. Will update and send again.
Waldek
^ permalink raw reply
* RE: [PATCH v3 5/7] Bluetooth: Double check sec req for pre 2.1 device
From: Waldemar.Rymarkiewicz @ 2011-04-29 8:23 UTC (permalink / raw)
To: padovan; +Cc: johan.hedberg, linux-bluetooth
In-Reply-To: <20110428180939.GA2302@joana>
Hi Gustavo,
>> +static int rfcomm_accept_secure(struct hci_conn *conn, struct
>> +rfcomm_dlc *d) {
>> + BT_DBG("");
>> +
>> + if (d->sec_level != BT_SECURITY_HIGH)
>> + return 1; /* Accept */
>> +
>> + if (conn->key_type == HCI_LK_AUTH_COMBINATION ||
>> + (conn->key_type == HCI_LK_COMBINATION &&
>> + conn->pin_length == 16))
>> + return 1;
>> +
>> + return 0; /* Reject */
>> +}
>
>I don't like the idea of mix HCI and RFCOMM code, I prefer
>that you create an hci_accept_secure(conn, d->sec_level) instead.
We could do like this
static int hci_accept_secure(hci_conn *conn, u8 required_sec_level)
{
if (required_sec_level != BT_SECURITY_HIGH)
return 1; /* Accept */
if (conn->sec_level == BT_SECURITY_HIGH)
return 1;
return 0;
}
Waldek
^ permalink raw reply
* RE: [PATCH v3 5/7] Bluetooth: Double check sec req for pre 2.1 device
From: Waldemar.Rymarkiewicz @ 2011-04-29 8:10 UTC (permalink / raw)
To: johan.hedberg; +Cc: padovan, linux-bluetooth
In-Reply-To: <20110428181117.GA11610@jh-x301>
Hi Johan,
>> +static int rfcomm_accept_secure(struct hci_conn *conn, struct
>> +rfcomm_dlc *d) {
>> + BT_DBG("");
>> +
>> + if (d->sec_level != BT_SECURITY_HIGH)
>> + return 1; /* Accept */
>> +
>> + if (conn->key_type == HCI_LK_AUTH_COMBINATION ||
>> + (conn->key_type == HCI_LK_COMBINATION &&
>> + conn->pin_length == 16))
>> + return 1;
>> +
>> + return 0; /* Reject */
>> +}
>
>If conn->key_type and conn->pin_length are like you want them
>to be in the second if-statement, shouldn't conn->sec_level
>already be BT_SECURITY_HIGH?
Yes, but if service requires BT_SECURITY_MEDIUM we should accept it as well. Thus, we need this first check.
>And if that's the case I guess
>you don't need a separate function at all: just check for
>conn->sec_level.
However, we could do like this
if (d->sec_level != BT_SECURITY_HIGH)
return 1; /* Accept */
If (conn->sec_level == BT_SECURITY_HIGH)
return 1; /* Accept */
return 0; /* Reject */
... and then perhaps we don't need a new function here.
> Btw, what purpose does d->sec_level serve
>when we already have conn->sec_level?
d->sec_level is required sec level for the service and conn->sec_level is the level that's already on the link.
/Waldek
^ permalink raw reply
* Re: [PATCH] bluetooth: Fix for security block issue.
From: Mika Linnanoja @ 2011-04-29 7:49 UTC (permalink / raw)
To: linux-bluetooth
Cc: ext Ville Tervo, Antti Julku, ext Marcel Holtmann,
Lukasz Rymanowski, linus.walleij, par-gunnar.p.hjalmdahl, padovan
In-Reply-To: <20110428095139.GJ18898@null>
On 04/28/2011 12:51 PM, ext Ville Tervo wrote:
> Could the actual reason be some change in usb stack? Could it have lower
> priority for event pipe than for data pipe? In that case event for security
> change might arrive to bt stack too late.
>
> At lest I haven't seen this kind of behaviour with serial attached chips. So I
> think this is something USB specific.
Happens on Ubuntu 11.04 (released yesterday; bluez 4.91 & kernel 2.6.38-8) as
well, tested with White PTS 2.1 dongle (CSR chip) on laptop x61s. Sending
party (OPP with obex-client in a loop) was a phone.
Cheers,
Mika
^ permalink raw reply
* [PATCH] Modify the condition of removing filters of dbus at filter_data_remove_callback and message_filter in file gdbus/watch.c
From: wu zheng @ 2011-04-29 7:23 UTC (permalink / raw)
To: linux-bluetooth; +Cc: wu zheng
After Checking the code style, and send the patch again.
Otherwise, removing filter will run twice when using g_dbus_add_signal_watch with sender and cause dbus remove filter error and crash.The result is that g_dbus_add_signal_watch will inovke g_dbus_add_service_watch if the param of sender of g_dbus_add_signal_watch is avaliable and add two callback and only add a dbus filter, which result in the func of g_dbus_remove_watch will remove dbus filter twice. When using telephony-ofono for telephony, add_watch will add signal watch with sender at telephony_init and remove_watch will be inovked at telephony_exit in file audio/telephony-ofono.c, which result in bluez crash when using telephony-ofono.c.
Signed-off-by: wu zheng <wu.zheng@intel.com>
---
gdbus/watch.c | 21 +++++++++++++++------
1 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/gdbus/watch.c b/gdbus/watch.c
index fba58c3..4f4533e 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -266,15 +266,16 @@ static struct filter_callback *filter_data_find_callback(
return NULL;
}
-static void filter_data_free(struct filter_data *data)
+static gboolean filter_data_free(struct filter_data *data)
{
GSList *l;
+ gboolean watch_removed;
for (l = data->callbacks; l != NULL; l = l->next)
g_free(l->data);
g_slist_free(data->callbacks);
- g_dbus_remove_watch(data->connection, data->name_watch);
+ watch_removed = g_dbus_remove_watch(data->connection, data->name_watch);
g_free(data->name);
g_free(data->owner);
g_free(data->path);
@@ -283,6 +284,8 @@ static void filter_data_free(struct filter_data *data)
g_free(data->argument);
dbus_connection_unref(data->connection);
g_free(data);
+
+ return watch_removed;
}
static void filter_data_call_and_free(struct filter_data *data)
@@ -350,6 +353,8 @@ static gboolean filter_data_remove_callback(struct filter_data *data,
struct filter_callback *cb)
{
DBusConnection *connection;
+ guint name_watch;
+ gboolean watch_removed;
data->callbacks = g_slist_remove(data->callbacks, cb);
data->processed = g_slist_remove(data->processed, cb);
@@ -375,13 +380,14 @@ static gboolean filter_data_remove_callback(struct filter_data *data,
return FALSE;
connection = dbus_connection_ref(data->connection);
+ name_watch = data->name_watch;
listeners = g_slist_remove(listeners, data);
- filter_data_free(data);
+ watch_removed = filter_data_free(data);
/* Remove filter if there are no listeners left for the connection */
data = filter_data_find(connection, NULL, NULL, NULL, NULL, NULL,
NULL);
- if (data == NULL)
+ if (data == NULL && (name_watch == 0 || watch_removed == FALSE))
dbus_connection_remove_filter(connection, message_filter,
NULL);
@@ -502,6 +508,8 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
{
struct filter_data *data;
const char *sender, *path, *iface, *member, *arg = NULL;
+ guint name_watch;
+ gboolean watch_removed;
/* Only filter signals */
if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
@@ -536,13 +544,14 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
remove_match(data);
+ name_watch = data->name_watch;
listeners = g_slist_remove(listeners, data);
- filter_data_free(data);
+ watch_removed = filter_data_free(data);
/* Remove filter if there no listener left for the connection */
data = filter_data_find(connection, NULL, NULL, NULL, NULL, NULL,
NULL);
- if (data == NULL)
+ if (data == NULL && (name_watch == 0 || watch_removed == FALSE))
dbus_connection_remove_filter(connection, message_filter,
NULL);
--
1.7.3.4
^ permalink raw reply related
* [PATCH] Modify the condition of removing filters of dbus at filter_data_remove_callback and message_filter in file gdbus/watch.c
From: wu.zheng @ 2011-04-29 4:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: wu.zheng
Otherwise, removing filter will run twice when using g_dbus_add_signal_watch with sender and cause dbus remove filter error and crash.The result is that g_dbus_add_signal_watch will inovke g_dbus_add_service_watch if the param of sender of g_dbus_add_signal_watch is avaliable and add two callback and only add a dbus filter, which result in the func of g_dbus_remove_watch will remove dbus filter twice. When using telephony-ofono for telephony, add_watch will add signal watch with sender at telephony_init and remove_watch will be inovked at telephony_exit in file audio/telephony-ofono.c, which result in bluez crash when using telephony-ofono.c.
---
gdbus/watch.c | 21 +++++++++++++++------
1 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/gdbus/watch.c b/gdbus/watch.c
index fba58c3..1304083 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -266,15 +266,16 @@ static struct filter_callback *filter_data_find_callback(
return NULL;
}
-static void filter_data_free(struct filter_data *data)
+static gboolean filter_data_free(struct filter_data *data)
{
GSList *l;
+ gboolean watch_removed;
for (l = data->callbacks; l != NULL; l = l->next)
g_free(l->data);
g_slist_free(data->callbacks);
- g_dbus_remove_watch(data->connection, data->name_watch);
+ watch_removed = g_dbus_remove_watch(data->connection, data->name_watch);
g_free(data->name);
g_free(data->owner);
g_free(data->path);
@@ -283,6 +284,8 @@ static void filter_data_free(struct filter_data *data)
g_free(data->argument);
dbus_connection_unref(data->connection);
g_free(data);
+
+ return watch_removed;
}
static void filter_data_call_and_free(struct filter_data *data)
@@ -350,6 +353,8 @@ static gboolean filter_data_remove_callback(struct filter_data *data,
struct filter_callback *cb)
{
DBusConnection *connection;
+ guint name_watch;
+ gboolean watch_removed;
data->callbacks = g_slist_remove(data->callbacks, cb);
data->processed = g_slist_remove(data->processed, cb);
@@ -375,13 +380,14 @@ static gboolean filter_data_remove_callback(struct filter_data *data,
return FALSE;
connection = dbus_connection_ref(data->connection);
+ name_watch = data->name_watch;
listeners = g_slist_remove(listeners, data);
- filter_data_free(data);
+ watch_removed = filter_data_free(data);
/* Remove filter if there are no listeners left for the connection */
data = filter_data_find(connection, NULL, NULL, NULL, NULL, NULL,
NULL);
- if (data == NULL)
+ if (data == NULL && (name_watch == 0 || watch_removed == FALSE))
dbus_connection_remove_filter(connection, message_filter,
NULL);
@@ -502,6 +508,8 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
{
struct filter_data *data;
const char *sender, *path, *iface, *member, *arg = NULL;
+ guint name_watch;
+ gboolean watch_removed;
/* Only filter signals */
if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
@@ -536,13 +544,14 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
remove_match(data);
+ name_watch = data->name_watch;
listeners = g_slist_remove(listeners, data);
- filter_data_free(data);
+ watch_removed = filter_data_free(data);
/* Remove filter if there no listener left for the connection */
data = filter_data_find(connection, NULL, NULL, NULL, NULL, NULL,
NULL);
- if (data == NULL)
+ if (data == NULL && (name_watch == 0 || watch_removed == FALSE))
dbus_connection_remove_filter(connection, message_filter,
NULL);
--
1.7.3.4
^ permalink raw reply related
* [PATCH 13/13] Drop variable EIR length
From: Claudio Takahasi @ 2011-04-28 22:37 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Bruna Moreira
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
From: Bruna Moreira <bruna.moreira@openbossa.org>
The functions eir_parse() and adapter_update_found_devices() now
assume that the EIR buffer has always 240 octets. For advertising
reports, the advertising data is stored on a buffer with 240 bytes,
padded with zeroes.
---
plugins/hciops.c | 13 +++++++++----
src/adapter.c | 5 ++---
src/adapter.h | 3 +--
src/eir.c | 8 ++++----
src/eir.h | 2 +-
src/event.c | 2 +-
6 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/plugins/hciops.c b/plugins/hciops.c
index 91d5778..8b7befa 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2080,7 +2080,7 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
{
struct dev_info *dev = &devs[index];
le_advertising_info *info;
- uint8_t num_reports, rssi;
+ uint8_t num_reports, rssi, eir[HCI_MAX_EIR_LENGTH];
const uint8_t RSSI_SIZE = 1;
num_reports = meta->data[0];
@@ -2088,8 +2088,11 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
info = (le_advertising_info *) &meta->data[1];
rssi = *(info->data + info->length);
+ memset(eir, 0, sizeof(eir));
+ memcpy(eir, info->data, info->length);
+
btd_event_device_found(&dev->bdaddr, &info->bdaddr,
- info->bdaddr_type, 0, rssi, info->data);
+ info->bdaddr_type, 0, rssi, eir);
num_reports--;
@@ -2098,9 +2101,11 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
RSSI_SIZE);
rssi = *(info->data + info->length);
+ memset(eir, 0, sizeof(eir));
+ memcpy(eir, info->data, info->length);
+
btd_event_device_found(&dev->bdaddr, &info->bdaddr,
- info->bdaddr_type, 0,
- rssi, info->data);
+ info->bdaddr_type, 0, rssi, eir);
}
}
diff --git a/src/adapter.c b/src/adapter.c
index bae7324..cd9df75 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3114,8 +3114,7 @@ static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
uint8_t bda_type, uint32_t class,
- int8_t rssi, uint8_t *data,
- size_t eir_size)
+ int8_t rssi, uint8_t *data)
{
struct remote_dev_info *dev, match;
struct eir_data eir_data;
@@ -3125,7 +3124,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
int err, type;
memset(&eir_data, 0, sizeof(eir_data));
- err = eir_parse(&eir_data, data, HCI_MAX_EIR_LENGTH);
+ err = eir_parse(&eir_data, data);
if (err < 0) {
error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
return;
diff --git a/src/adapter.h b/src/adapter.h
index 931be37..f296389 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -120,8 +120,7 @@ struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter
struct remote_dev_info *match);
void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
uint8_t bda_type, uint32_t class,
- int8_t rssi, uint8_t *data,
- size_t eir_size);
+ int8_t rssi, uint8_t *data);
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/eir.c b/src/eir.c
index 7dfc444..01b6ac5 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -52,7 +52,7 @@ void eir_data_free(struct eir_data *eir)
g_free(eir->name);
}
-int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
+int eir_parse(struct eir_data *eir, uint8_t *eir_data)
{
uint16_t len = 0;
size_t total;
@@ -69,10 +69,10 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
eir->flags = -1;
/* No EIR data to parse */
- if (eir_data == NULL || eir_length == 0)
+ if (eir_data == NULL)
return 0;
- while (len < eir_length - 1) {
+ while (len < HCI_MAX_EIR_LENGTH - 1) {
uint8_t field_len = eir_data[0];
/* Check for the end of EIR */
@@ -115,7 +115,7 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
}
/* Bail out if got incorrect length */
- if (len > eir_length)
+ if (len > HCI_MAX_EIR_LENGTH)
return -EINVAL;
total = uuid16_count + uuid32_count + uuid128_count;
diff --git a/src/eir.h b/src/eir.h
index ea38570..d225973 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -35,7 +35,7 @@ struct eir_data {
};
void eir_data_free(struct eir_data *eir);
-int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length);
+int eir_parse(struct eir_data *eir, uint8_t *eir_data);
void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
uint16_t did_product, uint16_t did_version,
GSList *uuids, uint8_t *data);
diff --git a/src/event.c b/src/event.c
index 2b83ea7..4390c54 100644
--- a/src/event.c
+++ b/src/event.c
@@ -302,7 +302,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint8_t bda_type,
}
adapter_update_found_devices(adapter, peer, bda_type, class,
- rssi, data, HCI_MAX_EIR_LENGTH);
+ rssi, data);
}
void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
--
1.7.5.rc3
^ permalink raw reply related
* [PATCH 12/13] Replace EIR_DATA_LENGTH with HCI_MAX_EIR_LENGTH
From: Claudio Takahasi @ 2011-04-28 22:37 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Bruna Moreira
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
From: Bruna Moreira <bruna.moreira@openbossa.org>
Both defines have the same value (240) and meaning.
---
src/adapter.c | 2 +-
src/eir.c | 9 +++++----
src/eir.h | 2 --
src/event.c | 2 +-
4 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 29a018a..bae7324 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3125,7 +3125,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
int err, type;
memset(&eir_data, 0, sizeof(eir_data));
- err = eir_parse(&eir_data, data, EIR_DATA_LENGTH);
+ err = eir_parse(&eir_data, data, HCI_MAX_EIR_LENGTH);
if (err < 0) {
error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
return;
diff --git a/src/eir.c b/src/eir.c
index 2fbd919..7dfc444 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -27,6 +27,7 @@
#include <glib.h>
#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
#include <bluetooth/sdp.h>
#include "glib-helper.h"
@@ -184,7 +185,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
continue;
/* Stop if not enough space to put next UUID128 */
- if ((len + 2 + SIZEOF_UUID128) > EIR_DATA_LENGTH) {
+ if ((len + 2 + SIZEOF_UUID128) > HCI_MAX_EIR_LENGTH) {
truncated = TRUE;
break;
}
@@ -229,7 +230,7 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
GSList *l;
uint8_t *ptr = data;
uint16_t eir_len = 0;
- uint16_t uuid16[EIR_DATA_LENGTH / 2];
+ uint16_t uuid16[HCI_MAX_EIR_LENGTH / 2];
int i, uuid_count = 0;
gboolean truncated = FALSE;
size_t name_len;
@@ -289,7 +290,7 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
continue;
/* Stop if not enough space to put next UUID16 */
- if ((eir_len + 2 + sizeof(uint16_t)) > EIR_DATA_LENGTH) {
+ if ((eir_len + 2 + sizeof(uint16_t)) > HCI_MAX_EIR_LENGTH) {
truncated = TRUE;
break;
}
@@ -322,6 +323,6 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
}
/* Group all UUID128 types */
- if (eir_len <= EIR_DATA_LENGTH - 2)
+ if (eir_len <= HCI_MAX_EIR_LENGTH - 2)
eir_generate_uuid128(uuids, ptr, &eir_len);
}
diff --git a/src/eir.h b/src/eir.h
index aacd16a..ea38570 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -22,8 +22,6 @@
*
*/
-#define EIR_DATA_LENGTH 240
-
struct uuid_info {
uuid_t uuid;
uint8_t svc_hint;
diff --git a/src/event.c b/src/event.c
index 6dc40c0..2b83ea7 100644
--- a/src/event.c
+++ b/src/event.c
@@ -302,7 +302,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint8_t bda_type,
}
adapter_update_found_devices(adapter, peer, bda_type, class,
- rssi, data, EIR_DATA_LENGTH);
+ rssi, data, HCI_MAX_EIR_LENGTH);
}
void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
--
1.7.5.rc3
^ permalink raw reply related
* [PATCH 11/13] Cleanup inserting new device found entry
From: Claudio Takahasi @ 2011-04-28 22:37 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
---
src/adapter.c | 97 +++++++++++++++++++++++++++-----------------------------
1 files changed, 47 insertions(+), 50 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 7fb92e3..29a018a 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3030,29 +3030,24 @@ void adapter_emit_device_found(struct btd_adapter *adapter,
g_free(alias);
}
-static struct remote_dev_info *get_found_dev(struct btd_adapter *adapter,
- const bdaddr_t *bdaddr,
- gboolean *new_dev)
+static struct remote_dev_info *found_device_new(const bdaddr_t *bdaddr,
+ gboolean le, const char *name,
+ const char *alias, uint32_t class,
+ gboolean legacy, name_status_t status,
+ int flags)
{
- struct remote_dev_info *dev, match;
+ struct remote_dev_info *dev;
- memset(&match, 0, sizeof(struct remote_dev_info));
- bacpy(&match.bdaddr, bdaddr);
- match.name_status = NAME_ANY;
-
- dev = adapter_search_found_devices(adapter, &match);
- if (dev) {
- *new_dev = FALSE;
- /* Out of range list update */
- adapter->oor_devices = g_slist_remove(adapter->oor_devices,
- dev);
- } else {
- *new_dev = TRUE;
- dev = g_new0(struct remote_dev_info, 1);
- bacpy(&dev->bdaddr, bdaddr);
- adapter->found_devices = g_slist_prepend(adapter->found_devices,
- dev);
- }
+ dev = g_new0(struct remote_dev_info, 1);
+ bacpy(&dev->bdaddr, bdaddr);
+ dev->le = le;
+ dev->name = g_strdup(name);
+ dev->alias = g_strdup(alias);
+ dev->class = class;
+ dev->legacy = legacy;
+ dev->name_status = status;
+ if (flags >= 0)
+ dev->flags = flags;
return dev;
}
@@ -3122,11 +3117,11 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
int8_t rssi, uint8_t *data,
size_t eir_size)
{
- struct remote_dev_info *dev;
+ struct remote_dev_info *dev, match;
struct eir_data eir_data;
- char *name;
- gboolean new_dev, legacy, le;
- name_status_t name_status = NAME_NOT_REQUIRED;
+ char *alias, *name;
+ gboolean legacy, le;
+ name_status_t name_status;
int err, type;
memset(&eir_data, 0, sizeof(eir_data));
@@ -3139,6 +3134,25 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
if (eir_data.name != NULL && eir_data.name_complete)
write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
+ /* Device already seen in the discovery session ? */
+ memset(&match, 0, sizeof(struct remote_dev_info));
+ bacpy(&match.bdaddr, bdaddr);
+ match.name_status = NAME_ANY;
+
+ dev = adapter_search_found_devices(adapter, &match);
+ if (dev) {
+ adapter->oor_devices = g_slist_remove(adapter->oor_devices,
+ dev);
+ if (dev->rssi != rssi)
+ goto done;
+
+ eir_data_free(&eir_data);
+
+ return;
+ }
+
+ /* New device in the discovery session */
+
name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
switch (bda_type) {
@@ -3146,6 +3160,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
case BRADDR_TYPE_LE_RANDOM:
le = TRUE;
legacy = FALSE;
+ name_status = NAME_NOT_REQUIRED;
break;
default:
/* BDADDR_TYPE_BR */
@@ -3164,32 +3179,16 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
break;
}
- dev = get_found_dev(adapter, bdaddr, &new_dev);
-
- if (new_dev) {
- const char *dev_name = (name ? name : eir_data.name);
- char *alias;
+ alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
- if (dev_name)
- dev->name = g_strdup(dev_name);
-
- alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
- if (alias) {
- dev->alias = g_strdup(alias);
- free(alias);
- }
-
- dev->le = FALSE;
- dev->class = class;
- dev->legacy = legacy;
- dev->name_status = name_status;
+ dev = found_device_new(bdaddr, le, name, alias, class, legacy,
+ name_status, eir_data.flags);
+ free(name);
+ free(alias);
- if (eir_data.flags >= 0)
- dev->flags = eir_data.flags;
-
- } else if (dev->rssi == rssi)
- goto done;
+ adapter->found_devices = g_slist_prepend(adapter->found_devices, dev);
+done:
dev->rssi = rssi;
adapter->found_devices = g_slist_sort(adapter->found_devices,
@@ -3200,8 +3199,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
adapter_emit_device_found(adapter, dev);
-done:
- free(name);
eir_data_free(&eir_data);
}
--
1.7.5.rc3
^ permalink raw reply related
* [PATCH 10/13] Change the order to write/read the remote's name
From: Claudio Takahasi @ 2011-04-28 22:37 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
When discovering, write the EIR "complete" name first before to read
the name. Only names retrieved from EIR "complete" name and HCI Remote
Name Request Complete event are stored. This patch doesn't change the
final result: the value of the name sent in the signal.
---
src/adapter.c | 19 +++++--------------
1 files changed, 5 insertions(+), 14 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index f96c115..7fb92e3 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3127,7 +3127,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
char *name;
gboolean new_dev, legacy, le;
name_status_t name_status = NAME_NOT_REQUIRED;
- const char *dev_name;
int err, type;
memset(&eir_data, 0, sizeof(eir_data));
@@ -3137,6 +3136,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
return;
}
+ if (eir_data.name != NULL && eir_data.name_complete)
+ write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
+
name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
switch (bda_type) {
@@ -3162,23 +3164,12 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
break;
}
- /* Complete EIR names are always used. Shortened EIR names are only
- * used if there is no name already in storage. */
- dev_name = name;
- if (eir_data.name != NULL) {
- if (eir_data.name_complete) {
- write_device_name(&adapter->bdaddr, bdaddr,
- eir_data.name);
- name_status = NAME_NOT_REQUIRED;
- dev_name = eir_data.name;
- } else if (name == NULL)
- dev_name = eir_data.name;
- }
-
dev = get_found_dev(adapter, bdaddr, &new_dev);
if (new_dev) {
+ const char *dev_name = (name ? name : eir_data.name);
char *alias;
+
if (dev_name)
dev->name = g_strdup(dev_name);
--
1.7.5.rc3
^ permalink raw reply related
* [PATCH 09/13] Remove btd_event_advertising_report
From: Claudio Takahasi @ 2011-04-28 22:37 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Bruna Moreira
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
From: Bruna Moreira <bruna.moreira@openbossa.org>
Advertises should be notified using btd_event_device_found function
to keep the compatibility with mgmtops plugin.
---
plugins/hciops.c | 27 +++++++++++++++++++--------
plugins/mgmtops.c | 3 ++-
src/event.c | 24 +++---------------------
src/event.h | 5 ++---
4 files changed, 26 insertions(+), 33 deletions(-)
diff --git a/plugins/hciops.c b/plugins/hciops.c
index c2aa614..91d5778 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -1805,8 +1805,8 @@ static inline void inquiry_result(int index, int plen, void *ptr)
(info->dev_class[1] << 8) |
(info->dev_class[2] << 16);
- btd_event_device_found(&dev->bdaddr, &info->bdaddr, class,
- 0, NULL);
+ btd_event_device_found(&dev->bdaddr, &info->bdaddr,
+ BDADDR_TYPE_BR, class, 0, NULL);
ptr += INQUIRY_INFO_SIZE;
}
}
@@ -1828,7 +1828,8 @@ static inline void inquiry_result_with_rssi(int index, int plen, void *ptr)
| (info->dev_class[2] << 16);
btd_event_device_found(&dev->bdaddr, &info->bdaddr,
- class, info->rssi, NULL);
+ BDADDR_TYPE_BR, class,
+ info->rssi, NULL);
ptr += INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE;
}
} else {
@@ -1839,7 +1840,8 @@ static inline void inquiry_result_with_rssi(int index, int plen, void *ptr)
| (info->dev_class[2] << 16);
btd_event_device_found(&dev->bdaddr, &info->bdaddr,
- class, info->rssi, NULL);
+ BDADDR_TYPE_BR, class,
+ info->rssi, NULL);
ptr += INQUIRY_INFO_WITH_RSSI_SIZE;
}
}
@@ -1857,7 +1859,8 @@ static inline void extended_inquiry_result(int index, int plen, void *ptr)
| (info->dev_class[1] << 8)
| (info->dev_class[2] << 16);
- btd_event_device_found(&dev->bdaddr, &info->bdaddr, class,
+ btd_event_device_found(&dev->bdaddr, &info->bdaddr,
+ BDADDR_TYPE_BR, class,
info->rssi, info->data);
ptr += EXTENDED_INQUIRY_INFO_SIZE;
}
@@ -2077,19 +2080,27 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
{
struct dev_info *dev = &devs[index];
le_advertising_info *info;
- uint8_t num_reports;
+ uint8_t num_reports, rssi;
const uint8_t RSSI_SIZE = 1;
num_reports = meta->data[0];
info = (le_advertising_info *) &meta->data[1];
- btd_event_advertising_report(&dev->bdaddr, info);
+ rssi = *(info->data + info->length);
+
+ btd_event_device_found(&dev->bdaddr, &info->bdaddr,
+ info->bdaddr_type, 0, rssi, info->data);
+
num_reports--;
while (num_reports--) {
info = (le_advertising_info *) (info->data + info->length +
RSSI_SIZE);
- btd_event_advertising_report(&dev->bdaddr, info);
+ rssi = *(info->data + info->length);
+
+ btd_event_device_found(&dev->bdaddr, &info->bdaddr,
+ info->bdaddr_type, 0,
+ rssi, info->data);
}
}
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index be94267..15f024a 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -1321,7 +1321,8 @@ static void mgmt_device_found(int sk, uint16_t index, void *buf, size_t len)
DBG("hci%u addr %s, class %u rssi %d %s", index, addr, cls,
ev->rssi, eir ? "eir" : "");
- btd_event_device_found(&info->bdaddr, &ev->bdaddr, cls, ev->rssi, eir);
+ btd_event_device_found(&info->bdaddr, &ev->bdaddr, BDADDR_TYPE_BR,
+ cls, ev->rssi, eir);
}
static void mgmt_remote_name(int sk, uint16_t index, void *buf, size_t len)
diff --git a/src/event.c b/src/event.c
index 84a51cf..6dc40c0 100644
--- a/src/event.c
+++ b/src/event.c
@@ -250,23 +250,6 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
device_simple_pairing_complete(device, status);
}
-void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
-{
- struct btd_adapter *adapter;
- int8_t rssi;
-
- adapter = manager_find_adapter(local);
- if (adapter == NULL) {
- error("No matching adapter found");
- return;
- }
-
- rssi = *(info->data + info->length);
-
- adapter_update_found_devices(adapter, &info->bdaddr, info->bdaddr_type,
- 0, rssi, info->data, info->length);
-}
-
static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
{
time_t t;
@@ -289,8 +272,8 @@ static void update_lastused(bdaddr_t *sba, bdaddr_t *dba)
write_lastused_info(sba, dba, tm);
}
-void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
- int8_t rssi, uint8_t *data)
+void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint8_t bda_type,
+ uint32_t class, int8_t rssi, uint8_t *data)
{
struct btd_adapter *adapter;
int state;
@@ -318,9 +301,8 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
adapter_set_state(adapter, state);
}
- adapter_update_found_devices(adapter, peer, BDADDR_TYPE_BR, class,
+ adapter_update_found_devices(adapter, peer, bda_type, class,
rssi, data, EIR_DATA_LENGTH);
-
}
void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
diff --git a/src/event.h b/src/event.h
index 765390a..16a900c 100644
--- a/src/event.h
+++ b/src/event.h
@@ -23,9 +23,8 @@
*/
int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba);
-void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info);
-void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
- int8_t rssi, uint8_t *data);
+void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint8_t bda_type,
+ uint32_t class, int8_t rssi, uint8_t *data);
void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer, gboolean legacy);
void btd_event_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class);
void btd_event_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, char *name);
--
1.7.5.rc3
^ permalink raw reply related
* [PATCH 08/13] Fix memory leak of EIR data
From: Claudio Takahasi @ 2011-04-28 22:37 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
---
src/adapter.c | 1 +
src/eir.c | 7 +++++++
src/eir.h | 1 +
3 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 7612eb6..f96c115 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3211,6 +3211,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
done:
free(name);
+ eir_data_free(&eir_data);
}
int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr)
diff --git a/src/eir.c b/src/eir.c
index d827c7e..2fbd919 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -44,6 +44,13 @@
#define EIR_TX_POWER 0x0A /* transmit power level */
#define EIR_DEVICE_ID 0x10 /* device ID */
+void eir_data_free(struct eir_data *eir)
+{
+ g_slist_foreach(eir->services, (GFunc) g_free, NULL);
+ g_slist_free(eir->services);
+ g_free(eir->name);
+}
+
int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
{
uint16_t len = 0;
diff --git a/src/eir.h b/src/eir.h
index c7699eb..aacd16a 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -36,6 +36,7 @@ struct eir_data {
gboolean name_complete;
};
+void eir_data_free(struct eir_data *eir);
int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length);
void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
uint16_t did_product, uint16_t did_version,
--
1.7.5.rc3
^ permalink raw reply related
* [PATCH 07/13] Unify inquiry results and advertises
From: Claudio Takahasi @ 2011-04-28 22:37 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
Adapter needs to have only one method to allow discovery results
integration for both interfaces: hciops and mgmtops. This patch
moves the code related to advertises parsing to the same function
that handles inquiry results.
---
src/adapter.c | 80 ++++++++++++++++++++++-----------------------------------
src/adapter.h | 8 ++---
src/event.c | 25 +++---------------
3 files changed, 38 insertions(+), 75 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index f2be3ba..7612eb6 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3082,43 +3082,6 @@ static void dev_prepend_uuid(gpointer data, gpointer user_data)
dev->services = g_slist_prepend(dev->services, g_strdup(new_uuid));
}
-void adapter_update_device_from_info(struct btd_adapter *adapter,
- bdaddr_t bdaddr, int8_t rssi,
- uint8_t evt_type, const char *name,
- GSList *services, int flags)
-{
- struct remote_dev_info *dev;
- gboolean new_dev;
-
- dev = get_found_dev(adapter, &bdaddr, &new_dev);
-
- if (new_dev) {
- dev->le = TRUE;
- dev->evt_type = evt_type;
- } else if (dev->rssi == rssi)
- return;
-
- dev->rssi = rssi;
-
- adapter->found_devices = g_slist_sort(adapter->found_devices,
- (GCompareFunc) dev_rssi_cmp);
-
- g_slist_foreach(services, remove_same_uuid, dev);
- g_slist_foreach(services, dev_prepend_uuid, dev);
-
- if (flags >= 0)
- dev->flags = flags;
-
- if (name) {
- g_free(dev->name);
- dev->name = g_strdup(name);
- }
-
- /* FIXME: check if other information was changed before emitting the
- * signal */
- adapter_emit_device_found(adapter, dev);
-}
-
static int remote_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
uint8_t *data, gboolean *legacy)
{
@@ -3155,13 +3118,15 @@ static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
}
void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
- uint32_t class, int8_t rssi, uint8_t *data)
+ uint8_t bda_type, uint32_t class,
+ int8_t rssi, uint8_t *data,
+ size_t eir_size)
{
struct remote_dev_info *dev;
struct eir_data eir_data;
char *name;
- gboolean new_dev, legacy;
- name_status_t name_status;
+ gboolean new_dev, legacy, le;
+ name_status_t name_status = NAME_NOT_REQUIRED;
const char *dev_name;
int err, type;
@@ -3172,17 +3137,30 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
return;
}
- if (remote_legacy_pairing(&adapter->bdaddr, bdaddr, data, &legacy) < 0)
- legacy = TRUE;
-
name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
- type = adapter_get_discover_type(adapter);
- if (!name && type & DISC_RESOLVNAME &&
- adapter_has_discov_sessions(adapter))
- name_status = NAME_REQUIRED;
- else
- name_status = NAME_NOT_REQUIRED;
+ switch (bda_type) {
+ case BDADDR_TYPE_LE_PUBLIC:
+ case BRADDR_TYPE_LE_RANDOM:
+ le = TRUE;
+ legacy = FALSE;
+ break;
+ default:
+ /* BDADDR_TYPE_BR */
+ le = FALSE;
+ if (remote_legacy_pairing(&adapter->bdaddr, bdaddr,
+ data, &legacy) < 0)
+ legacy = TRUE;
+
+ type = adapter_get_discover_type(adapter);
+
+ if (!name && type & DISC_RESOLVNAME &&
+ adapter_has_discov_sessions(adapter))
+ name_status = NAME_REQUIRED;
+ else
+ name_status = NAME_NOT_REQUIRED;
+ break;
+ }
/* Complete EIR names are always used. Shortened EIR names are only
* used if there is no name already in storage. */
@@ -3214,6 +3192,10 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
dev->class = class;
dev->legacy = legacy;
dev->name_status = name_status;
+
+ if (eir_data.flags >= 0)
+ dev->flags = eir_data.flags;
+
} else if (dev->rssi == rssi)
goto done;
diff --git a/src/adapter.h b/src/adapter.h
index 94707e5..931be37 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -118,12 +118,10 @@ 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,
- bdaddr_t bdaddr, int8_t rssi,
- uint8_t evt_type, const char *name,
- GSList *services, int flags);
void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
- uint32_t class, int8_t rssi, uint8_t *data);
+ uint8_t bda_type, uint32_t class,
+ int8_t rssi, uint8_t *data,
+ size_t eir_size);
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 263d428..84a51cf 100644
--- a/src/event.c
+++ b/src/event.c
@@ -250,19 +250,10 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
device_simple_pairing_complete(device, status);
}
-static void free_eir_data(struct eir_data *eir)
-{
- g_slist_foreach(eir->services, (GFunc) g_free, NULL);
- g_slist_free(eir->services);
- g_free(eir->name);
-}
-
void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
{
struct btd_adapter *adapter;
- struct eir_data eir_data;
int8_t rssi;
- int err;
adapter = manager_find_adapter(local);
if (adapter == NULL) {
@@ -270,19 +261,10 @@ void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
return;
}
- memset(&eir_data, 0, sizeof(eir_data));
- err = eir_parse(&eir_data, info->data, info->length);
- if (err < 0)
- error("Error parsing advertising data: %s (%d)",
- strerror(-err), -err);
-
rssi = *(info->data + info->length);
- adapter_update_device_from_info(adapter, info->bdaddr, rssi,
- info->evt_type, eir_data.name,
- eir_data.services, eir_data.flags);
-
- free_eir_data(&eir_data);
+ adapter_update_found_devices(adapter, &info->bdaddr, info->bdaddr_type,
+ 0, rssi, info->data, info->length);
}
static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
@@ -336,7 +318,8 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
adapter_set_state(adapter, state);
}
- adapter_update_found_devices(adapter, peer, class, rssi, data);
+ adapter_update_found_devices(adapter, peer, BDADDR_TYPE_BR, class,
+ rssi, data, EIR_DATA_LENGTH);
}
--
1.7.5.rc3
^ permalink raw reply related
* [PATCH 06/13] Don't resolve name if the name is in the storage
From: Claudio Takahasi @ 2011-04-28 22:37 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
---
src/adapter.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index dbdee8f..f2be3ba 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3163,7 +3163,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
gboolean new_dev, legacy;
name_status_t name_status;
const char *dev_name;
- int err;
+ int err, type;
memset(&eir_data, 0, sizeof(eir_data));
err = eir_parse(&eir_data, data, EIR_DATA_LENGTH);
@@ -3172,17 +3172,17 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
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))
- name_status = NAME_REQUIRED;
- else
- name_status = NAME_NOT_REQUIRED;
-
if (remote_legacy_pairing(&adapter->bdaddr, bdaddr, data, &legacy) < 0)
legacy = TRUE;
name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
+ type = adapter_get_discover_type(adapter);
+
+ if (!name && type & DISC_RESOLVNAME &&
+ adapter_has_discov_sessions(adapter))
+ name_status = NAME_REQUIRED;
+ else
+ name_status = NAME_NOT_REQUIRED;
/* Complete EIR names are always used. Shortened EIR names are only
* used if there is no name already in storage. */
--
1.7.5.rc3
^ permalink raw reply related
* [PATCH 05/13] Cleanup read name and alias from storage
From: Claudio Takahasi @ 2011-04-28 22:37 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
---
src/adapter.c | 37 ++++++++++++++++++++++++-------------
1 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index c14e6e0..dbdee8f 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3142,13 +3142,24 @@ static int remote_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
return 0;
}
+static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
+{
+ char local_addr[18], peer_addr[18], filename[PATH_MAX + 1];
+
+ ba2str(local, local_addr);
+ ba2str(peer, peer_addr);
+
+ create_name(filename, PATH_MAX, STORAGEDIR, local_addr, file);
+
+ return textfile_get(filename, peer_addr);
+}
+
void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
uint32_t class, int8_t rssi, uint8_t *data)
{
- char local_addr[18], peer_addr[18], filename[PATH_MAX + 1];
struct remote_dev_info *dev;
struct eir_data eir_data;
- char *alias, *name;
+ char *name;
gboolean new_dev, legacy;
name_status_t name_status;
const char *dev_name;
@@ -3168,18 +3179,11 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
else
name_status = NAME_NOT_REQUIRED;
- ba2str(&adapter->bdaddr, local_addr);
- ba2str(bdaddr, peer_addr);
-
- create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "aliases");
- alias = textfile_get(filename, peer_addr);
-
- create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
- name = textfile_get(filename, peer_addr);
-
if (remote_legacy_pairing(&adapter->bdaddr, bdaddr, data, &legacy) < 0)
legacy = TRUE;
+ name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
+
/* Complete EIR names are always used. Shortened EIR names are only
* used if there is no name already in storage. */
dev_name = name;
@@ -3196,18 +3200,22 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
dev = get_found_dev(adapter, bdaddr, &new_dev);
if (new_dev) {
+ char *alias;
if (dev_name)
dev->name = g_strdup(dev_name);
- if (alias)
+ alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
+ if (alias) {
dev->alias = g_strdup(alias);
+ free(alias);
+ }
dev->le = FALSE;
dev->class = class;
dev->legacy = legacy;
dev->name_status = name_status;
} else if (dev->rssi == rssi)
- return;
+ goto done;
dev->rssi = rssi;
@@ -3218,6 +3226,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
g_slist_foreach(eir_data.services, dev_prepend_uuid, dev);
adapter_emit_device_found(adapter, dev);
+
+done:
+ free(name);
}
int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr)
--
1.7.5.rc3
^ permalink raw reply related
* [PATCH 04/13] Move legacy verification to a new function
From: Claudio Takahasi @ 2011-04-28 22:37 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
---
src/adapter.c | 34 ++++++++++++++++++++++++----------
1 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 3a671e6..c14e6e0 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3119,6 +3119,29 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
adapter_emit_device_found(adapter, dev);
}
+static int remote_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
+ uint8_t *data, gboolean *legacy)
+{
+ unsigned char features[8];
+ int err;
+
+ if (data) {
+ *legacy = FALSE;
+ return 0;
+ }
+
+ err = read_remote_features(local, peer, NULL, features);
+ if (err < 0)
+ return err;
+
+ if (features[0] & 0x01)
+ *legacy = FALSE;
+ else
+ *legacy = TRUE;
+
+ return 0;
+}
+
void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
uint32_t class, int8_t rssi, uint8_t *data)
{
@@ -3128,7 +3151,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
char *alias, *name;
gboolean new_dev, legacy;
name_status_t name_status;
- unsigned char features[8];
const char *dev_name;
int err;
@@ -3155,15 +3177,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
name = textfile_get(filename, peer_addr);
- if (data)
- legacy = FALSE;
- else if (read_remote_features(&adapter->bdaddr, bdaddr, NULL,
- features) == 0) {
- if (features[0] & 0x01)
- legacy = FALSE;
- else
- legacy = TRUE;
- } else
+ if (remote_legacy_pairing(&adapter->bdaddr, bdaddr, data, &legacy) < 0)
legacy = TRUE;
/* Complete EIR names are always used. Shortened EIR names are only
--
1.7.5.rc3
^ permalink raw reply related
* [PATCH 03/13] Initial device found cleanup
From: Claudio Takahasi @ 2011-04-28 22:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
Moves EIR parsing call and stored name loading to adapter. This patch
doesn't change the implemented logic, it is only the initial step to
integrated inquiry results and LE advertises.
---
src/adapter.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++------
src/adapter.h | 4 +--
src/event.c | 59 +-----------------------------------------------
3 files changed, 64 insertions(+), 68 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index f7bbc3e..3a671e6 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -58,6 +58,7 @@
#include "storage.h"
#include "attrib-server.h"
#include "att.h"
+#include "eir.h"
/* Interleaved discovery window: 5.12 sec */
#define GAP_INTER_DISCOV_WIN 5120
@@ -3119,18 +3120,70 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
}
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)
+ uint32_t class, int8_t rssi, uint8_t *data)
{
+ char local_addr[18], peer_addr[18], filename[PATH_MAX + 1];
struct remote_dev_info *dev;
- gboolean new_dev;
+ struct eir_data eir_data;
+ char *alias, *name;
+ gboolean new_dev, legacy;
+ name_status_t name_status;
+ unsigned char features[8];
+ const char *dev_name;
+ int err;
+
+ memset(&eir_data, 0, sizeof(eir_data));
+ err = eir_parse(&eir_data, data, EIR_DATA_LENGTH);
+ if (err < 0) {
+ error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
+ 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))
+ name_status = NAME_REQUIRED;
+ else
+ name_status = NAME_NOT_REQUIRED;
+
+ ba2str(&adapter->bdaddr, local_addr);
+ ba2str(bdaddr, peer_addr);
+
+ create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "aliases");
+ alias = textfile_get(filename, peer_addr);
+
+ create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
+ name = textfile_get(filename, peer_addr);
+
+ if (data)
+ legacy = FALSE;
+ else if (read_remote_features(&adapter->bdaddr, bdaddr, NULL,
+ features) == 0) {
+ if (features[0] & 0x01)
+ legacy = FALSE;
+ else
+ legacy = TRUE;
+ } else
+ legacy = TRUE;
+
+ /* Complete EIR names are always used. Shortened EIR names are only
+ * used if there is no name already in storage. */
+ dev_name = name;
+ if (eir_data.name != NULL) {
+ if (eir_data.name_complete) {
+ write_device_name(&adapter->bdaddr, bdaddr,
+ eir_data.name);
+ name_status = NAME_NOT_REQUIRED;
+ dev_name = eir_data.name;
+ } else if (name == NULL)
+ dev_name = eir_data.name;
+ }
dev = get_found_dev(adapter, bdaddr, &new_dev);
if (new_dev) {
- if (name)
- dev->name = g_strdup(name);
+ if (dev_name)
+ dev->name = g_strdup(dev_name);
if (alias)
dev->alias = g_strdup(alias);
@@ -3147,8 +3200,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
adapter->found_devices = g_slist_sort(adapter->found_devices,
(GCompareFunc) dev_rssi_cmp);
- g_slist_foreach(services, remove_same_uuid, dev);
- g_slist_foreach(services, dev_prepend_uuid, dev);
+ g_slist_foreach(eir_data.services, remove_same_uuid, dev);
+ g_slist_foreach(eir_data.services, dev_prepend_uuid, dev);
adapter_emit_device_found(adapter, dev);
}
diff --git a/src/adapter.h b/src/adapter.h
index 7cc7c02..94707e5 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -123,9 +123,7 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
uint8_t evt_type, const char *name,
GSList *services, int 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);
+ uint32_t class, int8_t rssi, uint8_t *data);
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 b69cea7..263d428 100644
--- a/src/event.c
+++ b/src/event.c
@@ -310,18 +310,8 @@ static void update_lastused(bdaddr_t *sba, bdaddr_t *dba)
void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
int8_t rssi, uint8_t *data)
{
- char filename[PATH_MAX + 1];
struct btd_adapter *adapter;
- char local_addr[18], peer_addr[18], *alias, *name;
- name_status_t name_status;
- struct eir_data eir_data;
- int state, err;
- dbus_bool_t legacy;
- unsigned char features[8];
- const char *dev_name;
-
- ba2str(local, local_addr);
- ba2str(peer, peer_addr);
+ int state;
adapter = manager_find_adapter(local);
if (!adapter) {
@@ -346,53 +336,8 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
adapter_set_state(adapter, state);
}
- /* the inquiry result can be triggered by NON D-Bus client */
- if (adapter_get_discover_type(adapter) & DISC_RESOLVNAME &&
- adapter_has_discov_sessions(adapter))
- name_status = NAME_REQUIRED;
- else
- name_status = NAME_NOT_REQUIRED;
-
- create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "aliases");
- alias = textfile_get(filename, peer_addr);
-
- create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
- name = textfile_get(filename, peer_addr);
-
- if (data)
- legacy = FALSE;
- else if (read_remote_features(local, peer, NULL, features) == 0) {
- if (features[0] & 0x01)
- legacy = FALSE;
- else
- legacy = TRUE;
- } else
- legacy = TRUE;
-
- memset(&eir_data, 0, sizeof(eir_data));
- err = eir_parse(&eir_data, data, EIR_DATA_LENGTH);
- if (err < 0)
- error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
-
- /* Complete EIR names are always used. Shortened EIR names are only
- * used if there is no name already in storage. */
- dev_name = name;
- if (eir_data.name != NULL) {
- if (eir_data.name_complete) {
- write_device_name(local, peer, eir_data.name);
- name_status = NAME_NOT_REQUIRED;
- dev_name = eir_data.name;
- } else if (name == NULL)
- dev_name = eir_data.name;
- }
-
- adapter_update_found_devices(adapter, peer, rssi, class, dev_name,
- alias, legacy, eir_data.services,
- name_status);
+ adapter_update_found_devices(adapter, peer, class, rssi, data);
- free_eir_data(&eir_data);
- free(name);
- free(alias);
}
void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
--
1.7.5.rc3
^ permalink raw reply related
* [PATCH 02/13] Add Bluetooth address type definition
From: Claudio Takahasi @ 2011-04-28 22:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304030229-6672-1-git-send-email-claudio.takahasi@openbossa.org>
Values defined to LE(public and random) are defined in the Bluetooth
Core Specification. For basic rate, there isn't address type concept.
The constants introduced by this commit will be used to identify the
remote address type, basically to distinguish LE/BR devices before
to request the L2CAP connection.
---
lib/bluetooth.h | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 738e07a..98b8f1c 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -130,6 +130,10 @@ typedef struct {
#define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
+#define BDADDR_TYPE_LE_PUBLIC 0x00
+#define BRADDR_TYPE_LE_RANDOM 0x01
+#define BDADDR_TYPE_BR 0xff
+
/* Copy, swap, convert BD Address */
static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
{
--
1.7.5.rc3
^ permalink raw reply related
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