* [Bluez-devel] [D-BUS PATCH] Authentication
@ 2005-10-20 17:45 Claudio Takahasi
2005-10-22 13:08 ` Marcel Holtmann
0 siblings, 1 reply; 13+ messages in thread
From: Claudio Takahasi @ 2005-10-20 17:45 UTC (permalink / raw)
To: bluez-devel; +Cc: Claudio Takahasi
[-- Attachment #1.1: Type: text/plain, Size: 1542 bytes --]
Hi folks,
This is the initial patch to support authentication. There are improving
points
that I am planning send soon if everybody agree with my proposal.
The authentication function of this patch is not checking the authentication
complete event status. Clients should not use a blocking send method because
NO reply is being sent if the hci_send_req returns success.
There two possible solutions:
1. Change the security.c file to filter for authentication event and send a
SIGNAL with the bdaddr and the status
1. Change the security.c file to filter for authentication event and send a
METHOD REPLY with the bdaddr and the status. For this case will be required
keep the method_call message received in the service request.
>>>How test it:
- remove the linkkeys file :)
- use hcitool cc AA:BB:CC:DD:EE:FF to establish a connection
- send the D-BUS msg
$ dbus-send --system --dest='org.bluez' --type=method_call
/org/bluez/Manager/default/Controller
org.bluez.Manager.Authenticatestring:"AA:BB:CC:DD:EE:FF"
>>> Next action:
1. Change the reply
2. Change the pin helper to avoid blocking operation. Pipe should be
avoided. Maybe it's
possible add the file descriptor in the main loop instead of wait for data.
3. Support for re-authentication - It will be required add functions to
remove an entry from
the linkkey file.
Regards,
Claudio.
--
---------------------------------------------------------
Claudio Takahasi
Nokia's Institute of Technology - INdT
claudio.takahasi@indt.org.br
[-- Attachment #1.2: Type: text/html, Size: 1781 bytes --]
[-- Attachment #2: auth_01.patch --]
[-- Type: application/octet-stream, Size: 3855 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2005-10-19 16:48:36.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-20 14:20:21.000000000 -0200
@@ -128,6 +128,7 @@
#define HCI_ROLE_SWITCH "RoleSwitch"
#define HCI_REMOTE_NAME "RemoteName"
#define HCI_CONNECTIONS "Connections"
+#define HCI_AUTHENTICATE "Authenticate"
#define HCI_PERIODIC_INQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
@@ -172,6 +173,9 @@
DBUS_STRUCT_END_CHAR_AS_STRING\
__END_SIG__
+#define HCI_AUTHENTICATE_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+ __END_SIG__
+
/* BLUEZ_DBUS_ERROR
* EFailed error messages signature is : su
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-10-19 16:48:15.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-20 14:18:57.000000000 -0200
@@ -225,6 +225,7 @@
static DBusMessage* handle_role_switch_req(DBusMessage *msg, void *data);
static DBusMessage* handle_remote_name_req(DBusMessage *msg, void *data);
static DBusMessage* handle_display_conn_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_auth_req(DBusMessage *msg, void *data);
static const struct service_data hci_services[] = {
{ HCI_PERIODIC_INQ, handle_periodic_inq_req, HCI_PERIODIC_INQ_SIGNATURE },
@@ -233,6 +234,7 @@
{ HCI_INQ, handle_inq_req, HCI_INQ_SIGNATURE },
{ HCI_REMOTE_NAME, handle_remote_name_req, HCI_REMOTE_NAME_SIGNATURE },
{ HCI_CONNECTIONS, handle_display_conn_req, HCI_CONNECTIONS_SIGNATURE },
+ { HCI_AUTHENTICATE, handle_auth_req, HCI_AUTHENTICATE_SIGNATURE },
{ NULL, NULL, NULL }
};
@@ -1443,6 +1445,92 @@
return reply;
}
+static DBusMessage* handle_auth_req(DBusMessage *msg, void *data)
+{
+ struct hci_request rq;
+ auth_requested_cp cp;
+ evt_cmd_status rp;
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ char *str_bdaddr = NULL;
+ struct hci_dbus_data *dbus_data = data;
+ struct hci_conn_info_req *cr = NULL;
+ bdaddr_t bdaddr;
+ int dev_id = -1;
+ int sock = -1;
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &str_bdaddr);
+ str2ba(str_bdaddr, &bdaddr);
+
+ dev_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr);
+
+ if (dev_id < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_CONN_NOT_FOUND);
+ goto failed;
+ }
+
+ if (dbus_data->id != DEFAULT_DEVICE_PATH_ID && dbus_data->id != dev_id) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_CONN_NOT_FOUND);
+ goto failed;
+ }
+
+ sock = hci_open_dev(dev_id);
+ if (sock < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto failed;
+ }
+
+ cr = malloc(sizeof(*cr) + sizeof(struct hci_conn_info));
+ if (!cr) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+ goto failed;
+ }
+
+ bacpy(&cr->bdaddr, &bdaddr);
+ cr->type = ACL_LINK;
+
+ if (ioctl(sock, HCIGETCONNINFO, (unsigned long) cr) < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto failed;
+ }
+
+ memset(&cp, 0, sizeof(cp));
+ cp.handle = cr->conn_info->handle;
+
+ memset(&rq, 0, sizeof(rq));
+ rq.ogf = OGF_LINK_CTL;
+ rq.ocf = OCF_AUTH_REQUESTED;
+ rq.cparam = &cp;
+ rq.clen = AUTH_REQUESTED_CP_SIZE;
+ rq.rparam = &rp;
+ rq.rlen = EVT_CMD_STATUS_SIZE;
+ rq.event = EVT_CMD_STATUS;
+
+ if (hci_send_req(sock, &rq, 25000) < 0) {
+ syslog(LOG_ERR, "Unable to send authentication request: %s", strerror(errno));
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto failed;
+ }
+
+ if (rp.status) {
+ syslog(LOG_ERR, "Authentication command failed with status 0x%02X", rp.status);
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + EIO);
+ goto failed;
+ }
+
+failed:
+
+ if (sock > 0)
+ close (sock);
+
+ if (cr)
+ free (cr);
+
+ return reply;
+
+}
+
/*****************************************************************
*
* Section reserved to Manager D-Bus message handlers
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-20 17:45 [Bluez-devel] [D-BUS PATCH] Authentication Claudio Takahasi
@ 2005-10-22 13:08 ` Marcel Holtmann
2005-10-24 13:06 ` Claudio Takahasi
0 siblings, 1 reply; 13+ messages in thread
From: Marcel Holtmann @ 2005-10-22 13:08 UTC (permalink / raw)
To: bluez-devel; +Cc: Claudio Takahasi
Hi Claudio,
> This is the initial patch to support authentication. There are
> improving points
> that I am planning send soon if everybody agree with my proposal.
I applied the patch, but please do the coding style right. It seems that
you still copy some parts for your old patches.
if (sock > 0)
close (sock);
I first prefer to use "sk" instead of "sock", but this hasn't been used
in full consistency and so I didn't corrected it. However you need to
check for (sock >= 0) in case of a socket or file descriptor and we
don't put a space between the function name and its parameters. So it
must be called "close(sock);" in any case.
It is also better to introduce more error labels than using another if
statement to check for state of a file descriptor. We now if the file
descriptor is valid or not.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-22 13:08 ` Marcel Holtmann
@ 2005-10-24 13:06 ` Claudio Takahasi
2005-10-24 13:19 ` Marcel Holtmann
0 siblings, 1 reply; 13+ messages in thread
From: Claudio Takahasi @ 2005-10-24 13:06 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 2510 bytes --]
Hi Marcel,
I will send a cleanup patch before send the authentication improvements
patch.
Regarding the variable name, It should be better change to "dd" instead of
sock or sk. If you see the hcitool code standard you will notice that.
I noticed that there is a HCI raw socket created in the main.c file that
belongs to hcid structure.
Can I use it in the functions handle_display_conn_req and
handle_get_devices_req instead of create
a new one?
I will try apply you other suggestions.
Another point is the reply method for authentication. We need discuss how we
should design it.
I am not a hcid expert therefore I would like ask you how we should
implement the authentication stuff.
Currently, the METHOD REPLY of the authentication doesn't consider the
authentication complete event.
In order to check it and reply after the authentication finishes it is
required store some D-Bus message
attributes(sender, serial, destination, ...). Another approach is send a
SIGNAL. Which approach do you prefer
send send a peer message(method reply) or a signal?
Regarding the pin helper. Are you planning support the "normal" helper and
the dbus helper? I am asking
this because the call_pin_helper function is blocking. If you are planning
support both, we have to try add
the pin helper file descriptor inside the hcid main loop.
Regards,
Claudio.
On 10/22/05, Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Claudio,
>
> > This is the initial patch to support authentication. There are
> > improving points
> > that I am planning send soon if everybody agree with my proposal.
>
> I applied the patch, but please do the coding style right. It seems that
> you still copy some parts for your old patches.
>
> if (sock > 0)
> close (sock);
>
> I first prefer to use "sk" instead of "sock", but this hasn't been used
> in full consistency and so I didn't corrected it. However you need to
> check for (sock >= 0) in case of a socket or file descriptor and we
> don't put a space between the function name and its parameters. So it
> must be called "close(sock);" in any case.
>
> It is also better to introduce more error labels than using another if
> statement to check for state of a file descriptor. We now if the file
> descriptor is valid or not.
>
> Regards
>
> Marcel
>
>
>
--
---------------------------------------------------------
Claudio Takahasi
Nokia's Institute of Technology - INdT
claudio.takahasi@indt.org.br
[-- Attachment #2: Type: text/html, Size: 3185 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-24 13:06 ` Claudio Takahasi
@ 2005-10-24 13:19 ` Marcel Holtmann
2005-10-25 19:03 ` Claudio Takahasi
0 siblings, 1 reply; 13+ messages in thread
From: Marcel Holtmann @ 2005-10-24 13:19 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
> I will send a cleanup patch before send the authentication
> improvements patch.
> Regarding the variable name, It should be better change to "dd"
> instead of
> sock or sk. If you see the hcitool code standard you will notice
> that.
I am fine with dd. My point was to be consistent.
> I noticed that there is a HCI raw socket created in the main.c file
> that belongs to hcid structure.
> Can I use it in the functions handle_display_conn_req and
> handle_get_devices_req instead of create
> a new one?
Open a new one, because the HCI filter is per descriptor and you don't
wanna mess with the filter of the HCI socket in main.c.
> I will try apply you other suggestions.
Cool.
> Another point is the reply method for authentication. We need discuss
> how we should design it.
> I am not a hcid expert therefore I would like ask you how we should
> implement the authentication stuff.
>
> Currently, the METHOD REPLY of the authentication doesn't consider the
> authentication complete event.
> In order to check it and reply after the authentication finishes it is
> required store some D-Bus message
> attributes(sender, serial, destination, ...). Another approach is send
> a SIGNAL. Which approach do you prefer
> send send a peer message(method reply) or a signal?
In generell everything authentication or encryption related should be
done inside the kernel. However the infrastructure is not there yet and
so keep it as simple as possible.
> Regarding the pin helper. Are you planning support the "normal" helper
> and the dbus helper? I am asking
> this because the call_pin_helper function is blocking. If you are
> planning support both, we have to try add
> the pin helper file descriptor inside the hcid main loop.
My plan is to require D-Bus for bluez-utils, but so far I haven't
received any comments on it. The main problem is that the distributions
must move to a decent version of D-Bus and Debian unstable is still on
D-Bus 0.23. Actually any D-Bus 0.3x will not work very good and so we
might need to support the "normal" PIN helper for some time. I am open
for changes, because the PIN helper code in generell is not that good.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-24 13:19 ` Marcel Holtmann
@ 2005-10-25 19:03 ` Claudio Takahasi
2005-10-27 0:37 ` Marcel Holtmann
0 siblings, 1 reply; 13+ messages in thread
From: Claudio Takahasi @ 2005-10-25 19:03 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 3311 bytes --]
Hi,
Here are the patches to send the authentication result, please DON'T
commit it. Probably
it will conflict with the latest Eduardo's patch.
Which approach do you preffer?
1. Send a signal
2. Send a method return (peer message)
Regards,
Claudio.
On 10/24/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Claudio,
>
> > I will send a cleanup patch before send the authentication
> > improvements patch.
> > Regarding the variable name, It should be better change to "dd"
> > instead of
> > sock or sk. If you see the hcitool code standard you will notice
> > that.
>
> I am fine with dd. My point was to be consistent.
>
> > I noticed that there is a HCI raw socket created in the main.c file
> > that belongs to hcid structure.
> > Can I use it in the functions handle_display_conn_req and
> > handle_get_devices_req instead of create
> > a new one?
>
> Open a new one, because the HCI filter is per descriptor and you don't
> wanna mess with the filter of the HCI socket in main.c.
>
> > I will try apply you other suggestions.
>
> Cool.
>
> > Another point is the reply method for authentication. We need discuss
> > how we should design it.
> > I am not a hcid expert therefore I would like ask you how we should
> > implement the authentication stuff.
> >
> > Currently, the METHOD REPLY of the authentication doesn't consider the
> > authentication complete event.
> > In order to check it and reply after the authentication finishes it is
> > required store some D-Bus message
> > attributes(sender, serial, destination, ...). Another approach is send
> > a SIGNAL. Which approach do you prefer
> > send send a peer message(method reply) or a signal?
>
> In generell everything authentication or encryption related should be
> done inside the kernel. However the infrastructure is not there yet and
> so keep it as simple as possible.
>
> > Regarding the pin helper. Are you planning support the "normal" helper
> > and the dbus helper? I am asking
> > this because the call_pin_helper function is blocking. If you are
> > planning support both, we have to try add
> > the pin helper file descriptor inside the hcid main loop.
>
> My plan is to require D-Bus for bluez-utils, but so far I haven't
> received any comments on it. The main problem is that the distributions
> must move to a decent version of D-Bus and Debian unstable is still on
> D-Bus 0.23. Actually any D-Bus 0.3x will not work very good and so we
> might need to support the "normal" PIN helper for some time. I am open
> for changes, because the PIN helper code in generell is not that good.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through End of 2005
> Visit http://www.jboss.com/services/certification for more information
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
[-- Attachment #2: auth_complete_method_ret_01.patch --]
[-- Type: application/octet-stream, Size: 5083 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2005-10-23 19:27:41.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-25 15:43:40.000000000 -0200
@@ -30,8 +30,9 @@
#define __END_SIG__ DBUS_TYPE_INVALID_AS_STRING
+#define BLUEZ_BUS_NAME "org.bluez"
#define BASE_PATH "/org/bluez"
-#define BASE_INTERFACE "org.bluez"
+#define BASE_INTERFACE BLUEZ_BUS_NAME
#define DEVICE_PATH BASE_PATH "/Device"
#define DEVICE_INTERFACE BASE_INTERFACE ".Device"
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-10-23 19:27:41.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-25 15:54:24.000000000 -0200
@@ -60,6 +60,7 @@
#define MAX_PATH_LENGTH (64)
#define READ_REMOTE_NAME_TIMEOUT (25000)
#define MAX_CONN_NUMBER (10)
+#define MAX_SENDER_LEN (16)
#define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
#define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
@@ -80,7 +81,9 @@
};
struct hci_dbus_data {
- uint16_t id;
+ uint16_t id;
+ char sender[MAX_SENDER_LEN];
+ dbus_uint32_t serial;
};
typedef int register_function_t(DBusConnection *conn, int dft_reg, uint16_t id);
@@ -635,6 +638,82 @@
{
}
+void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status, const uint16_t handle)
+{
+ char *local_addr, *peer_addr;
+ DBusMessage *message = NULL;
+ struct hci_dbus_data *dbus_data = NULL;
+ bdaddr_t tmp;
+ char path[MAX_PATH_LENGTH];
+ int id;
+
+ baswap(&tmp, local); local_addr = batostr(&tmp);
+ baswap(&tmp, peer); peer_addr = batostr(&tmp);
+
+ id = hci_devid(local_addr);
+ if (id < 0) {
+ syslog(LOG_ERR, "No matching device id for %s", local_addr);
+ goto failed;
+ }
+
+ snprintf(path, sizeof(path), "%s/hci%d/%s", MANAGER_PATH, id, BLUEZ_HCI);
+
+ if (!dbus_connection_get_object_path_data(connection, path, (void*)&dbus_data))
+ goto failed;
+
+ /* check if the auth request was triggered by a D-Bus client */
+ if (!dbus_data || dbus_data->serial == 0)
+ goto failed;
+
+ if (!status) {
+
+ message = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
+ if (message == NULL)
+ goto failed;
+
+ dbus_message_append_args(message,
+ DBUS_TYPE_STRING, &peer_addr,
+ DBUS_TYPE_UINT16, &handle,
+ DBUS_TYPE_INVALID);
+
+ } else {
+ const char *error_msg = bluez_dbus_error_to_str(status);
+
+ message = dbus_message_new(DBUS_MESSAGE_TYPE_ERROR);
+ if (message == NULL)
+ goto failed;
+
+ dbus_message_set_error_name(message, ERROR_INTERFACE);
+ dbus_message_append_args(message,
+ DBUS_TYPE_STRING, &error_msg,
+ DBUS_TYPE_INVALID);
+ }
+
+ if (!dbus_message_set_destination(message, dbus_data->sender))
+ goto failed;
+
+ dbus_message_set_no_reply (message, TRUE);
+ if (!dbus_message_set_reply_serial (message, dbus_data->serial))
+ goto failed;
+
+ /* Clean the auth dbus_data */
+ memset(dbus_data->sender, 0, MAX_SENDER_LEN);
+ dbus_data->serial = 0;
+
+
+ if (dbus_connection_send(connection, message, NULL) == FALSE)
+ goto failed;
+
+ dbus_connection_flush(connection);
+
+failed:
+ if (message)
+ dbus_message_unref(message);
+
+ bt_free(local_addr);
+ bt_free(peer_addr);
+}
+
gboolean watch_func(GIOChannel *chan, GIOCondition cond, gpointer data)
{
DBusWatch *watch = (DBusWatch *) data;
@@ -1681,10 +1760,18 @@
rq.rlen = EVT_CMD_STATUS_SIZE;
rq.event = EVT_CMD_STATUS;
- if (hci_send_req(sock, &rq, 25000) < 0) {
+ if (hci_send_req(sock, &rq, 100) < 0) {
syslog(LOG_ERR, "Unable to send authentication request: %s", strerror(errno));
reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
goto failed;
+ } else {
+ const char *sender = dbus_message_get_sender(msg);
+
+ /* get the serial and the sender info to reply later */
+ if (sender) {
+ snprintf(dbus_data->sender, MAX_SENDER_LEN, "%s", sender);
+ dbus_data->serial = dbus_message_get_serial(msg);
+ }
}
failed:
--- bluez-utils-cvs.orig/hcid/security.c 2005-10-24 09:03:37.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/security.c 2005-10-24 13:33:00.000000000 -0200
@@ -644,6 +644,18 @@
hcid_dbus_disconn_complete(sba, &dba, evt->reason);
}
+static inline void auth_complete(int dev, bdaddr_t *sba, void *ptr)
+{
+ evt_auth_complete *evt = ptr;
+ bdaddr_t dba;
+
+ if (get_bdaddr(dev, sba, evt->handle, &dba) < 0)
+ return;
+
+ hcid_dbus_auth_complete(sba, &dba, evt->status, evt->handle);
+}
+
+
static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data)
{
unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr = buf;
@@ -726,6 +738,9 @@
case EVT_DISCONN_COMPLETE:
disconn_complete(dev, &di->bdaddr, ptr);
break;
+ case EVT_AUTH_COMPLETE:
+ auth_complete(dev, &di->bdaddr, ptr);
+ break;
}
if (hci_test_bit(HCI_SECMGR, &di->flags))
@@ -789,6 +804,7 @@
hci_filter_set_event(EVT_EXTENDED_INQUIRY_RESULT, &flt);
hci_filter_set_event(EVT_CONN_COMPLETE, &flt);
hci_filter_set_event(EVT_DISCONN_COMPLETE, &flt);
+ hci_filter_set_event(EVT_AUTH_COMPLETE, &flt);
if (setsockopt(dev, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
syslog(LOG_ERR, "Can't set filter on hci%d: %s (%d)",
hdev, strerror(errno), errno);
[-- Attachment #3: auth_complete_signal_01.patch --]
[-- Type: application/octet-stream, Size: 3211 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2005-10-23 19:27:41.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-24 14:06:43.000000000 -0200
@@ -96,6 +96,7 @@
#define BLUEZ_HCI_INQ_RESULT "InquiryResult"
#define BLUEZ_HCI_REMOTE_NAME "RemoteName"
#define BLUEZ_HCI_REMOTE_NAME_FAILED "RemoteNameFailed"
+#define BLUEZ_HCI_AUTH_COMPLETE "AuthenticationComplete"
//HCI signals sent in the BLUEZ_HCI_PATH
#define BLUEZ_HCI_DEV_ADDED "DeviceAdded"
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-10-23 19:27:41.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-24 14:02:13.000000000 -0200
@@ -635,6 +635,54 @@
{
}
+void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status, const uint16_t handle)
+{
+ DBusMessage *message = NULL;
+ char *local_addr, *peer_addr;
+ bdaddr_t tmp;
+ char path[MAX_PATH_LENGTH];
+ int id;
+
+ baswap(&tmp, local); local_addr = batostr(&tmp);
+ baswap(&tmp, peer); peer_addr = batostr(&tmp);
+
+ id = hci_devid(local_addr);
+ if (id < 0) {
+ syslog(LOG_ERR, "No matching device id for %s", local_addr);
+ goto failed;
+ }
+
+ snprintf(path, sizeof(path), "%s/hci%d/%s", MANAGER_PATH, id, BLUEZ_HCI);
+
+ message = dbus_message_new_signal(path,
+ BLUEZ_HCI_INTERFACE, BLUEZ_HCI_AUTH_COMPLETE);
+ if (message == NULL) {
+ syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
+ goto failed;
+ }
+
+ dbus_message_append_args(message,
+ DBUS_TYPE_STRING, &peer_addr,
+ DBUS_TYPE_BYTE, &status,
+ DBUS_TYPE_UINT16, &handle,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_connection_send(connection, message, NULL) == FALSE) {
+ syslog(LOG_ERR, "Can't send D-BUS remote name message");
+ goto failed;
+ }
+
+ dbus_connection_flush(connection);
+
+failed:
+ if (message)
+ dbus_message_unref(message);
+
+ bt_free(local_addr);
+ bt_free(peer_addr);
+
+}
+
gboolean watch_func(GIOChannel *chan, GIOCondition cond, gpointer data)
{
DBusWatch *watch = (DBusWatch *) data;
--- bluez-utils-cvs.orig/hcid/security.c 2005-10-24 09:03:37.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/security.c 2005-10-24 13:33:00.000000000 -0200
@@ -644,6 +644,18 @@
hcid_dbus_disconn_complete(sba, &dba, evt->reason);
}
+static inline void auth_complete(int dev, bdaddr_t *sba, void *ptr)
+{
+ evt_auth_complete *evt = ptr;
+ bdaddr_t dba;
+
+ if (get_bdaddr(dev, sba, evt->handle, &dba) < 0)
+ return;
+
+ hcid_dbus_auth_complete(sba, &dba, evt->status, evt->handle);
+}
+
+
static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data)
{
unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr = buf;
@@ -726,6 +738,9 @@
case EVT_DISCONN_COMPLETE:
disconn_complete(dev, &di->bdaddr, ptr);
break;
+ case EVT_AUTH_COMPLETE:
+ auth_complete(dev, &di->bdaddr, ptr);
+ break;
}
if (hci_test_bit(HCI_SECMGR, &di->flags))
@@ -789,6 +804,7 @@
hci_filter_set_event(EVT_EXTENDED_INQUIRY_RESULT, &flt);
hci_filter_set_event(EVT_CONN_COMPLETE, &flt);
hci_filter_set_event(EVT_DISCONN_COMPLETE, &flt);
+ hci_filter_set_event(EVT_AUTH_COMPLETE, &flt);
if (setsockopt(dev, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
syslog(LOG_ERR, "Can't set filter on hci%d: %s (%d)",
hdev, strerror(errno), errno);
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-25 19:03 ` Claudio Takahasi
@ 2005-10-27 0:37 ` Marcel Holtmann
2005-10-27 14:33 ` Claudio Takahasi
0 siblings, 1 reply; 13+ messages in thread
From: Marcel Holtmann @ 2005-10-27 0:37 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
> Here are the patches to send the authentication result, please DON'T
> commit it. Probably
> it will conflict with the latest Eduardo's patch.
>
> Which approach do you preffer?
> 1. Send a signal
> 2. Send a method return (peer message)
I think that a signal to inform the applications that a connection is
now authenticated (and also encrypted) is a good idea.
Eduardos patches are now in the CVS. So you can re-create yours.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-27 0:37 ` Marcel Holtmann
@ 2005-10-27 14:33 ` Claudio Takahasi
2005-10-27 14:39 ` Claudio Takahasi
2005-10-27 14:53 ` Marcel Holtmann
0 siblings, 2 replies; 13+ messages in thread
From: Claudio Takahasi @ 2005-10-27 14:33 UTC (permalink / raw)
To: bluez-devel
Hi Marcel,
Here are the patches based on the lastest BlueZ CVS. I am sending both
approaches.
Using signals is more clear in hcid side, however the clients will
have to add flags to indicate that there is a authentication pending.
Another problem is the error, using signals will not be possible send
D-Bus error messages, therefore client will have to translate the
status to a success or errors result.
I understand that store atributes to create a reply later is not a
clean solution but I don't see another solution. Using a peer message
it's possible reply errors properly and it easier develop the python/c
clients
I think it's better ask py-dbus developers about this. I prefer the
peer message reply approach.
Regards,
Claudio
PS: This is the message content for both approachs:
* Signal approach
>>> D-Bus AuthenticationComplete signal
- String: peer bt address
- Byte: status
- Uint16: handle
* For method return approach
>>> D-Bus method return msg
- String: peer bt address
- Byte: handle
>>> D-Bus error msg
- String: error description
- uint32: error code
On 10/26/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Claudio,
>
> > Here are the patches to send the authentication result, please DON'T
> > commit it. Probably
> > it will conflict with the latest Eduardo's patch.
> >
> > Which approach do you preffer?
> > 1. Send a signal
> > 2. Send a method return (peer message)
>
> I think that a signal to inform the applications that a connection is
> now authenticated (and also encrypted) is a good idea.
>
> Eduardos patches are now in the CVS. So you can re-create yours.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through End of 2005
> Visit http://www.jboss.com/services/certification for more information
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-27 14:33 ` Claudio Takahasi
@ 2005-10-27 14:39 ` Claudio Takahasi
2005-10-27 14:53 ` Marcel Holtmann
1 sibling, 0 replies; 13+ messages in thread
From: Claudio Takahasi @ 2005-10-27 14:39 UTC (permalink / raw)
To: bluez-devel; +Cc: Claudio Takahasi
[-- Attachment #1: Type: text/plain, Size: 2714 bytes --]
sorry... The attachment was missing :)
On 10/27/05, Claudio Takahasi <cktakahasi@gmail.com> wrote:
> Hi Marcel,
>
> Here are the patches based on the lastest BlueZ CVS. I am sending both
> approaches.
> Using signals is more clear in hcid side, however the clients will
> have to add flags to indicate that there is a authentication pending.
> Another problem is the error, using signals will not be possible send
> D-Bus error messages, therefore client will have to translate the
> status to a success or errors result.
>
> I understand that store atributes to create a reply later is not a
> clean solution but I don't see another solution. Using a peer message
> it's possible reply errors properly and it easier develop the python/c
> clients
>
> I think it's better ask py-dbus developers about this. I prefer the
> peer message reply approach.
>
> Regards,
> Claudio
>
> PS: This is the message content for both approachs:
> * Signal approach
> >>> D-Bus AuthenticationComplete signal
> - String: peer bt address
> - Byte: status
> - Uint16: handle
>
> * For method return approach
> >>> D-Bus method return msg
> - String: peer bt address
> - Byte: handle
> >>> D-Bus error msg
> - String: error description
> - uint32: error code
>
> On 10/26/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> > Hi Claudio,
> >
> > > Here are the patches to send the authentication result, please DON'T
> > > commit it. Probably
> > > it will conflict with the latest Eduardo's patch.
> > >
> > > Which approach do you preffer?
> > > 1. Send a signal
> > > 2. Send a method return (peer message)
> >
> > I think that a signal to inform the applications that a connection is
> > now authenticated (and also encrypted) is a good idea.
> >
> > Eduardos patches are now in the CVS. So you can re-create yours.
> >
> > Regards
> >
> > Marcel
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by the JBoss Inc.
> > Get Certified Today * Register for a JBoss Training Course
> > Free Certification Exam for All Training Attendees Through End of 2005
> > Visit http://www.jboss.com/services/certification for more information
> > _______________________________________________
> > Bluez-devel mailing list
> > Bluez-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/bluez-devel
> >
>
>
> --
> ---------------------------------------------------------
> Claudio Takahasi
> Instituto Nokia de Tecnologia - INdT
>
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
[-- Attachment #2: auth_complete_method_ret_03.patch --]
[-- Type: application/octet-stream, Size: 5510 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2005-10-23 19:27:41.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-27 09:42:46.000000000 -0200
@@ -30,8 +30,9 @@
#define __END_SIG__ DBUS_TYPE_INVALID_AS_STRING
+#define BLUEZ_BUS_NAME "org.bluez"
#define BASE_PATH "/org/bluez"
-#define BASE_INTERFACE "org.bluez"
+#define BASE_INTERFACE BLUEZ_BUS_NAME
#define DEVICE_PATH BASE_PATH "/Device"
#define DEVICE_INTERFACE BASE_INTERFACE ".Device"
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-10-26 22:33:33.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-27 10:27:14.000000000 -0200
@@ -60,6 +60,7 @@
#define MAX_PATH_LENGTH (64)
#define READ_REMOTE_NAME_TIMEOUT (25000)
#define MAX_CONN_NUMBER (10)
+#define MAX_SENDER_LEN (16)
#define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
#define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
@@ -80,7 +81,12 @@
};
struct hci_dbus_data {
- uint16_t id;
+ /* adapter identification */
+ uint16_t id;
+ /* authentication data used to create the method return */
+ uint16_t handle;
+ char sender[MAX_SENDER_LEN];
+ dbus_uint32_t serial;
};
typedef int register_function_t(DBusConnection *conn, int dft_reg, uint16_t id);
@@ -668,6 +674,84 @@
{
}
+void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status, const uint16_t handle)
+{
+ char *local_addr, *peer_addr;
+ DBusMessage *message = NULL;
+ struct hci_dbus_data *dbus_data = NULL;
+ bdaddr_t tmp;
+ char path[MAX_PATH_LENGTH];
+ int id;
+
+ baswap(&tmp, local); local_addr = batostr(&tmp);
+ baswap(&tmp, peer); peer_addr = batostr(&tmp);
+
+ id = hci_devid(local_addr);
+ if (id < 0) {
+ syslog(LOG_ERR, "No matching device id for %s", local_addr);
+ goto failed;
+ }
+
+ snprintf(path, sizeof(path), "%s/hci%d/%s", MANAGER_PATH, id, BLUEZ_HCI);
+
+ if (!dbus_connection_get_object_path_data(connection, path, (void*)&dbus_data))
+ goto failed;
+
+ /* check if the auth request was triggered by a D-Bus client */
+ if (!dbus_data || dbus_data->serial == 0 || dbus_data->handle != handle)
+ goto failed;
+
+ if (!status) {
+ message = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
+ if (message == NULL)
+ goto failed;
+
+ dbus_message_append_args(message,
+ DBUS_TYPE_STRING, &peer_addr,
+ DBUS_TYPE_UINT16, &handle,
+ DBUS_TYPE_INVALID);
+
+ } else {
+ const uint32_t ecode = status;
+ const char *error_msg = bluez_dbus_error_to_str(ecode);
+
+ message = dbus_message_new(DBUS_MESSAGE_TYPE_ERROR);
+ if (message == NULL)
+ goto failed;
+
+ dbus_message_set_error_name(message, ERROR_INTERFACE);
+ dbus_message_append_args(message,
+ DBUS_TYPE_STRING, &error_msg,
+ DBUS_TYPE_UINT32, &ecode,
+ DBUS_TYPE_INVALID);
+ }
+
+ if (!dbus_message_set_destination(message, dbus_data->sender))
+ goto failed;
+
+ dbus_message_set_no_reply (message, TRUE);
+ if (!dbus_message_set_reply_serial (message, dbus_data->serial))
+ goto failed;
+
+ /* Clean the auth dbus_data */
+ memset(dbus_data->sender, 0, MAX_SENDER_LEN);
+ dbus_data->serial = 0;
+ dbus_data->handle = 0;
+
+
+ if (dbus_connection_send(connection, message, NULL) == FALSE)
+ goto failed;
+
+ dbus_connection_flush(connection);
+
+failed:
+ if (message)
+ dbus_message_unref(message);
+
+ bt_free(local_addr);
+ bt_free(peer_addr);
+}
+
gboolean watch_func(GIOChannel *chan, GIOCondition cond, gpointer data)
{
DBusWatch *watch = (DBusWatch *) data;
@@ -1697,12 +1781,25 @@
rq.rlen = EVT_CMD_STATUS_SIZE;
rq.event = EVT_CMD_STATUS;
- if (hci_send_req(dd, &rq, 25000) < 0) {
+ if (hci_send_req(dd, &rq, 100) < 0) {
syslog(LOG_ERR, "Unable to send authentication request: %s", strerror(errno));
reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
goto failed;
- }
+ } else {
+ const char *sender = dbus_message_get_sender(msg);
+ /* get the serial and the sender info to reply later */
+ if (sender) {
+ snprintf(dbus_data->sender, MAX_SENDER_LEN, "%s", sender);
+ dbus_data->serial = dbus_message_get_serial(msg);
+ dbus_data->handle = cr->conn_info->handle;
+ } else {
+ memset(dbus_data->sender, 0, MAX_SENDER_LEN);
+ dbus_data->serial = 0;
+ dbus_data->handle = 0;
+ }
+ }
+
failed:
if (dd >= 0)
close(dd);
--- bluez-utils-cvs.orig/hcid/security.c 2005-10-24 09:03:37.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/security.c 2005-10-27 09:42:46.000000000 -0200
@@ -644,6 +644,18 @@
hcid_dbus_disconn_complete(sba, &dba, evt->reason);
}
+static inline void auth_complete(int dev, bdaddr_t *sba, void *ptr)
+{
+ evt_auth_complete *evt = ptr;
+ bdaddr_t dba;
+
+ if (get_bdaddr(dev, sba, evt->handle, &dba) < 0)
+ return;
+
+ hcid_dbus_auth_complete(sba, &dba, evt->status, evt->handle);
+}
+
+
static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data)
{
unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr = buf;
@@ -726,6 +738,9 @@
case EVT_DISCONN_COMPLETE:
disconn_complete(dev, &di->bdaddr, ptr);
break;
+ case EVT_AUTH_COMPLETE:
+ auth_complete(dev, &di->bdaddr, ptr);
+ break;
}
if (hci_test_bit(HCI_SECMGR, &di->flags))
@@ -789,6 +804,7 @@
hci_filter_set_event(EVT_EXTENDED_INQUIRY_RESULT, &flt);
hci_filter_set_event(EVT_CONN_COMPLETE, &flt);
hci_filter_set_event(EVT_DISCONN_COMPLETE, &flt);
+ hci_filter_set_event(EVT_AUTH_COMPLETE, &flt);
if (setsockopt(dev, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
syslog(LOG_ERR, "Can't set filter on hci%d: %s (%d)",
hdev, strerror(errno), errno);
[-- Attachment #3: auth_complete_signal_02.patch --]
[-- Type: application/octet-stream, Size: 3213 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2005-10-23 19:27:41.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-27 10:39:59.000000000 -0200
@@ -96,6 +96,7 @@
#define BLUEZ_HCI_INQ_RESULT "InquiryResult"
#define BLUEZ_HCI_REMOTE_NAME "RemoteName"
#define BLUEZ_HCI_REMOTE_NAME_FAILED "RemoteNameFailed"
+#define BLUEZ_HCI_AUTH_COMPLETE "AuthenticationComplete"
//HCI signals sent in the BLUEZ_HCI_PATH
#define BLUEZ_HCI_DEV_ADDED "DeviceAdded"
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-10-26 22:33:33.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-27 10:42:14.000000000 -0200
@@ -668,6 +668,52 @@
{
}
+void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status, const uint16_t handle)
+{
+ DBusMessage *message = NULL;
+ char *local_addr, *peer_addr;
+ bdaddr_t tmp;
+ char path[MAX_PATH_LENGTH];
+ int id;
+
+ baswap(&tmp, local); local_addr = batostr(&tmp);
+ baswap(&tmp, peer); peer_addr = batostr(&tmp);
+
+ id = hci_devid(local_addr);
+ if (id < 0) {
+ syslog(LOG_ERR, "No matching device id for %s", local_addr);
+ goto failed;
+ }
+
+ snprintf(path, sizeof(path), "%s/hci%d/%s", MANAGER_PATH, id, BLUEZ_HCI);
+
+ message = dbus_message_new_signal(path, BLUEZ_HCI_INTERFACE, BLUEZ_HCI_AUTH_COMPLETE);
+ if (message == NULL) {
+ syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
+ goto failed;
+ }
+
+ dbus_message_append_args(message,
+ DBUS_TYPE_STRING, &peer_addr,
+ DBUS_TYPE_BYTE, &status,
+ DBUS_TYPE_UINT16, &handle,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_connection_send(connection, message, NULL) == FALSE) {
+ syslog(LOG_ERR, "Can't send D-BUS remote name message");
+ goto failed;
+ }
+
+ dbus_connection_flush(connection);
+
+failed:
+ if (message)
+ dbus_message_unref(message);
+
+ bt_free(local_addr);
+ bt_free(peer_addr);
+}
+
gboolean watch_func(GIOChannel *chan, GIOCondition cond, gpointer data)
{
DBusWatch *watch = (DBusWatch *) data;
--- bluez-utils-cvs.orig/hcid/security.c 2005-10-24 09:03:37.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/security.c 2005-10-27 10:32:40.000000000 -0200
@@ -644,6 +644,18 @@
hcid_dbus_disconn_complete(sba, &dba, evt->reason);
}
+static inline void auth_complete(int dev, bdaddr_t *sba, void *ptr)
+{
+ evt_auth_complete *evt = ptr;
+ bdaddr_t dba;
+
+ if (get_bdaddr(dev, sba, evt->handle, &dba) < 0)
+ return;
+
+ hcid_dbus_auth_complete(sba, &dba, evt->status, evt->handle);
+}
+
+
static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data)
{
unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr = buf;
@@ -726,6 +738,9 @@
case EVT_DISCONN_COMPLETE:
disconn_complete(dev, &di->bdaddr, ptr);
break;
+ case EVT_AUTH_COMPLETE:
+ auth_complete(dev, &di->bdaddr, ptr);
+ break;
}
if (hci_test_bit(HCI_SECMGR, &di->flags))
@@ -789,6 +804,7 @@
hci_filter_set_event(EVT_EXTENDED_INQUIRY_RESULT, &flt);
hci_filter_set_event(EVT_CONN_COMPLETE, &flt);
hci_filter_set_event(EVT_DISCONN_COMPLETE, &flt);
+ hci_filter_set_event(EVT_AUTH_COMPLETE, &flt);
if (setsockopt(dev, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
syslog(LOG_ERR, "Can't set filter on hci%d: %s (%d)",
hdev, strerror(errno), errno);
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-27 14:33 ` Claudio Takahasi
2005-10-27 14:39 ` Claudio Takahasi
@ 2005-10-27 14:53 ` Marcel Holtmann
2005-10-27 16:33 ` Claudio Takahasi
1 sibling, 1 reply; 13+ messages in thread
From: Marcel Holtmann @ 2005-10-27 14:53 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
> Here are the patches based on the lastest BlueZ CVS. I am sending both
> approaches.
> Using signals is more clear in hcid side, however the clients will
> have to add flags to indicate that there is a authentication pending.
> Another problem is the error, using signals will not be possible send
> D-Bus error messages, therefore client will have to translate the
> status to a success or errors result.
we need the signal anyway, because a second application might be request
the authentication and if your first application displays different
icons for authenticated or unauthenticated connection then it should be
told that this connection is now authenticated. The same applies for the
encryption.
> PS: This is the message content for both approachs:
> * Signal approach
> >>> D-Bus AuthenticationComplete signal
> - String: peer bt address
> - Byte: status
> - Uint16: handle
We don't need the handle and the address. Use the address only, because
connection handles should be only used in hcid and the kernel.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-27 14:53 ` Marcel Holtmann
@ 2005-10-27 16:33 ` Claudio Takahasi
2005-10-27 17:11 ` Marcel Holtmann
0 siblings, 1 reply; 13+ messages in thread
From: Claudio Takahasi @ 2005-10-27 16:33 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 1960 bytes --]
done!
The signal has two arguments now:
- String: peer address
- Byte: authentication status
Regards,
Claudio.
On 10/27/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Claudio,
>
> > Here are the patches based on the lastest BlueZ CVS. I am sending both
> > approaches.
> > Using signals is more clear in hcid side, however the clients will
> > have to add flags to indicate that there is a authentication pending.
> > Another problem is the error, using signals will not be possible send
> > D-Bus error messages, therefore client will have to translate the
> > status to a success or errors result.
>
> we need the signal anyway, because a second application might be request
> the authentication and if your first application displays different
> icons for authenticated or unauthenticated connection then it should be
> told that this connection is now authenticated. The same applies for the
> encryption.
>
> > PS: This is the message content for both approachs:
> > * Signal approach
> > >>> D-Bus AuthenticationComplete signal
> > - String: peer bt address
> > - Byte: status
> > - Uint16: handle
>
> We don't need the handle and the address. Use the address only, because
> connection handles should be only used in hcid and the kernel.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through End of 2005
> Visit http://www.jboss.com/services/certification for more information
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
[-- Attachment #2: auth_complete_signal_03.patch --]
[-- Type: application/octet-stream, Size: 4582 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2005-10-23 19:27:41.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-27 10:39:59.000000000 -0200
@@ -96,6 +96,7 @@
#define BLUEZ_HCI_INQ_RESULT "InquiryResult"
#define BLUEZ_HCI_REMOTE_NAME "RemoteName"
#define BLUEZ_HCI_REMOTE_NAME_FAILED "RemoteNameFailed"
+#define BLUEZ_HCI_AUTH_COMPLETE "AuthenticationComplete"
//HCI signals sent in the BLUEZ_HCI_PATH
#define BLUEZ_HCI_DEV_ADDED "DeviceAdded"
--- bluez-utils-cvs.orig/hcid/hcid.h 2005-10-26 22:28:36.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/hcid.h 2005-10-27 13:25:12.000000000 -0200
@@ -137,6 +137,7 @@
void hcid_dbus_remote_name_failed(bdaddr_t *local, bdaddr_t *peer, uint8_t status);
void hcid_dbus_conn_complete(bdaddr_t *local, bdaddr_t *peer);
void hcid_dbus_disconn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t reason);
+void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status);
#else
static inline void hcid_dbus_inquiry_start(bdaddr_t *local) {}
static inline void hcid_dbus_inquiry_complete(bdaddr_t *local) {}
@@ -145,6 +146,7 @@
static inline void hcid_dbus_remote_name_failed(bdaddr_t *local, bdaddr_t *peer, uint8_t status) {}
static inline void hcid_dbus_conn_complete(bdaddr_t *local, bdaddr_t *peer) {}
static inline void hcid_dbus_disconn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t reason) {}
+static inline void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status) {}
#endif
int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name);
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-10-26 22:33:33.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-27 13:12:05.000000000 -0200
@@ -668,6 +668,51 @@
{
}
+void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status)
+{
+ DBusMessage *message = NULL;
+ char *local_addr, *peer_addr;
+ bdaddr_t tmp;
+ char path[MAX_PATH_LENGTH];
+ int id;
+
+ baswap(&tmp, local); local_addr = batostr(&tmp);
+ baswap(&tmp, peer); peer_addr = batostr(&tmp);
+
+ id = hci_devid(local_addr);
+ if (id < 0) {
+ syslog(LOG_ERR, "No matching device id for %s", local_addr);
+ goto failed;
+ }
+
+ snprintf(path, sizeof(path), "%s/hci%d/%s", MANAGER_PATH, id, BLUEZ_HCI);
+
+ message = dbus_message_new_signal(path, BLUEZ_HCI_INTERFACE, BLUEZ_HCI_AUTH_COMPLETE);
+ if (message == NULL) {
+ syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
+ goto failed;
+ }
+
+ dbus_message_append_args(message,
+ DBUS_TYPE_STRING, &peer_addr,
+ DBUS_TYPE_BYTE, &status,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_connection_send(connection, message, NULL) == FALSE) {
+ syslog(LOG_ERR, "Can't send D-BUS remote name message");
+ goto failed;
+ }
+
+ dbus_connection_flush(connection);
+
+failed:
+ if (message)
+ dbus_message_unref(message);
+
+ bt_free(local_addr);
+ bt_free(peer_addr);
+}
+
gboolean watch_func(GIOChannel *chan, GIOCondition cond, gpointer data)
{
DBusWatch *watch = (DBusWatch *) data;
@@ -1697,7 +1742,7 @@
rq.rlen = EVT_CMD_STATUS_SIZE;
rq.event = EVT_CMD_STATUS;
- if (hci_send_req(dd, &rq, 25000) < 0) {
+ if (hci_send_req(dd, &rq, 100) < 0) {
syslog(LOG_ERR, "Unable to send authentication request: %s", strerror(errno));
reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
goto failed;
--- bluez-utils-cvs.orig/hcid/security.c 2005-10-24 09:03:37.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/security.c 2005-10-27 13:01:45.000000000 -0200
@@ -644,6 +644,18 @@
hcid_dbus_disconn_complete(sba, &dba, evt->reason);
}
+static inline void auth_complete(int dev, bdaddr_t *sba, void *ptr)
+{
+ evt_auth_complete *evt = ptr;
+ bdaddr_t dba;
+
+ if (get_bdaddr(dev, sba, evt->handle, &dba) < 0)
+ return;
+
+ hcid_dbus_auth_complete(sba, &dba, evt->status);
+}
+
+
static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data)
{
unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr = buf;
@@ -726,6 +738,9 @@
case EVT_DISCONN_COMPLETE:
disconn_complete(dev, &di->bdaddr, ptr);
break;
+ case EVT_AUTH_COMPLETE:
+ auth_complete(dev, &di->bdaddr, ptr);
+ break;
}
if (hci_test_bit(HCI_SECMGR, &di->flags))
@@ -789,6 +804,7 @@
hci_filter_set_event(EVT_EXTENDED_INQUIRY_RESULT, &flt);
hci_filter_set_event(EVT_CONN_COMPLETE, &flt);
hci_filter_set_event(EVT_DISCONN_COMPLETE, &flt);
+ hci_filter_set_event(EVT_AUTH_COMPLETE, &flt);
if (setsockopt(dev, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
syslog(LOG_ERR, "Can't set filter on hci%d: %s (%d)",
hdev, strerror(errno), errno);
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-27 16:33 ` Claudio Takahasi
@ 2005-10-27 17:11 ` Marcel Holtmann
2005-10-31 14:53 ` Eduardo Rocha
0 siblings, 1 reply; 13+ messages in thread
From: Marcel Holtmann @ 2005-10-27 17:11 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
> The signal has two arguments now:
> - String: peer address
> - Byte: authentication status
the patch is in the CVS now.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-27 17:11 ` Marcel Holtmann
@ 2005-10-31 14:53 ` Eduardo Rocha
2005-10-31 15:42 ` Marcel Holtmann
0 siblings, 1 reply; 13+ messages in thread
From: Eduardo Rocha @ 2005-10-31 14:53 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 1215 bytes --]
Hi Marcel,
here is the patch for /org/bluez/Device. It adds the function
DeviceList that returns the list of registered devices in the machine.
For each device I'm returning (device name, addr, type, up/down, and
an array of capability). I've also splitted some functions that was
used in conjuction with /org/bluez/Manager. I've also included a
python client for test.
BR,
Eduardo.
On 10/27/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Claudio,
>
> > The signal has two arguments now:
> > - String: peer address
> > - Byte: authentication status
>
> the patch is in the CVS now.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through End of 2005
> Visit http://www.jboss.com/services/certification for more information
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>
--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT
[-- Attachment #2: dbus_devices01.patch --]
[-- Type: text/x-patch, Size: 14778 bytes --]
--- bluez-cvs-new.2/utils/hcid/dbus.h 2005-10-31 11:30:46.706609400 -0300
+++ bluez-cvs-new/utils/hcid/dbus.h 2005-10-31 11:31:30.393967912 -0300
@@ -44,17 +44,36 @@
/*========================================================================
BlueZ D-Bus Device service definitions "/org/bluez/Device"
*========================================================================*/
+#define DEV_GET_DEV "DeviceList"
#define DEV_UP "Up"
#define DEV_DOWN "Down"
#define DEV_RESET "Reset"
#define DEV_SET_PROPERTY "SetProperty"
#define DEV_GET_PROPERTY "GetProperty"
-#define DEV_UP_SIGNATURE __END_SIG__
-#define DEV_DOWN_SIGNATURE __END_SIG__
-#define DEV_RESET_SIGNATURE __END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE __END_SIG__
-#define DEV_GET_PROPERTY_SIGNATURE __END_SIG__
+#define DEV_GET_DEV_SIGNATURE __END_SIG__
+
+/* DeviceList Reply: a(devname, addr, type, up/down, a(flags)) - all types strings */
+#define DEV_GET_DEV_REPLY_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_ARRAY_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING\
+ __END_SIG__
+
+#define DEV_GET_DEV_REPLY_SIGNATURE DBUS_TYPE_ARRAY_AS_STRING\
+ DEV_GET_DEV_REPLY_STRUCT_SIGNATURE\
+ __END_SIG__
+
+
+#define DEV_UP_SIGNATURE __END_SIG__
+#define DEV_DOWN_SIGNATURE __END_SIG__
+#define DEV_RESET_SIGNATURE __END_SIG__
+#define DEV_SET_PROPERTY_SIGNATURE __END_SIG__
+#define DEV_GET_PROPERTY_SIGNATURE __END_SIG__
/*========================================================================
BlueZ D-Bus Manager service definitions "/org/bluez/Manager"
--- bluez-cvs-new.2/utils/hcid/dbus.c 2005-10-31 11:30:46.706609400 -0300
+++ bluez-cvs-new/utils/hcid/dbus.c 2005-10-31 11:39:21.725314656 -0300
@@ -53,6 +53,7 @@
#define MAX_PATH_LENGTH (64)
#define READ_REMOTE_NAME_TIMEOUT (25000)
#define MAX_CONN_NUMBER (10)
+#define DEVICE_FLAG_NAME (16)
#define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
#define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
@@ -106,6 +107,24 @@
const char *str;
}bluez_error_t;
+typedef struct {
+ char *str;
+ unsigned int val;
+} hci_map;
+
+static hci_map dev_flags_map[] = {
+ { "INIT", HCI_INIT },
+ { "RUNNING", HCI_RUNNING },
+ { "RAW", HCI_RAW },
+ { "PSCAN", HCI_PSCAN },
+ { "ISCAN", HCI_ISCAN },
+ { "INQUIRY", HCI_INQUIRY },
+ { "AUTH", HCI_AUTH },
+ { "ENCRYPT", HCI_ENCRYPT },
+ { "SECMGR", HCI_SECMGR },
+ { NULL }
+};
+
static const bluez_error_t dbus_error_array[] = {
{ BLUEZ_EDBUS_UNKNOWN_METHOD, "Method not found" },
{ BLUEZ_EDBUS_WRONG_SIGNATURE, "Wrong method signature" },
@@ -234,13 +253,20 @@
/*
* Device Message handler functions object table declaration
*/
-static DBusHandlerResult msg_func(DBusConnection *conn, DBusMessage *msg, void *data);
+static DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void *data);
+static DBusHandlerResult msg_func_manager(DBusConnection *conn, DBusMessage *msg, void *data);
-static DBusMessage* handle_get_devices_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_get_devices_req_device(DBusMessage *msg, void *data);
+static DBusMessage* handle_get_devices_req_manager(DBusMessage *msg, void *data);
static DBusMessage* handle_not_implemented_req(DBusMessage *msg, void *data);
-static const DBusObjectPathVTable obj_vtable = {
- .message_function = &msg_func,
+static const DBusObjectPathVTable obj_dev_vtable = {
+ .message_function = &msg_func_device,
+ .unregister_function = NULL
+};
+
+static const DBusObjectPathVTable obj_mgr_vtable = {
+ .message_function = &msg_func_manager,
.unregister_function = NULL
};
@@ -248,6 +274,11 @@
* Service provided under the path DEVICE_PATH
* TODO add the handlers
*/
+static const struct service_data dev_root_services[] = {
+ { DEV_GET_DEV, handle_get_devices_req_device, DEV_GET_DEV_SIGNATURE },
+ { NULL, NULL, NULL}
+};
+
static const struct service_data dev_services[] = {
{ DEV_UP, handle_not_implemented_req, DEV_UP_SIGNATURE },
{ DEV_DOWN, handle_not_implemented_req, DEV_DOWN_SIGNATURE },
@@ -262,7 +293,7 @@
*
*/
static const struct service_data mgr_services[] = {
- { MGR_GET_DEV, handle_get_devices_req, MGR_GET_DEV_SIGNATURE },
+ { MGR_GET_DEV, handle_get_devices_req_manager, MGR_GET_DEV_SIGNATURE },
{ MGR_INIT, handle_not_implemented_req, NULL },
{ MGR_ENABLE, handle_not_implemented_req, NULL },
{ MGR_DISABLE, handle_not_implemented_req, NULL },
@@ -352,7 +383,7 @@
free(req);
}
-static gboolean register_dbus_path(char *path, uint16_t id)
+static gboolean register_dbus_path(char *path, uint16_t id, const DBusObjectPathVTable *pvtable)
{
struct hci_dbus_data *data;
syslog(LOG_INFO,"Registering DBUS Path: %s", path);
@@ -363,7 +394,7 @@
}
data->id = id;
- if (!dbus_connection_register_object_path(connection, path, &obj_vtable, data)) {
+ if (!dbus_connection_register_object_path(connection, path, pvtable, data)) {
syslog(LOG_ERR,"DBUS failed to register %s object", path);
free(data);
return FALSE;
@@ -811,7 +842,7 @@
data->id = DEVICE_PATH_ID;
if (!dbus_connection_register_fallback(connection, DEVICE_PATH,
- &obj_vtable, data)) {
+ &obj_dev_vtable, data)) {
syslog(LOG_ERR, "Can't register %s object", DEVICE_PATH);
return FALSE;
}
@@ -823,7 +854,7 @@
data->id = MANAGER_PATH_ID;
if (!dbus_connection_register_fallback(connection, MANAGER_PATH,
- &obj_vtable, data)) {
+ &obj_mgr_vtable, data)) {
syslog(LOG_ERR, "Can't register %s object", MANAGER_PATH);
return FALSE;
}
@@ -936,7 +967,7 @@
snprintf(path, sizeof(path), "%s/%s", DEVICE_PATH, pdev);
/* register the default path*/
- return register_dbus_path(path, id);
+ return register_dbus_path(path, id, &obj_dev_vtable);
}
gboolean hcid_dbus_unregister_device(uint16_t id)
@@ -1066,12 +1097,12 @@
/* register the default path*/
if (!dft_reg) {
snprintf(path, sizeof(path), "%s/%s/%s", MANAGER_PATH, HCI_DEFAULT_DEVICE_NAME, BLUEZ_HCI);
- register_dbus_path(path, DEFAULT_DEVICE_PATH_ID);
+ register_dbus_path(path, DEFAULT_DEVICE_PATH_ID, &obj_mgr_vtable);
}
/* register the default path*/
snprintf(path, sizeof(path), "%s/%s%d/%s", MANAGER_PATH, HCI_DEVICE_NAME, id, BLUEZ_HCI);
- register_dbus_path(path, id);
+ register_dbus_path(path, id, &obj_mgr_vtable);
return 0;
}
@@ -1146,7 +1177,81 @@
*
*/
-static DBusHandlerResult msg_func(DBusConnection *conn, DBusMessage *msg, void *data)
+static DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+ const struct service_data *ptr_handlers = NULL;
+ DBusMessage *reply = NULL;
+ int type;
+ const char *iface;
+ const char *method;
+ const char *signature;
+ const char *path;
+ struct hci_dbus_data *dbus_data = data;
+ uint32_t result = BLUEZ_EDBUS_UNKNOWN_METHOD;
+ DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ uint8_t found = 0;
+
+ path = dbus_message_get_path(msg);
+ type = dbus_message_get_type(msg);
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member (msg);
+ signature = dbus_message_get_signature(msg);
+
+ if (strcmp(iface, DEVICE_INTERFACE))
+ return ret;
+
+ if (strcmp(path, DEVICE_PATH) > 0) {
+ if ( dbus_data->id == DEVICE_PATH_ID ) {
+ /* fallback handling. The child path IS NOT registered */
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_UNKNOWN_PATH);
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ } else {
+ /* hciX code */
+
+ }
+
+ } else {
+ /* it's the device path */
+ ptr_handlers = dev_root_services;
+ found = 1;
+ }
+ if (found && (type == DBUS_MESSAGE_TYPE_METHOD_CALL) && (method != NULL)) {
+
+ for (; ptr_handlers->name; ptr_handlers++) {
+ if (strcmp(method, ptr_handlers->name) == 0) {
+ /* resetting unknown method. It's possible handle method overload */
+ result = BLUEZ_EDBUS_WRONG_SIGNATURE;
+ if (strcmp(ptr_handlers->signature, signature) == 0) {
+ if (ptr_handlers->handler_func) {
+ reply = (ptr_handlers->handler_func)(msg, data);
+ result = 0; /* resetting wrong signature*/
+ } else
+ syslog(LOG_INFO, "Service not implemented");
+
+ break;
+ }
+
+ }
+ }
+
+ if (result) {
+ reply = bluez_new_failure_msg(msg, result);
+ }
+
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ /* send an error or the success reply*/
+ if (reply) {
+ if (!dbus_connection_send (conn, reply, NULL)) {
+ syslog(LOG_ERR, "Can't send reply message!") ;
+ }
+ dbus_message_unref (reply);
+ }
+ return ret;
+}
+
+static DBusHandlerResult msg_func_manager(DBusConnection *conn, DBusMessage *msg, void *data)
{
const struct service_data *ptr_handlers = NULL;
DBusMessage *reply = NULL;
@@ -1156,7 +1261,6 @@
const char *signature;
const char *path;
const char *rel_path;
- const char *tmp_iface = NULL;
struct hci_dbus_data *dbus_data = data;
uint32_t result = BLUEZ_EDBUS_UNKNOWN_METHOD;
DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -1170,43 +1274,38 @@
syslog (LOG_INFO, "%s - path:%s, id:0x%X", __PRETTY_FUNCTION__, path, dbus_data->id);
- if (strcmp(path, DEVICE_PATH) == 0) {
- ptr_handlers = dev_services;
- tmp_iface = DEVICE_INTERFACE;
- found = 1;
- } else {
- if (strcmp(path, MANAGER_PATH) > 0) {
- /* it is device specific path */
- if ( dbus_data->id == MANAGER_PATH_ID ) {
- /* fallback handling. The child path IS NOT registered */
- reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_UNKNOWN_PATH);
- ret = DBUS_HANDLER_RESULT_HANDLED;
- } else {
- const struct profile_obj_path_data *mgr_child = obj_path_table;
- rel_path = strrchr(path,'/');
- rel_path++;
-
- if (rel_path) {
- for ( ;mgr_child->name; mgr_child++) {
- if (strcmp(mgr_child->name, rel_path) == 0) {
- ptr_handlers = mgr_child->get_svc_table();
- found = 1;
- }
- }
+ if (strcmp(iface, MANAGER_INTERFACE))
+ return ret;
- tmp_iface = MANAGER_INTERFACE;
+ if (strcmp(path, MANAGER_PATH) > 0) {
+ /* it is device specific path */
+ if ( dbus_data->id == MANAGER_PATH_ID ) {
+ /* fallback handling. The child path IS NOT registered */
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_UNKNOWN_PATH);
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ } else {
+ const struct profile_obj_path_data *mgr_child = obj_path_table;
+ rel_path = strrchr(path,'/');
+ rel_path++;
+
+ if (rel_path) {
+ for ( ;mgr_child->name; mgr_child++) {
+ if (strcmp(mgr_child->name, rel_path) == 0) {
+ ptr_handlers = mgr_child->get_svc_table();
+ found = 1;
+ break;
+ }
}
+
}
- } else {
- /* it's the manager path */
- ptr_handlers = mgr_services;
- tmp_iface = MANAGER_INTERFACE;
- found = 1;
}
+ } else {
+ /* it's the manager! path */
+ ptr_handlers = mgr_services;
+ found = 1;
}
- if (found && (type == DBUS_MESSAGE_TYPE_METHOD_CALL) &&
- (strcmp(iface, tmp_iface) == 0) && (method != NULL)) {
+ if (found && (type == DBUS_MESSAGE_TYPE_METHOD_CALL) && (method != NULL)) {
for (; ptr_handlers->name; ptr_handlers++) {
if (strcmp(method, ptr_handlers->name) == 0) {
@@ -1748,8 +1847,111 @@
* Section reserved to Manager D-Bus message handlers
*
*****************************************************************/
+static DBusMessage* handle_get_devices_req_device(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter flag_array_iter;
+ DBusMessageIter struct_iter;
+ DBusMessage *reply = NULL;
+ struct hci_dev_list_req *dl = NULL;
+ struct hci_dev_req *dr = NULL;
+ struct hci_dev_info di;
+ int sk = -1;
+ int i;
+ char aname[BLUETOOTH_DEVICE_NAME_LEN+1];
+ char aaddr[BLUETOOTH_DEVICE_ADDR_LEN];
+ char aflag[DEVICE_FLAG_NAME];
+ char *paddr = aaddr;
+ char *pname = aname;
+ char *pflag = aflag;
+ char *ptype;
+ const char array_sig[] = DEV_GET_DEV_REPLY_STRUCT_SIGNATURE;
+ hci_map *mp;
+
+ /* Create and bind HCI socket */
+ sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+ if (sk < 0) {
+ syslog(LOG_ERR, "Can't open HCI socket: %s (%d)", strerror(errno), errno);
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto failed;
+ }
+
+ dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
+ if (!dl) {
+ syslog(LOG_ERR, "Can't allocate memory");
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+ goto failed;
+ }
+
+ dl->dev_num = HCI_MAX_DEV;
+ dr = dl->dev_req;
+
+ if (ioctl(sk, HCIGETDEVLIST, dl) < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto failed;
+ }
+
+ /* active bluetooth adapter found */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, array_sig, &array_iter);
+ dr = dl->dev_req;
+
+ for (i = 0; i < dl->dev_num; i++, dr++) {
+ mp = dev_flags_map;
+ memset(&di, 0 , sizeof(struct hci_dev_info));
+ di.dev_id = dr->dev_id;
+
+ if (ioctl(sk, HCIGETDEVINFO, &di) < 0)
+ continue;
+
+ strncpy(aname, di.name, BLUETOOTH_DEVICE_NAME_LEN);
+ aname[BLUETOOTH_DEVICE_NAME_LEN] = '\0';
+
+ ba2str(&di.bdaddr, aaddr);
+ ptype = hci_dtypetostr(di.type);
+
+ dbus_message_iter_open_container(&array_iter,
+ DBUS_TYPE_STRUCT, NULL, &struct_iter);
+
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &pname);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &paddr);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &ptype);
+
+ if (hci_test_bit(HCI_UP, &dr->dev_opt)) {
+ sprintf(pflag, "%s", "UP");
+ } else {
+ sprintf(pflag, "%s", "DOWN");
+ }
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &pflag);
+
+ dbus_message_iter_open_container(&struct_iter,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &flag_array_iter);
+
+ while (mp->str) {
+ if (hci_test_bit(mp->val, &dr->dev_opt)) {
+ sprintf(pflag, "%s", mp->str);
+ dbus_message_iter_append_basic(&flag_array_iter, DBUS_TYPE_STRING, &pflag);
+ }
+ mp++;
+ }
+ dbus_message_iter_close_container(&struct_iter, &flag_array_iter);
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+
+ dbus_message_iter_close_container(&iter, &array_iter);
+
+failed:
+ if (sk >= 0)
+ close(sk);
+ if (dl)
+ free(dl);
+ return reply;
+}
+
-static DBusMessage* handle_get_devices_req(DBusMessage *msg, void *data)
+static DBusMessage* handle_get_devices_req_manager(DBusMessage *msg, void *data)
{
DBusMessageIter iter;
DBusMessageIter array_iter;
[-- Attachment #3: devlistdev.py --]
[-- Type: text/x-python, Size: 187 bytes --]
import dbus
bus = dbus.SystemBus()
proxy_obj = bus.get_object('org.bluez', '/org/bluez/Device')
dbus_iface = dbus.Interface(proxy_obj, 'org.bluez.Device')
print dbus_iface.DeviceList()
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Bluez-devel] [D-BUS PATCH] Authentication
2005-10-31 14:53 ` Eduardo Rocha
@ 2005-10-31 15:42 ` Marcel Holtmann
0 siblings, 0 replies; 13+ messages in thread
From: Marcel Holtmann @ 2005-10-31 15:42 UTC (permalink / raw)
To: bluez-devel
Hi Eduardo,
> here is the patch for /org/bluez/Device. It adds the function
> DeviceList that returns the list of registered devices in the machine.
> For each device I'm returning (device name, addr, type, up/down, and
> an array of capability). I've also splitted some functions that was
> used in conjuction with /org/bluez/Manager. I've also included a
> python client for test.
the patch is in the CVS now, but I had to do housekeeping of the coding
style again. Especially the whitespaces. So please use an editor that
visualizes the whitespaces and tabs for you. This really helps to keep
the code clean.
I like the idea with the test program. I think we need a lot more
command line based test programs to verify the D-Bus interface. After
another walk-through the code, I realized that nobody actually bothered
about big endian system. So we need some regression tests.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2005-10-31 15:42 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-20 17:45 [Bluez-devel] [D-BUS PATCH] Authentication Claudio Takahasi
2005-10-22 13:08 ` Marcel Holtmann
2005-10-24 13:06 ` Claudio Takahasi
2005-10-24 13:19 ` Marcel Holtmann
2005-10-25 19:03 ` Claudio Takahasi
2005-10-27 0:37 ` Marcel Holtmann
2005-10-27 14:33 ` Claudio Takahasi
2005-10-27 14:39 ` Claudio Takahasi
2005-10-27 14:53 ` Marcel Holtmann
2005-10-27 16:33 ` Claudio Takahasi
2005-10-27 17:11 ` Marcel Holtmann
2005-10-31 14:53 ` Eduardo Rocha
2005-10-31 15:42 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).